I want to use tree -p
on SNAP_COMMON, SNAP_DATA, and SNAP to troubleshoot what is visible / readable / writable when running my configure
hook, but what I’ve tried so far did not work:
But my configure script invariably fails with
===> [ SNAP_DATA contents ]
+ tree -p /var/snap/btcd/x14
/snap/btcd/x14/meta/hooks/configure: line 23: tree: command not found
Suggestions?
apt-install tree
can be achieved through use of build-packages
, but this solution will not work as it installs packages onto the host to support the build of the snap and do not necessarily become part of the snap.
stage-packages
should work, but hooks run with a different environment that that of regular entries under apps. As such, there is no default path, so I would change your tree command to something like $SNAP/usr/bin/tree
(or $SNAP/bin/tree
depending on where tree
lives within the snap).
@sergiusens thx, that works but I had to create a helper function to get more visibility into what’s where.
Adding it here in case someone else needs to ‘run that script, wherever that script happens to be’
function banner() {
echo -e "\n===> [" "$@" "]\n" 1>&2
}
function whereis() {
local name="$1" && shift 1
local cmd_path=""
local cmd_from_find=$(find "${SNAP}" -type f -executable -name "${name}")
if [[ -n "${cmd_from_find}" ]]; then
cmd_path="${cmd_from_find}"
fi
local cmd_from_path=$(command -v "${name}")
if [[ -n "${cmd_from_path}" ]]; then
cmd_path="${cmd_from_path}"
fi
banner "whereis '${name}'"
echo "find says: ${cmd_from_find:-not found}" 1>&2
echo "PATH says: ${cmd_from_path:-not found}" 1>&2
echo "using: ${cmd_path}" 1>&2
echo "permissions: $(ls -la "${cmd_path}")" 1>&2
echo "${cmd_path}"
}
...
Then I can actually do what it is I wanted to do, which is, again, to get more visibility into what’s going on (you can see the theme here)
function dump_manifest() {
local _tree=$(whereis "tree")
for dir in SNAP_COMMON SNAP_DATA; do
banner "${dir}"
eval "${_tree}" -puglFCh --du --inodes "\${${dir}}" | eval tee "${hook_dir}/${dir}.manifest"
done
}
trap dump_manifest EXIT
1 Like