From 520a20479e6c4d07aadc5bb1324d729f5effa5eb Mon Sep 17 00:00:00 2001 From: Sz Date: Mon, 8 May 2023 23:08:59 -0400 Subject: [PATCH] =initial commit --- delete-all-catalogs.sh | 19 +++++++ setup-catalog.sh | 16 ++++++ shut-down-procedure.sh | 11 ++++ start-all-charts.sh | 111 +++++++++++++++++++++++++++++++++++++++++ startup-procedure.sh | 14 ++++++ stop-all-chrats.sh | 35 +++++++++++++ 6 files changed, 206 insertions(+) create mode 100755 delete-all-catalogs.sh create mode 100755 setup-catalog.sh create mode 100755 shut-down-procedure.sh create mode 100755 start-all-charts.sh create mode 100755 startup-procedure.sh create mode 100755 stop-all-chrats.sh diff --git a/delete-all-catalogs.sh b/delete-all-catalogs.sh new file mode 100755 index 0000000..bd78df4 --- /dev/null +++ b/delete-all-catalogs.sh @@ -0,0 +1,19 @@ +#! /usr/bin/env bash +set -e + +get_catalogs() { + midclt call catalog.query | jq -r '.[] | .label' | grep -v 'OFFICIAL' +} + +delete_catalog() { + local CATALOG="${1}" + printf 'Deleting catalog: %s... ' "$CATALOG" + midclt call catalog.delete "$CATALOG" + printf '\n' +} + +get_catalogs | while read catalog; do + [[ -n "$catalog" ]] || continue + delete_catalog "$catalog" +done + diff --git a/setup-catalog.sh b/setup-catalog.sh new file mode 100755 index 0000000..deeb8ac --- /dev/null +++ b/setup-catalog.sh @@ -0,0 +1,16 @@ +#! /usr/bin/env bash +set -e + +setup_catalog() { + printf 'Setting up catalog: truecharts...' + + midclt call catalog.create '{ + "label": "truecharts", + "repository": "https://github.com/truecharts/catalog", + "branch": "main", + "preferred_trains": ["stable", "dependency", "enterprise"] + }' + printf '\n' +} + +setup_catalog diff --git a/shut-down-procedure.sh b/shut-down-procedure.sh new file mode 100755 index 0000000..2445c1d --- /dev/null +++ b/shut-down-procedure.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env bash +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +USER_HOME=$HOME +[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")" +. ${SHRC_D:-$USER_HOME/.pqb.shrc.d}/01_util.functions + +set -e + +${SCRIPT_DIR}/delete-all-catalogs.sh +${SCRIPT_DIR}/stop-all-chrats.sh + diff --git a/start-all-charts.sh b/start-all-charts.sh new file mode 100755 index 0000000..c980444 --- /dev/null +++ b/start-all-charts.sh @@ -0,0 +1,111 @@ +#! /usr/bin/env bash +set -e + +get_charts() { + midclt call chart.release.query | jq -r ' + .[] + | select( .status == "STOPPED" ) + | .id + ' +} + +get_charts_by_category() { + local CATEGORY="${1}" + midclt call chart.release.query | jq -r ' + .[] + | select ( .chart_metadata.annotations."truecharts.org/catagories" == "- '"$CATEGORY"'\n" ) + | .id + ' +} + +start_chart_category() { + local CATEGORY="${1}" + printf "Starting apps by category: %s\n" "$CATEGORY" + get_charts_by_category "$CATEGORY" | while read chart; do + start_chart $chart + done + wait_for_idle_queue +} + +start_chart() { + local CHART="${1}" + printf 'Starting charts: %s... ' "$CHART" + midclt call chart.release.scale "$CHART" '{"replica_count": 1}' + printf '\n' +} + +count_unfinished_jobs() { + midclt call core.get_jobs | jq -r '.[] | select( .time_finished == null )' | wc -l +} + +wait_for_idle_queue() { + while [[ "$( count_unfinished_jobs )" -gt 0 ]]; do + printf '.' + sleep 2 + done + printf '\n' +} + +safe_start_chart() { + wait_for_idle_queue + start_chart "${1}" +} + +wait_for_idle_queue +start_chart cloudflareddns +start_chart_category network +start_chart_category networking +start_chart_category authentication +start_chart uptime-kuma + +safe_start_chart plex-pms +safe_start_chart unifi + +start_chart homepage +start_chart it-tools +start_chart haste + +safe_start_chart shlink +start_chart shlink-frontend +safe_start_chart ferdi + +start_chart hammond +start_chart monica +start_chart languagetool +safe_start_chart paperless-ng +safe_start_chart gitea +safe_start_chart immich +safe_start_chart syncthing + +start_chart nzbget +start_chart deluge +start_chart prowlarr +safe_start_chart lunasea +safe_start_chart jdownloader +safe_start_chart calibre +safe_start_chart bazarr +safe_start_chart sonarr +safe_start_chart radarr +safe_start_chart tdarr + +# start_chart deepstack +# start_chart docker-compose +# start_chart firefox-syncserver +# start_chart gerev +# start_chart grocy +# start_chart homarr +# start_chart jellyfin +# start_chart jellyseerr +# start_chart mango +# start_chart plex-auto-languages +# start_chart portainer +# start_chart qbittorrent +# start_chart scratch-map +# start_chart silverbullet +# start_chart stash +# start_chart trilium-notes +# start_chart wger +# start_chart whoami + +wait_for_idle_queue + diff --git a/startup-procedure.sh b/startup-procedure.sh new file mode 100755 index 0000000..c1962bd --- /dev/null +++ b/startup-procedure.sh @@ -0,0 +1,14 @@ +#! /usr/bin/env bash +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +USER_HOME=$HOME +[[ -n "${SUDO_USER}" ]] && USER_HOME="$(eval "echo ~${SUDO_USER}")" +. ${SHRC_D:-$USER_HOME/.pqb.shrc.d}/01_util.functions + +set -e + +${SCRIPT_DIR}/start-all-charts.sh +printf 'Sleeping for 20 seconds...' +sleep 20s +printf '\n' +${SCRIPT_DIR}/setup-catalog.sh + diff --git a/stop-all-chrats.sh b/stop-all-chrats.sh new file mode 100755 index 0000000..afc89a0 --- /dev/null +++ b/stop-all-chrats.sh @@ -0,0 +1,35 @@ +#! /usr/bin/env bash +set -e + +get_charts() { + midclt call chart.release.query | jq -r '.[] | select( .status != "STOPPED" ) | .id' +} + +stop_chart() { + local CHART="${1}" + printf 'Stopping charts: %s... ' "$CHART" + midclt call chart.release.scale "$CHART" '{"replica_count": 0}' + printf '\n' +} + +stop_all_charts() { + get_charts | while read chart; do + [[ -n "$chart" ]] || continue + stop_chart "$chart" + done +} + +count_unfinished_jobs() { + midclt call core.get_jobs | jq -r '.[] | select( .time_finished == null )' | wc -l +} + +while [[ "$( get_charts | wc -l )" -gt 0 ]]; do + stop_all_charts + + while [[ "$( count_unfinished_jobs )" -gt 0 ]]; do + printf '.' + sleep 2 + done + printf '\n' +done +