2024-12-02 22:47:56 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
jlmkr () {
|
|
|
|
sudo VISUAL="${VISUAL:-}" EDITOR="${EDITOR:-}" $SCALE_POOL_ROOT/jailmaker/jlmkr.py "${@:---help}"
|
|
|
|
}
|
|
|
|
|
|
|
|
JAIL_UID=${JAIL_UID:-${UID}}
|
|
|
|
|
|
|
|
jlmkr-exec () {
|
2024-12-08 19:46:16 +00:00
|
|
|
local set_x=" set -x; pwd; id; "
|
|
|
|
[ -z "$QUIET" ] || set_x=""
|
|
|
|
local cli="cd ${START_DIR:-/srv/runtipi};${set_x} ${1:?Must supply command} "
|
|
|
|
if [ -n "$ROOT_EXEC" ]; then
|
|
|
|
cli="$cli ${*:2}"
|
|
|
|
else
|
|
|
|
cli="$cli "${2:+"$(
|
|
|
|
printf '\"%s\" ' "${@:2}"
|
|
|
|
)"}
|
|
|
|
fi
|
2024-12-02 22:47:56 +00:00
|
|
|
|
|
|
|
if jlmkr exec runtipi true; then
|
2024-12-08 19:46:16 +00:00
|
|
|
if [ -n "$ROOT_EXEC" ]; then
|
|
|
|
jlmkr exec runtipi /bin/bash <<<"$cli"
|
|
|
|
else
|
|
|
|
jlmkr shell --uid "${JAIL_UID}" runtipi /bin/bash -c "$cli"
|
|
|
|
fi
|
2024-12-02 22:47:56 +00:00
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2024-12-08 19:46:16 +00:00
|
|
|
dls() {
|
|
|
|
# Default docker ps format is:
|
|
|
|
# jlmkr-exec docker ps --format "table {{ .ID }}\t{{ .Image }}\t{{ .Command }}\t{{ .Created }}\t{{ .Status }}\t{{ .Ports }}\t{{ .Names }}"
|
|
|
|
|
|
|
|
local base='{{.Status}}\t{{.ID}}\t{{.Names}}\t{{.Image}}' #'\t{{.Networks}}\t{{.Ports}}\t{{.Mounts}}'
|
|
|
|
local compose='{{.Label "com.docker.compose.project"}}\t{{.Label "com.docker.compose.service"}}'
|
|
|
|
local format="table $compose\t$base"
|
2024-12-08 21:55:19 +00:00
|
|
|
ROOT_EXEC=1 QUIET=${QUIET:-0} jlmkr-exec \
|
|
|
|
docker "container ls --all --format '$format' | ( sed -u '1s/.*/\U&/; q'; sed -Ee 's|^|555|; s|^555runtipi|000runtipi|;' | sort | sed -Ee 's/^[[:digit:]]{3}//' )"
|
2024-12-08 19:46:16 +00:00
|
|
|
}
|
|
|
|
|
2024-12-02 22:47:56 +00:00
|
|
|
case "${1}" in
|
|
|
|
cli)
|
|
|
|
runtipi-cli "${@:2}"
|
|
|
|
;;
|
|
|
|
log)
|
2024-12-05 01:59:34 +00:00
|
|
|
jlmkr-exec "POSTGRES_PASSWORD=_ TIPI_VERSION=_ LOCAL_DOMAIN=_ DOMAIN=_" docker compose --env-file user-config/.env.local logs --tail=${TAIL:-40} "${2:-runtipi}" ${3:+"${@:3}"}
|
2024-12-02 22:47:56 +00:00
|
|
|
;;
|
|
|
|
start)
|
|
|
|
runtipi-cli start --env-file user-config/.env.local --no-permissions
|
|
|
|
;;
|
2024-12-08 22:01:36 +00:00
|
|
|
update)
|
|
|
|
runtipi-cli update --env-file user-config/.env.local --no-permissions "${2:?Must supply version}" "${@:3}"
|
|
|
|
;;
|
2024-12-02 22:47:56 +00:00
|
|
|
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}"
|
|
|
|
;;
|
2024-12-08 19:46:16 +00:00
|
|
|
dls)
|
|
|
|
dls "${@:2}"
|
|
|
|
;;
|
2024-12-02 22:47:56 +00:00
|
|
|
dcoapp)
|
|
|
|
runtipi-app-docker-compose "${@:2}"
|
|
|
|
;;
|
2024-12-04 04:45:04 +00:00
|
|
|
dockge)
|
|
|
|
START_DIR=/srv/dockge/stacks/${2:?Must supply stack name} jlmkr-exec docker compose "${@:3}"
|
|
|
|
;;
|
2024-12-02 22:47:56 +00:00
|
|
|
setup)
|
2024-12-04 04:45:04 +00:00
|
|
|
ln -s $2 "$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" "$HOME/.local/bin/"
|
2024-12-02 22:47:56 +00:00
|
|
|
;;
|
|
|
|
*)
|
2024-12-04 04:45:04 +00:00
|
|
|
printf '%s %-12s %s\n' \
|
|
|
|
"" "" ""\
|
|
|
|
"Usage:" "" ""\
|
|
|
|
" $(basename "$0") <command> [args...]" "" ""\
|
|
|
|
"" "" "" \
|
|
|
|
"Available commands:" "" ""\
|
|
|
|
"" "" "" \
|
2024-12-08 22:01:36 +00:00
|
|
|
"runtipi" "" ""\
|
2024-12-04 04:45:04 +00:00
|
|
|
"" "cli" "runtipi-cli" \
|
2024-12-08 22:01:36 +00:00
|
|
|
"" "full-start" "start runtipi jail, following with starting runtipi" \
|
|
|
|
"" "log" "runtipi docker stack logs" \
|
|
|
|
"" "start" "start runtipi" \
|
|
|
|
"" "update" "update runtipi to a specific version" \
|
|
|
|
"" "" "" \
|
|
|
|
"docker/docker-compose" "" ""\
|
2024-12-04 04:45:04 +00:00
|
|
|
"" "dcoapp" "docker compose for runtipi apps" \
|
2024-12-08 21:55:19 +00:00
|
|
|
"" "dls" "stylized docker ls" \
|
2024-12-04 04:45:04 +00:00
|
|
|
"" "docker" "docker" \
|
2024-12-08 22:01:36 +00:00
|
|
|
"" "dockge" "docker compose for dockge stacks" \
|
|
|
|
"" "" "" \
|
|
|
|
"misc." "" ""\
|
2024-12-04 04:45:04 +00:00
|
|
|
"" "exec" "execute within the shell, START_DIR env applies" \
|
|
|
|
"" "" "" \
|
|
|
|
"" "setup" "setup runtipictl in user's .local/bin dir"
|
2024-12-02 22:47:56 +00:00
|
|
|
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|