47 lines
895 B
Bash
47 lines
895 B
Bash
#!/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/
|
|
}
|
|
|
|
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" ]]
|
|
}
|