From 900c27c4a08c77a4cf784a37be18a084263b6801 Mon Sep 17 00:00:00 2001 From: "Lockszmith (@wolfpack)" Date: Mon, 2 Dec 2024 17:47:56 -0500 Subject: [PATCH] Added runtipictl out-of-jlmkr helper script The script will be used to manage runtipi from outside the jailmaker created systemd-nspawn namespace container. TODO: Will need to modify the script to work within the runtipi instance in cases where not working with jailmaker --- _bin/runtipictl | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 _bin/runtipictl diff --git a/_bin/runtipictl b/_bin/runtipictl new file mode 100755 index 0000000..6e6dda4 --- /dev/null +++ b/_bin/runtipictl @@ -0,0 +1,89 @@ +#! /usr/bin/env bash + +jlmkr () { + sudo VISUAL="${VISUAL:-}" EDITOR="${EDITOR:-}" $SCALE_POOL_ROOT/jailmaker/jlmkr.py "${@:---help}" +} + +JAIL_UID=${JAIL_UID:-${UID}} + +jlmkr-exec () { + local cli='cd /srv/runtipi; '"${1:?Must supply command} "${2:+"$( + printf '\"%s\" ' "${@:2}" + )"} + + if jlmkr exec runtipi true; then + [ -n "$QUIET" ] || printf 'jlmkr UID:\t%s\ncli:\t\t%s\n' "${JAIL_UID}" "$cli" + jlmkr shell --uid "${JAIL_UID}" runtipi /bin/bash -c "$cli" + else + echo "ERROR: ${_ERROR_MGS:-"Please check if runtipi jail has started! Have you tried 'full-start'?"}" >&2 + exit -1 + fi +} + +runtipi-cli() { + jlmkr-exec ./runtipi-cli "${@}" +} + +runtipi-app-docker-compose() { + local APP="${1:-Must supply app name}" + local LOCAL_YML="user-config/${APP}/docker-compose.yml" + + jlmkr exec runtipi test -e "/srv/runtipi/${LOCAL_YML}" || LOCAL_YML="" + [ -z "$LOCAL_YML" ] || LOCAL_YML="--file ${LOCAL_YML}" + + jlmkr-exec docker compose \ + --env-file user-config/.env.local \ + --env-file app-data/${APP}/app.env \ + --env-file user-config/${APP}/app.env \ + --project-name ${APP} \ + --file apps/${APP}/docker-compose.yml \ + --file repos/29ca930bfdaffa1dfabf5726336380ede7066bc53297e3c0c868b27c97282903/apps/docker-compose.common.yml \ + ${LOCAL_YML} ${@:2} +} + +case "${1}" in + cli) + runtipi-cli "${@:2}" + ;; + log) + jlmkr-exec docker compose --env-file user-config/.env.local logs --tail=${TAIL:-40} "${2:-runtipi}" ${3:+"${@:3}"} + ;; + start) + runtipi-cli start --env-file user-config/.env.local --no-permissions + ;; + full-start) + if ! jlmkr exec runtipi true; then + jlmkr start runtipi + sleep 1s + fi + _ERROR_MSG="ERROR: failed to invoke a command inside the runtipi jail and can't start the jail." \ + runtipi-cli start --env-file user-config/.env.local --no-permissions + ;; + exec) + jlmkr-exec "${@:2}" + ;; + docker) + jlmkr-exec docker "${@:2}" + ;; + dcoapp) + runtipi-app-docker-compose "${@:2}" + ;; + setup) + ln -s "${BASH_SOURCE[0]}" "$HOME/.local/bin/" + ;; + *) + printf '%s\n' \ + "Usage:" \ + "" \ + "cli" \ + "log" \ + "start" \ + "full-start" \ + "exec" \ + "docker" \ + "dcoapp" \ + "setup" + + ;; +esac +