diff --git a/functions.sh b/functions.sh new file mode 100644 index 0000000..50b2ba5 --- /dev/null +++ b/functions.sh @@ -0,0 +1,30 @@ +#!/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/ +} diff --git a/podman-peerjs/10_install.sh b/podman-peerjs/10_install.sh new file mode 100755 index 0000000..fa8d143 --- /dev/null +++ b/podman-peerjs/10_install.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +if podman container exists ${container_name}; then + echo container ${container_name} alredy exists, please remove it first. + exit 1 +fi + +podman run --name ${container_name} --user nobody -p ${listen_if}:${listen_port}:9000 -d ${upstream_image}:${upstream_version} + diff --git a/podman-peerjs/20_enable.sh b/podman-peerjs/20_enable.sh new file mode 100755 index 0000000..5f77cce --- /dev/null +++ b/podman-peerjs/20_enable.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +if ! podman container exists ${container_name}; then + echo container ${container_name} must exist in order to add it to systemd + exit 1 +fi + +ensure_systemd_as_user_dir_exists +podman generate systemd --name ${container_name} > ~/.config/systemd/user/${service_name} + +podman stop ${container_name} +systemctl --user enable ${service_name} +systemctl --user start ${service_name} diff --git a/podman-peerjs/30_start.sh b/podman-peerjs/30_start.sh new file mode 100755 index 0000000..b07f65e --- /dev/null +++ b/podman-peerjs/30_start.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +if systemctl is-active --quiet service ${service_name}; then + echo Service ${service_name} is already running. + exit 1 +fi + +systemctl --user start ${service_name}.service diff --git a/podman-peerjs/40_stop.sh b/podman-peerjs/40_stop.sh new file mode 100755 index 0000000..9c765c9 --- /dev/null +++ b/podman-peerjs/40_stop.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +if ! systemctl is-active --quiet service ${service_name}; then + echo Service ${service_name} is already stopped. + exit 1 +fi + +systemctl --user stop ${service_name}.service diff --git a/podman-peerjs/80_disable.sh b/podman-peerjs/80_disable.sh new file mode 100755 index 0000000..dc4d440 --- /dev/null +++ b/podman-peerjs/80_disable.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +ABSDIR="$( dirname "$(readlink -f -- "$0")" )" +source ${ABSDIR}/../functions.sh +source ${ABSDIR}/vars.sh + +ensure_pwd_is_scriptdir +ensure_not_root + +if ! podman container exists ${container_name}; then + echo container ${container_name} must exist in order to add it to systemd + exit 1 +fi + +ensure_systemd_as_user_dir_exists +podman generate systemd --name ${container_name} > ~/.config/systemd/user/${service_name} + +podman stop ${container_name} +systemctl --user disable ${service_name} +systemctl --user stop ${service_name} diff --git a/podman-peerjs/vars.sh b/podman-peerjs/vars.sh new file mode 100644 index 0000000..6f3eb43 --- /dev/null +++ b/podman-peerjs/vars.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +container_name='peerjs-server' +service_name="container_${container_name}.service" +listen_if='127.0.0.1' +listen_port='9000' +upstream_image='docker.io/peerjs/peerjs-server' +upstream_version='0.6.1'