develop
Dominik Dzienia 3 weeks ago
parent dbefb5f55f
commit 10d8c0ac10

@ -1,3 +1,14 @@
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#dev-begin:
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# IMPORTS
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# shellcheck source=./headers.sh
source ./headers.sh
#dev-end
#======================================= #=======================================
# CLEANUP UI # CLEANUP UI
#======================================= #=======================================
@ -112,4 +123,4 @@ cleanup_menu() {
;; ;;
esac esac
done done
} }

@ -1,3 +1,6 @@
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# UPGRADE # UPGRADE
#======================================= #=======================================
@ -117,7 +120,8 @@ download_if_needed() {
local lastCheck=$(read_or_default "$UPDATES_DIR/timestamp") local lastCheck=$(read_or_default "$UPDATES_DIR/timestamp")
local lastDownload=$(read_or_default "$UPDATES_DIR/downloaded" "") local lastDownload=$(read_or_default "$UPDATES_DIR/downloaded" "")
local timestampNow=$(date +%s) local timestampNow=$(date +%s)
local updateCheck=$UPDATE_CHECK local updateCheck=$UPDATE_CHECK]
#shellcheck disable=SC2154
if (((timestampNow - lastCheck) > updateCheck)) || [ "$lastDownload" == "" ] || [ "$lastDownload" == "error" ] || ((forceUpdateCheck == 1)) || [ $# -eq 1 ]; then if (((timestampNow - lastCheck) > updateCheck)) || [ "$lastDownload" == "" ] || [ "$lastDownload" == "error" ] || ((forceUpdateCheck == 1)) || [ $# -eq 1 ]; then
echo "$timestampNow" >"$UPDATES_DIR/timestamp" echo "$timestampNow" >"$UPDATES_DIR/timestamp"
ohai "Checking if new version is available..." ohai "Checking if new version is available..."
@ -156,7 +160,7 @@ download_update_forced() {
ohai "GitHub failed, retrying with Gitea (version check)..." ohai "GitHub failed, retrying with Gitea (version check)..."
onlineUpdated=$(curl -fsSL "$url" 2>>"$LOGTO") onlineUpdated=$(curl -fsSL "$url" 2>>"$LOGTO")
fi fi
if [ "$onlineUpdated" == "$lastDownload" ]; then if [ "$onlineUpdated" == "$lastDownload" ]; then
msgdebug "Downloaded update will be the same as last downloaded" msgdebug "Downloaded update will be the same as last downloaded"
fi fi
@ -165,7 +169,7 @@ download_update_forced() {
download_updates download_updates
} }
#shellcheck disable=SC2154
do_update_tool() { do_update_tool() {
download_update_forced download_update_forced
@ -173,113 +177,113 @@ do_update_tool() {
local updateInstalled=$(read_or_default "$UPDATES_DIR/updated" "???") local updateInstalled=$(read_or_default "$UPDATES_DIR/updated" "???")
if [ "$lastDownload" == "error" ]; then if [ "$lastDownload" == "error" ]; then
msgerr "Aktualizacja niemożliwa" msgerr "Aktualizacja niemożliwa"
msgerr "Nie można w tej chwili aktualizować narzędzia.${TL}Spróbuj ponownie później.${NL}Jeśli problem nie ustąpi - sprawdź konfigurację kanału aktualizacji" msgerr "Nie można w tej chwili aktualizować narzędzia.${TL}Spróbuj ponownie później.${NL}Jeśli problem nie ustąpi - sprawdź konfigurację kanału aktualizacji"
else else
if [ "$UPDATE_CHANNEL" == "master" ] && [[ "$lastDownload" < "$updateInstalled" ]]; then if [ "$UPDATE_CHANNEL" == "master" ] && [[ "$lastDownload" < "$updateInstalled" ]]; then
warn "Downgrade na produkcyjnym kanale aktualizacji!" warn "Downgrade na produkcyjnym kanale aktualizacji!"
fi fi
local changed=0 local changed=0
local redeploy=0 local redeploy=0
local instOnlineVer=$(extract_version "$(<"$UPDATES_DIR/install.sh")") local instOnlineVer=$(extract_version "$(<"$UPDATES_DIR/install.sh")")
local depEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/deployment.env")") local depEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/deployment.env")")
local nsEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/nightscout.env")") local nsEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/nightscout.env")")
local compOnlineVer=$(extract_version "$(<"$UPDATES_DIR/docker-compose.yml")") local compOnlineVer=$(extract_version "$(<"$UPDATES_DIR/docker-compose.yml")")
local instLocalVer=$(extract_version "$(<"$TOOL_FILE")") local instLocalVer=$(extract_version "$(<"$TOOL_FILE")")
local depEnvLocalVer=$(extract_version "$(<"$ENV_FILE_DEP")") local depEnvLocalVer=$(extract_version "$(<"$ENV_FILE_DEP")")
local nsEnvLocalVer=$(extract_version "$(<"$ENV_FILE_NS")") local nsEnvLocalVer=$(extract_version "$(<"$ENV_FILE_NS")")
local compLocalVer=$(extract_version "$(<"$DOCKER_COMPOSE_FILE")") local compLocalVer=$(extract_version "$(<"$DOCKER_COMPOSE_FILE")")
local msgInst="$(printf "\U1F7E2") $instLocalVer" local msgInst="$(printf "\U1F7E2") $instLocalVer"
local msgDep="$(printf "\U1F7E2") $depEnvLocalVer" local msgDep="$(printf "\U1F7E2") $depEnvLocalVer"
local msgNs="$(printf "\U1F7E2") $nsEnvLocalVer" local msgNs="$(printf "\U1F7E2") $nsEnvLocalVer"
local msgComp="$(printf "\U1F7E2") $compLocalVer" local msgComp="$(printf "\U1F7E2") $compLocalVer"
if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then
changed=$((changed + 1)) changed=$((changed + 1))
msgInst="$(printf "\U1F534") $instLocalVer $(printf "\U27A1") $instOnlineVer" msgInst="$(printf "\U1F534") $instLocalVer $(printf "\U27A1") $instOnlineVer"
fi fi
if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then
changed=$((changed + 1)) changed=$((changed + 1))
redeploy=$((redeploy + 1)) redeploy=$((redeploy + 1))
msgDep="$(printf "\U1F534") $depEnvLocalVer $(printf "\U27A1") $depEnvOnlineVer" msgDep="$(printf "\U1F534") $depEnvLocalVer $(printf "\U27A1") $depEnvOnlineVer"
fi fi
if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then
changed=$((changed + 1)) changed=$((changed + 1))
redeploy=$((redeploy + 1)) redeploy=$((redeploy + 1))
msgNs="$(printf "\U1F534") $nsEnvLocalVer $(printf "\U27A1") $nsEnvOnlineVer" msgNs="$(printf "\U1F534") $nsEnvLocalVer $(printf "\U27A1") $nsEnvOnlineVer"
fi fi
if ! [ "$compLocalVer" == "$compOnlineVer" ]; then if ! [ "$compLocalVer" == "$compOnlineVer" ]; then
changed=$((changed + 1)) changed=$((changed + 1))
redeploy=$((redeploy + 1)) redeploy=$((redeploy + 1))
msgComp="$(printf "\U1F534") $compLocalVer $(printf "\U27A1") $compOnlineVer" msgComp="$(printf "\U1F534") $compLocalVer $(printf "\U27A1") $compOnlineVer"
fi fi
local okTxt="" local okTxt=""
if [ "$redeploy" -gt 0 ]; then if [ "$redeploy" -gt 0 ]; then
okTxt="${TL}${uni_warn} Aktualizacja zrestartuje i zaktualizuje kontenery ${uni_warn}" okTxt="${TL}${uni_warn} Aktualizacja zrestartuje i zaktualizuje kontenery ${uni_warn}"
fi fi
local versionMsg="${TL}Build: ${updateInstalled}" local versionMsg="${TL}Build: ${updateInstalled}"
if [ ! "$lastDownload" == "$updateInstalled" ]; then if [ ! "$lastDownload" == "$updateInstalled" ]; then
versionMsg="$(pad_multiline "${TL}Masz build: ${updateInstalled}${NL} Dostępny: ${lastDownload}")" versionMsg="$(pad_multiline "${TL}Masz build: ${updateInstalled}${NL} Dostępny: ${lastDownload}")"
fi fi
hline hline
echo -e "Aktualizacja plików:" "${versionMsg}" \ echo -e "Aktualizacja plików:" "${versionMsg}" \
"$( "$(
pad_multiline \ pad_multiline \
"${TL}${uni_bullet}Skrypt instalacyjny: $msgInst" \ "${TL}${uni_bullet}Skrypt instalacyjny: $msgInst" \
"${NL}${uni_bullet}Konfiguracja deploymentu: $msgDep" \ "${NL}${uni_bullet}Konfiguracja deploymentu: $msgDep" \
"${NL}${uni_bullet}Konfiguracja Nightscout: $msgNs" \ "${NL}${uni_bullet}Konfiguracja Nightscout: $msgNs" \
"${NL}${uni_bullet}Kompozycja usług: $msgComp${NL}" "${NL}${uni_bullet}Kompozycja usług: $msgComp${NL}"
)" \ )" \
"$okTxt" "$okTxt"
hline hline
clear_last_time "update_needed" clear_last_time "update_needed"
if [ "$redeploy" -gt 0 ]; then if [ "$redeploy" -gt 0 ]; then
ohai "Redeploy - uninstalling containers" ohai "Redeploy - uninstalling containers"
uninstall_containers uninstall_containers
fi fi
if ! [ "$compOnlineVer" == "$compLocalVer" ]; then if ! [ "$compOnlineVer" == "$compLocalVer" ]; then
ohai "Updating $DOCKER_COMPOSE_FILE" ohai "Updating $DOCKER_COMPOSE_FILE"
cp -fr "$UPDATES_DIR/docker-compose.yml" "$DOCKER_COMPOSE_FILE" cp -fr "$UPDATES_DIR/docker-compose.yml" "$DOCKER_COMPOSE_FILE"
fi fi
if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then
ohai "Updating $ENV_FILE_DEP" ohai "Updating $ENV_FILE_DEP"
dotenv-tool -pr -o "$ENV_FILE_DEP" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_DEP" dotenv-tool -pr -o "$ENV_FILE_DEP" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_DEP"
fi fi
if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then
ohai "Updating $ENV_FILE_NS" ohai "Updating $ENV_FILE_NS"
dotenv-tool -pr -o "$ENV_FILE_NS" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_NS" dotenv-tool -pr -o "$ENV_FILE_NS" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_NS"
fi fi
echo "$lastDownload" >"$UPDATES_DIR/updated" echo "$lastDownload" >"$UPDATES_DIR/updated"
if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then
ohai "Updating $TOOL_FILE" ohai "Updating $TOOL_FILE"
cp -fr "$UPDATES_DIR/install.sh" "$TOOL_FILE" cp -fr "$UPDATES_DIR/install.sh" "$TOOL_FILE"
fi fi
if [ "$redeploy" -gt 0 ]; then if [ "$redeploy" -gt 0 ]; then
ohai "Redeploy - installing containers" ohai "Redeploy - installing containers"
install_containers install_containers
fi fi
hline hline
msgok "Aktualizacja zakończona" msgok "Aktualizacja zakończona"
# fi # fi
fi fi
} }

Loading…
Cancel
Save