detecting if petget is called in pinstall.sh
Posted: Thu 19 Mar 2020, 06:39
In a pinstall.sh script I want to detect if it is being installed via the petget command because unlike package_chooser.sh, the petget command won't install dependencies and the pinstall.sh script needs the dependencies in order to work.
Unfortunately there is currently no variable exported in petget that would allow the pinstall.sh script to dected whether the petget command is a parrent process. So what to do? Well...let's abuse stack traces.
Bash has a command "called caller" (see manpage) that can be used to build a stack trace.
Here is such a function
https://unix.stackexchange.com/question ... er-command
So, in theory I should be able to do something like this:
I'll try it tommorow and report back on the results.
Edit:
Here's a draft of what I was thinking (not tested)
pinstall.sh arch_certs-1.0.1 (draft)
https://pastebin.com/bwyHBeX9
a modified version of my previous pet (see post). The old pet had the dependencies stored in /var/tmp as pets. The new pinstall script will first look in the folder /var/tmp and /root and otherwise download the pet. However, it will only do this if the petget command is a parent command. Otherwise it will rely on the package manager to install the dependencies. Well at least that is my idea but it isn't fully implemented yet.
Unfortunately there is currently no variable exported in petget that would allow the pinstall.sh script to dected whether the petget command is a parrent process. So what to do? Well...let's abuse stack traces.
Bash has a command "called caller" (see manpage) that can be used to build a stack trace.
Here is such a function
Code: Select all
stacktrace() {
local frame=0 LINE SUB FILE
while read LINE SUB FILE < <(caller "$frame"); do
printf ' %s @ %s:%s' "${SUB}" "${FILE}" "${LINE}"
((frame++))
done
}
So, in theory I should be able to do something like this:
Code: Select all
petget_cmd="$(stacktrace | grep petget/petget)"
if [ ! -z "$petget_cmd" ]; then
echo "Petget command called"
else
echo "Petget command not called"
fi
Edit:
Here's a draft of what I was thinking (not tested)
pinstall.sh arch_certs-1.0.1 (draft)
https://pastebin.com/bwyHBeX9
a modified version of my previous pet (see post). The old pet had the dependencies stored in /var/tmp as pets. The new pinstall script will first look in the folder /var/tmp and /root and otherwise download the pet. However, it will only do this if the petget command is a parent command. Otherwise it will rely on the package manager to install the dependencies. Well at least that is my idea but it isn't fully implemented yet.