diff --git a/install.sh b/install.sh index f8a4536..8758e55 100644 --- a/install.sh +++ b/install.sh @@ -1163,7 +1163,7 @@ update_background_check() { } update_if_needed() { - + download_if_needed "$@" local lastDownload=$(read_or_default "$UPDATES_DIR/downloaded" "???") @@ -1180,105 +1180,112 @@ update_if_needed() { fi else - local changed=0 - local redeploy=0 - - local instOnlineVer=$(extract_version "$(<"$UPDATES_DIR/install.sh")") - local depEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/deployment.env")") - local nsEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/nightscout.env")") - local compOnlineVer=$(extract_version "$(<"$UPDATES_DIR/docker-compose.yml")") - - local instLocalVer=$(extract_version "$(<"$TOOL_FILE")") - local depEnvLocalVer=$(extract_version "$(<"$ENV_FILE_DEP")") - local nsEnvLocalVer=$(extract_version "$(<"$ENV_FILE_NS")") - local compLocalVer=$(extract_version "$(<"$DOCKER_COMPOSE_FILE")") + if [ $# -eq 0 ] && [ "$UPDATE_CHANNEL" == "master" ] && [[ "$lastDownload" < "$updateInstalled" ]]; then + msgnote "Downgrade not possible on master channel" + forceUpdateCheck=1 + download_if_needed + else - local msgInst="$(printf "\U1F7E2") $instLocalVer" - local msgDep="$(printf "\U1F7E2") $depEnvLocalVer" - local msgNs="$(printf "\U1F7E2") $nsEnvLocalVer" - local msgComp="$(printf "\U1F7E2") $compLocalVer" + local changed=0 + local redeploy=0 - if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then - changed=$((changed + 1)) - msgInst="$(printf "\U1F534") $instLocalVer $(printf "\U27A1") $instOnlineVer" - fi + local instOnlineVer=$(extract_version "$(<"$UPDATES_DIR/install.sh")") + local depEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/deployment.env")") + local nsEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/nightscout.env")") + local compOnlineVer=$(extract_version "$(<"$UPDATES_DIR/docker-compose.yml")") - if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then - changed=$((changed + 1)) - redeploy=$((redeploy + 1)) - msgDep="$(printf "\U1F534") $depEnvLocalVer $(printf "\U27A1") $depEnvOnlineVer" - fi + local instLocalVer=$(extract_version "$(<"$TOOL_FILE")") + local depEnvLocalVer=$(extract_version "$(<"$ENV_FILE_DEP")") + local nsEnvLocalVer=$(extract_version "$(<"$ENV_FILE_NS")") + local compLocalVer=$(extract_version "$(<"$DOCKER_COMPOSE_FILE")") - if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then - changed=$((changed + 1)) - redeploy=$((redeploy + 1)) - msgNs="$(printf "\U1F534") $nsEnvLocalVer $(printf "\U27A1") $nsEnvOnlineVer" - fi + local msgInst="$(printf "\U1F7E2") $instLocalVer" + local msgDep="$(printf "\U1F7E2") $depEnvLocalVer" + local msgNs="$(printf "\U1F7E2") $nsEnvLocalVer" + local msgComp="$(printf "\U1F7E2") $compLocalVer" - if ! [ "$compLocalVer" == "$compOnlineVer" ]; then - changed=$((changed + 1)) - redeploy=$((redeploy + 1)) - msgComp="$(printf "\U1F534") $compLocalVer $(printf "\U27A1") $compOnlineVer" - fi - - if [ "$changed" -eq 0 ]; then - if [ $# -eq 1 ]; then - msgok "Scripts and config files are up to date" - okdlg "Aktualizacja skryptów" "$1" - fi - else - local okTxt="" - if [ "$redeploy" -gt 0 ]; then - okTxt="${TL}${uni_warn} Aktualizacja zrestartuje i zaktualizuje kontenery ${uni_warn}" + if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then + changed=$((changed + 1)) + msgInst="$(printf "\U1F534") $instLocalVer $(printf "\U27A1") $instOnlineVer" fi - local versionMsg="${TL}Build: ${updateInstalled}" - if [ ! "$lastDownload" == "$updateInstalled" ]; then - versionMsg="$(pad_multiline "${TL}Masz build: ${updateInstalled}${NL} Dostępny: ${lastDownload}")" + if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then + changed=$((changed + 1)) + redeploy=$((redeploy + 1)) + msgDep="$(printf "\U1F534") $depEnvLocalVer $(printf "\U27A1") $depEnvOnlineVer" fi - yesnodlg "Aktualizacja skryptów" "$uni_confirm_upd" "$uni_resign" \ - "Zalecana jest aktualizacja plików:${versionMsg}" \ - "$( - pad_multiline \ - "${TL}${uni_bullet}Skrypt instalacyjny: $msgInst" \ - "${NL}${uni_bullet}Konfiguracja deploymentu: $msgDep" \ - "${NL}${uni_bullet}Konfiguracja Nightscout: $msgNs" \ - "${NL}${uni_bullet}Kompozycja usług: $msgComp${NL}" - )" \ - "$okTxt" - - if ! [ $? -eq 1 ]; then + if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then + changed=$((changed + 1)) + redeploy=$((redeploy + 1)) + msgNs="$(printf "\U1F534") $nsEnvLocalVer $(printf "\U27A1") $nsEnvOnlineVer" + fi - clear_last_time "update_needed" + if ! [ "$compLocalVer" == "$compOnlineVer" ]; then + changed=$((changed + 1)) + redeploy=$((redeploy + 1)) + msgComp="$(printf "\U1F534") $compLocalVer $(printf "\U27A1") $compOnlineVer" + fi + if [ "$changed" -eq 0 ]; then + if [ $# -eq 1 ]; then + msgok "Scripts and config files are up to date" + okdlg "Aktualizacja skryptów" "$1" + fi + else + local okTxt="" if [ "$redeploy" -gt 0 ]; then - docker_compose_down + okTxt="${TL}${uni_warn} Aktualizacja zrestartuje i zaktualizuje kontenery ${uni_warn}" fi - if ! [ "$compOnlineVer" == "$compLocalVer" ]; then - ohai "Updating $DOCKER_COMPOSE_FILE" - cp -fr "$UPDATES_DIR/docker-compose.yml" "$DOCKER_COMPOSE_FILE" + local versionMsg="${TL}Build: ${updateInstalled}" + if [ ! "$lastDownload" == "$updateInstalled" ]; then + versionMsg="$(pad_multiline "${TL}Masz build: ${updateInstalled}${NL} Dostępny: ${lastDownload}")" fi - if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then - ohai "Updating $ENV_FILE_DEP" - dotenv-tool -pr -o "$ENV_FILE_DEP" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_DEP" - fi + yesnodlg "Aktualizacja skryptów" "$uni_confirm_upd" "$uni_resign" \ + "Zalecana jest aktualizacja plików:${versionMsg}" \ + "$( + pad_multiline \ + "${TL}${uni_bullet}Skrypt instalacyjny: $msgInst" \ + "${NL}${uni_bullet}Konfiguracja deploymentu: $msgDep" \ + "${NL}${uni_bullet}Konfiguracja Nightscout: $msgNs" \ + "${NL}${uni_bullet}Kompozycja usług: $msgComp${NL}" + )" \ + "$okTxt" - if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then - ohai "Updating $ENV_FILE_NS" - dotenv-tool -pr -o "$ENV_FILE_NS" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_NS" - fi + if ! [ $? -eq 1 ]; then + + clear_last_time "update_needed" + + if [ "$redeploy" -gt 0 ]; then + docker_compose_down + fi - echo "$lastDownload" >"$UPDATES_DIR/updated" + if ! [ "$compOnlineVer" == "$compLocalVer" ]; then + ohai "Updating $DOCKER_COMPOSE_FILE" + cp -fr "$UPDATES_DIR/docker-compose.yml" "$DOCKER_COMPOSE_FILE" + fi + + if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then + ohai "Updating $ENV_FILE_DEP" + dotenv-tool -pr -o "$ENV_FILE_DEP" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_DEP" + fi - if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then - ohai "Updating $TOOL_FILE" - cp -fr "$UPDATES_DIR/install.sh" "$TOOL_FILE" - okdlg "Aktualizacja zakończona" "Narzędzie zostanie uruchomione ponownie" - ohai "Restarting tool" - exec "$TOOL_FILE" + if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then + ohai "Updating $ENV_FILE_NS" + dotenv-tool -pr -o "$ENV_FILE_NS" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_NS" + fi + + echo "$lastDownload" >"$UPDATES_DIR/updated" + + if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then + ohai "Updating $TOOL_FILE" + cp -fr "$UPDATES_DIR/install.sh" "$TOOL_FILE" + okdlg "Aktualizacja zakończona" "Narzędzie zostanie uruchomione ponownie" + ohai "Restarting tool" + exec "$TOOL_FILE" + fi fi fi fi diff --git a/src/lib.sh b/src/lib.sh index b48b561..3fa7bb2 100644 --- a/src/lib.sh +++ b/src/lib.sh @@ -1147,7 +1147,7 @@ update_background_check() { } update_if_needed() { - + download_if_needed "$@" local lastDownload=$(read_or_default "$UPDATES_DIR/downloaded" "???") @@ -1164,105 +1164,112 @@ update_if_needed() { fi else - local changed=0 - local redeploy=0 - - local instOnlineVer=$(extract_version "$(<"$UPDATES_DIR/install.sh")") - local depEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/deployment.env")") - local nsEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/nightscout.env")") - local compOnlineVer=$(extract_version "$(<"$UPDATES_DIR/docker-compose.yml")") - - local instLocalVer=$(extract_version "$(<"$TOOL_FILE")") - local depEnvLocalVer=$(extract_version "$(<"$ENV_FILE_DEP")") - local nsEnvLocalVer=$(extract_version "$(<"$ENV_FILE_NS")") - local compLocalVer=$(extract_version "$(<"$DOCKER_COMPOSE_FILE")") + if [ $# -eq 0 ] && [ "$UPDATE_CHANNEL" == "master" ] && [[ "$lastDownload" < "$updateInstalled" ]]; then + msgnote "Downgrade not possible on master channel" + forceUpdateCheck=1 + download_if_needed + else - local msgInst="$(printf "\U1F7E2") $instLocalVer" - local msgDep="$(printf "\U1F7E2") $depEnvLocalVer" - local msgNs="$(printf "\U1F7E2") $nsEnvLocalVer" - local msgComp="$(printf "\U1F7E2") $compLocalVer" + local changed=0 + local redeploy=0 - if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then - changed=$((changed + 1)) - msgInst="$(printf "\U1F534") $instLocalVer $(printf "\U27A1") $instOnlineVer" - fi + local instOnlineVer=$(extract_version "$(<"$UPDATES_DIR/install.sh")") + local depEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/deployment.env")") + local nsEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/nightscout.env")") + local compOnlineVer=$(extract_version "$(<"$UPDATES_DIR/docker-compose.yml")") - if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then - changed=$((changed + 1)) - redeploy=$((redeploy + 1)) - msgDep="$(printf "\U1F534") $depEnvLocalVer $(printf "\U27A1") $depEnvOnlineVer" - fi + local instLocalVer=$(extract_version "$(<"$TOOL_FILE")") + local depEnvLocalVer=$(extract_version "$(<"$ENV_FILE_DEP")") + local nsEnvLocalVer=$(extract_version "$(<"$ENV_FILE_NS")") + local compLocalVer=$(extract_version "$(<"$DOCKER_COMPOSE_FILE")") - if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then - changed=$((changed + 1)) - redeploy=$((redeploy + 1)) - msgNs="$(printf "\U1F534") $nsEnvLocalVer $(printf "\U27A1") $nsEnvOnlineVer" - fi + local msgInst="$(printf "\U1F7E2") $instLocalVer" + local msgDep="$(printf "\U1F7E2") $depEnvLocalVer" + local msgNs="$(printf "\U1F7E2") $nsEnvLocalVer" + local msgComp="$(printf "\U1F7E2") $compLocalVer" - if ! [ "$compLocalVer" == "$compOnlineVer" ]; then - changed=$((changed + 1)) - redeploy=$((redeploy + 1)) - msgComp="$(printf "\U1F534") $compLocalVer $(printf "\U27A1") $compOnlineVer" - fi - - if [ "$changed" -eq 0 ]; then - if [ $# -eq 1 ]; then - msgok "Scripts and config files are up to date" - okdlg "Aktualizacja skryptów" "$1" - fi - else - local okTxt="" - if [ "$redeploy" -gt 0 ]; then - okTxt="${TL}${uni_warn} Aktualizacja zrestartuje i zaktualizuje kontenery ${uni_warn}" + if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then + changed=$((changed + 1)) + msgInst="$(printf "\U1F534") $instLocalVer $(printf "\U27A1") $instOnlineVer" fi - local versionMsg="${TL}Build: ${updateInstalled}" - if [ ! "$lastDownload" == "$updateInstalled" ]; then - versionMsg="$(pad_multiline "${TL}Masz build: ${updateInstalled}${NL} Dostępny: ${lastDownload}")" + if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then + changed=$((changed + 1)) + redeploy=$((redeploy + 1)) + msgDep="$(printf "\U1F534") $depEnvLocalVer $(printf "\U27A1") $depEnvOnlineVer" fi - yesnodlg "Aktualizacja skryptów" "$uni_confirm_upd" "$uni_resign" \ - "Zalecana jest aktualizacja plików:${versionMsg}" \ - "$( - pad_multiline \ - "${TL}${uni_bullet}Skrypt instalacyjny: $msgInst" \ - "${NL}${uni_bullet}Konfiguracja deploymentu: $msgDep" \ - "${NL}${uni_bullet}Konfiguracja Nightscout: $msgNs" \ - "${NL}${uni_bullet}Kompozycja usług: $msgComp${NL}" - )" \ - "$okTxt" - - if ! [ $? -eq 1 ]; then + if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then + changed=$((changed + 1)) + redeploy=$((redeploy + 1)) + msgNs="$(printf "\U1F534") $nsEnvLocalVer $(printf "\U27A1") $nsEnvOnlineVer" + fi - clear_last_time "update_needed" + if ! [ "$compLocalVer" == "$compOnlineVer" ]; then + changed=$((changed + 1)) + redeploy=$((redeploy + 1)) + msgComp="$(printf "\U1F534") $compLocalVer $(printf "\U27A1") $compOnlineVer" + fi + if [ "$changed" -eq 0 ]; then + if [ $# -eq 1 ]; then + msgok "Scripts and config files are up to date" + okdlg "Aktualizacja skryptów" "$1" + fi + else + local okTxt="" if [ "$redeploy" -gt 0 ]; then - docker_compose_down + okTxt="${TL}${uni_warn} Aktualizacja zrestartuje i zaktualizuje kontenery ${uni_warn}" fi - if ! [ "$compOnlineVer" == "$compLocalVer" ]; then - ohai "Updating $DOCKER_COMPOSE_FILE" - cp -fr "$UPDATES_DIR/docker-compose.yml" "$DOCKER_COMPOSE_FILE" + local versionMsg="${TL}Build: ${updateInstalled}" + if [ ! "$lastDownload" == "$updateInstalled" ]; then + versionMsg="$(pad_multiline "${TL}Masz build: ${updateInstalled}${NL} Dostępny: ${lastDownload}")" fi - if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then - ohai "Updating $ENV_FILE_DEP" - dotenv-tool -pr -o "$ENV_FILE_DEP" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_DEP" - fi + yesnodlg "Aktualizacja skryptów" "$uni_confirm_upd" "$uni_resign" \ + "Zalecana jest aktualizacja plików:${versionMsg}" \ + "$( + pad_multiline \ + "${TL}${uni_bullet}Skrypt instalacyjny: $msgInst" \ + "${NL}${uni_bullet}Konfiguracja deploymentu: $msgDep" \ + "${NL}${uni_bullet}Konfiguracja Nightscout: $msgNs" \ + "${NL}${uni_bullet}Kompozycja usług: $msgComp${NL}" + )" \ + "$okTxt" - if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then - ohai "Updating $ENV_FILE_NS" - dotenv-tool -pr -o "$ENV_FILE_NS" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_NS" - fi + if ! [ $? -eq 1 ]; then + + clear_last_time "update_needed" + + if [ "$redeploy" -gt 0 ]; then + docker_compose_down + fi - echo "$lastDownload" >"$UPDATES_DIR/updated" + if ! [ "$compOnlineVer" == "$compLocalVer" ]; then + ohai "Updating $DOCKER_COMPOSE_FILE" + cp -fr "$UPDATES_DIR/docker-compose.yml" "$DOCKER_COMPOSE_FILE" + fi + + if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then + ohai "Updating $ENV_FILE_DEP" + dotenv-tool -pr -o "$ENV_FILE_DEP" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_DEP" + fi - if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then - ohai "Updating $TOOL_FILE" - cp -fr "$UPDATES_DIR/install.sh" "$TOOL_FILE" - okdlg "Aktualizacja zakończona" "Narzędzie zostanie uruchomione ponownie" - ohai "Restarting tool" - exec "$TOOL_FILE" + if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then + ohai "Updating $ENV_FILE_NS" + dotenv-tool -pr -o "$ENV_FILE_NS" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_NS" + fi + + echo "$lastDownload" >"$UPDATES_DIR/updated" + + if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then + ohai "Updating $TOOL_FILE" + cp -fr "$UPDATES_DIR/install.sh" "$TOOL_FILE" + okdlg "Aktualizacja zakończona" "Narzędzie zostanie uruchomione ponownie" + ohai "Restarting tool" + exec "$TOOL_FILE" + fi fi fi fi diff --git a/updated b/updated index fa64a13..038a788 100644 --- a/updated +++ b/updated @@ -1 +1 @@ -2024-10-26T07:55:59.620Z \ No newline at end of file +2024-10-26T08:38:49.153Z \ No newline at end of file