services-garbaye/functions.sh

47 lines
895 B
Bash
Raw Normal View History

2021-05-04 20:14:08 +00:00
#!/usr/bin/env bash
SCRIPTNAME="$( basename -- "$0" )"
ensure_root () {
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
}
ensure_not_root () {
if [[ $EUID -eq 0 ]]; then
echo "This script must not be run as root"
exit 1
fi
}
ensure_pwd_is_scriptdir () {
if [[ $PWD != $ABSDIR ]]; then
echo "Please cd in the script directory before running it :"
echo "cd ${ABSDIR}"
echo "./${SCRIPTNAME}"
exit 1
fi
}
ensure_systemd_as_user_dir_exists () {
mkdir -p ${HOME}/.config/systemd/user/
}
2021-05-05 21:03:22 +00:00
check_systemd_unit_exists () {
systemctl --user cat -- ${1} &> /dev/null
}
check_systemd_unit_running () {
systemctl --user is-active --quiet service ${1}
}
check_container_exists () {
podman container exists ${1}
}
check_container_running () {
[[ "podman container inspect -f '{{.State.Status}}' ${1}" != "running" ]]
2021-05-05 21:03:22 +00:00
}