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.