1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/bin/bash
show_help() {
echo "usage: os.paths snap-mount-dir, media-dir, libexec-dir"
echo ""
echo "get paths information for the current system"
}
snap_mount_dir() {
if os.query is-fedora || os.query is-amazon-linux || os.query is-centos || os.query is-arch-linux; then
echo "/var/lib/snapd/snap"
else
echo "/snap"
fi
}
media_dir() {
if os.query is-fedora || os.query is-amazon-linux || os.query is-centos || os.query is-arch-linux || os.query is-opensuse; then
echo "/run/media"
else
echo "/media"
fi
}
libexec_dir() {
if os.query is-fedora || os.query is-amazon-linux || os.query is-centos || os.query is-opensuse tumbleweed; then
echo "/usr/libexec"
else
echo "/usr/lib"
fi
}
main() {
if [ $# -eq 0 ]; then
show_help
exit 0
fi
local subcommand="$1"
local action=
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
*)
action=$(echo "$subcommand" | tr '-' '_')
shift
break
;;
esac
done
if [ -z "$(declare -f "$action")" ]; then
echo "os.paths: unknown path $subcommand" >&2
show_help
exit 1
fi
"$action" "$@"
}
main "$@"
|