diff --git a/_bin/rtpctl.d b/_bin/rtpctl.d index cec20cc..3cde351 100755 --- a/_bin/rtpctl.d +++ b/_bin/rtpctl.d @@ -2,78 +2,67 @@ RPH_UID=${RPH_UID:-${UID}} -rph-docker-exec () { - docker exec $1 runtipi-host "${@:2}" -} +# Identify source path (even if symlinked) +SOURCE=${BASH_SOURCE[0]} +while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd ) + SOURCE=$(readlink "$SOURCE") + [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SCRIPT_DIR=$( cd -- "$( dirname -- "${SOURCE}" )" &> /dev/null && pwd ) -rph-shell() { - if rph-docker-exec "" true; then - rph-docker-exec "-it --user ${RPH_UID}" bash - fi -} +BASE_NAME="$(basename -- "$0")" +BASE_BASE_NAME="${BASE_NAME%.*}" -rph-exec () { - 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 +RUNTIPI_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" +RUNTIPI_CLI="${RUNTIPI_ROOT}/runtipi_cli" +set -e - if rph exec runtipi true; then - if [ -n "$ROOT_EXEC" ]; then - rph exec runtipi /bin/bash <<<"$cli" - else - rph shell --uid "${RPH_UID}" runtipi /bin/bash -c "$cli" - fi - else - echo "ERROR: ${_ERROR_MGS:-"Please check if runtipi jail has started! Have you tried 'full-start'?"}" >&2 - exit -1 - fi -} +cd "${RUNTIPI_ROOT}" > /dev/null runtipi-cli() { - rph-exec ./runtipi-cli "${@}" + if ! [ -x "${RUNTIPI_CLI}" ]; then + >&2 printf '%s\n' \ + "ERROR: ${RUNTIPI_CLI} not found or not executable!" + return 1 + fi + "${RUNTIPI_CLI}" "${@}" +} + +append_file_param() { + [ -e "${2:?File name missing}" ] || return + echo "${*}" } runtipi-app-docker-compose() { local APP="${1:-Must supply app name}" - local LOCAL_YML="user-config/${APP}/docker-compose.yml" - rph exec runtipi test -e "/srv/runtipi/${LOCAL_YML}" || LOCAL_YML="" - [ -z "$LOCAL_YML" ] || LOCAL_YML="--file ${LOCAL_YML}" - - rph-exec docker compose \ - --env-file user-config/.env.local \ - --env-file app-data/${APP}/app.env \ - --env-file user-config/${APP}/app.env \ + docker compose \ + $(append_file_param --env-file user-config/.env.local) \ + $(append_file_param --env-file app-data/${APP}/app.env) \ + $(append_file_param --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} + $(if [ "$APP" != "runtipi" ]; then + echo --file apps/${APP}/docker-compose.yml + append_file_param --file repos/29ca930bfdaffa1dfabf5726336380ede7066bc53297e3c0c868b27c97282903/apps/docker-compose.common.yml + append_file_param --file "user-config/${APP}/docker-compose.yml" + fi) \ + ${@:2} } dls() { - # Default docker ps format is: - # rph-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" - ROOT_EXEC=1 QUIET=${QUIET:-0} rph-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}//' )" + docker container ls --all --format "$format" | ( sed -u '1s/.*/\U&/; q'; sed -Ee 's|^|555|; s|^555runtipi|000runtipi|;' | sort | sed -Ee 's/^[[:digit:]]{3}//' ) } case "${1}" in cli) runtipi-cli "${@:2}" ;; - log) - rph-exec "POSTGRES_PASSWORD=_ TIPI_VERSION=_ LOCAL_DOMAIN=_ DOMAIN=_" docker compose --env-file user-config/.env.local logs --tail=${TAIL:-40} "${2:-runtipi}" ${3:+"${@:3}"} + log|logs) + POSTGRES_PASSWORD=_ TIPI_VERSION=_ LOCAL_DOMAIN=_ DOMAIN=_ runtipi-app-docker-compose "${2:-runtipi}" logs ${3:+"${@:3}"} ;; start) runtipi-cli start --env-file user-config/.env.local --no-permissions @@ -81,22 +70,8 @@ case "${1}" in update) runtipi-cli update --env-file user-config/.env.local --no-permissions "${2:?Must supply version}" "${@:3}" ;; - full-start) - if ! rph exec runtipi true; then - rph 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 - ;; - shell) - rph-shell - ;; - exec) - rph-exec "${@:2}" - ;; docker) - rph-exec docker "${@:2}" + docker "${@:2}" ;; dls) dls "${@:2}" @@ -105,22 +80,25 @@ case "${1}" in runtipi-app-docker-compose "${@:2}" ;; dockge) - START_DIR=/srv/dockge/stacks/${2:?Must supply stack name} rph-exec docker compose "${@:3}" + cd "${RUNTIPI_ROOT}/../dockge/stacks/${2:?Must supply stack name}" > /dev/null + docker compose "${@:3}" ;; setup) - ln -s $2 "$(cd "$(dirname "$0")" && pwd)/$(basename "$0")" "$HOME/.local/bin/" + ln -s $2 "$(cd -- "${SCRIPT_DIR}" && pwd)/${BASE_NAME}" "${3:-$HOME/.local/bin/}" + ;; + edit) + ${VISUAL:-${EDITOR:-vi}} $0 ;; *) printf '%s %-12s %s\n' \ "" "" ""\ "Usage:" "" ""\ - " $(basename "$0") [args...]" "" ""\ + " ${BASE_NAME} [args...]" "" ""\ "" "" "" \ "Available commands:" "" ""\ "" "" "" \ "runtipi" "" ""\ "" "cli" "runtipi-cli" \ - "" "full-start" "start runtipi jail, following with starting runtipi" \ "" "log" "runtipi docker stack logs" \ "" "start" "start runtipi" \ "" "update" "update runtipi to a specific version" \ @@ -136,6 +114,9 @@ case "${1}" in "" "shell" "enter an insteractive shell" \ "" "" "" \ "" "setup" "setup runtipictl in user's .local/bin dir" \ + "" "" "${BASE_NAME} setup" \ + "" "" "${BASE_NAME} setup '' ~/.local/bin/${BASE_BASE_NAME}" \ + "" "" "${BASE_NAME} setup '' ~/.local/bin/runtipictl" \ "" "" "" \ "Related env. vars:" "" "" \ "" "VISUAL EDITOR RPH_UID QUIET START_DIR ROOT_EXEC" "" @@ -143,3 +124,4 @@ case "${1}" in ;; esac +# vim: set ft=sh expandtab tabstop=4 shiftwidth=4: diff --git a/_bin/rtpctl.j b/_bin/rtpctl.j index 0afccb4..43b8712 100755 --- a/_bin/rtpctl.j +++ b/_bin/rtpctl.j @@ -152,3 +152,4 @@ case "${1}" in ;; esac +# vim: set ft=sh expandtab tabstop=4 shiftwidth=4: