@ -1094,12 +1094,18 @@ read_or_default() {
download_updates( ) {
download_updates( ) {
ohai "Downloading updated scripts and config files"
ohai "Downloading updated scripts and config files"
curl -fsSL -o " $UPDATES_DIR /install.sh " " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /install.sh "
local onlineUpdated = " $( curl -fsSL " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /updated " ) "
curl -fsSL -o " $UPDATES_DIR /deployment.env " " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /templates/deployment.env "
if [ ! " $onlineUpdated " = = "" ] ; then
curl -fsSL -o " $UPDATES_DIR /nightscout.env " " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /templates/nightscout.env "
curl -fsSL -o " $UPDATES_DIR /install.sh " " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /install.sh "
curl -fsSL -o " $UPDATES_DIR /docker-compose.yml " " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /templates/docker-compose.yml "
curl -fsSL -o " $UPDATES_DIR /deployment.env " " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /templates/deployment.env "
curl -fsSL -o " $PROFANITY_DB_FILE " "https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/profanity/templates/profanity.db"
curl -fsSL -o " $UPDATES_DIR /nightscout.env " " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /templates/nightscout.env "
curl -fsSL -o " $RESERVED_DB_FILE " "https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/profanity/templates/reserved.db"
curl -fsSL -o " $UPDATES_DIR /docker-compose.yml " " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /templates/docker-compose.yml "
curl -fsSL -o " $PROFANITY_DB_FILE " "https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/profanity/templates/profanity.db"
curl -fsSL -o " $RESERVED_DB_FILE " "https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/profanity/templates/reserved.db"
else
onlineUpdated = "error"
fi
echo " $onlineUpdated " >" $UPDATES_DIR /downloaded "
}
}
download_if_needed( ) {
download_if_needed( ) {
@ -1107,7 +1113,7 @@ download_if_needed() {
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
if ( ( ( timestampNow - lastCheck) > updateCheck) ) || [ " $lastDownload " = = "" ] || (( forceUpdateCheck = = 1) ) ; then
if ( ( ( timestampNow - lastCheck) > updateCheck) ) || [ " $lastDownload " = = "" ] || [ " $lastDownload " = = "error" ] || (( forceUpdateCheck = = 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..."
local onlineUpdated = " $( curl -fsSL " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /updated " ) "
local onlineUpdated = " $( curl -fsSL " https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch/ $UPDATE_CHANNEL /updated " ) "
@ -1115,7 +1121,6 @@ download_if_needed() {
if [ " $onlineUpdated " = = " $lastDownload " ] && ( ( forceUpdateCheck = = 0) ) ; then
if [ " $onlineUpdated " = = " $lastDownload " ] && ( ( forceUpdateCheck = = 0) ) ; then
msgok "Latest update already downloaded"
msgok "Latest update already downloaded"
else
else
echo " $onlineUpdated " >" $UPDATES_DIR /downloaded "
download_updates
download_updates
fi
fi
else
else
@ -1129,7 +1134,7 @@ update_background_check() {
local lastDownload = $( read_or_default " $UPDATES_DIR /downloaded " "" )
local lastDownload = $( read_or_default " $UPDATES_DIR /downloaded " "" )
local updateInstalled = $( read_or_default " $UPDATES_DIR /updated " "" )
local updateInstalled = $( read_or_default " $UPDATES_DIR /updated " "" )
if [ ! " $lastDownload " = = " $updateInstalled " ] ; then
if [ ! " $lastDownload " = = " $updateInstalled " ] && [ ! " $lastDownload " = = "" ] && [ ! " $lastDownload " = = "error" ] ; then
echo "Update needed"
echo "Update needed"
local lastCalled = $( get_since_last_time "update_needed" )
local lastCalled = $( get_since_last_time "update_needed" )
if ( ( lastCalled = = -1) ) || ( ( lastCalled > UPDATE_MAIL) ) ; then
if ( ( lastCalled = = -1) ) || ( ( lastCalled > UPDATE_MAIL) ) ; then
@ -1168,107 +1173,114 @@ update_if_needed() {
msgok "Scripts and config files are up to date"
msgok "Scripts and config files are up to date"
else
else
local changed = 0
if [ " $lastDownload " = = "error" ] ; then
local redeploy = 0
msgerr "Download update failed"
if [ $# -eq 1 ] ; then
local instOnlineVer = $( extract_version " $( <" $UPDATES_DIR /install.sh " ) " )
okdlg "Aktualizacja niemożliwa" " 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 "
local depEnvOnlineVer = $( extract_version " $( <" $UPDATES_DIR /deployment.env " ) " )
fi
local nsEnvOnlineVer = $( extract_version " $( <" $UPDATES_DIR /nightscout.env " ) " )
else
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 " ) " )
local msgInst = " $( printf "\U1F7E2" ) $instLocalVer "
local msgDep = " $( printf "\U1F7E2" ) $depEnvLocalVer "
local msgNs = " $( printf "\U1F7E2" ) $nsEnvLocalVer "
local msgComp = " $( printf "\U1F7E2" ) $compLocalVer "
if ! [ " $instOnlineVer " = = " $instLocalVer " ] || ! [ " $lastDownload " = = " $updateInstalled " ] ; then
local changed = 0
changed = $(( changed + 1 ))
local redeploy = 0
msgInst = " $( printf "\U1F534" ) $instLocalVer $( printf "\U27A1" ) $instOnlineVer "
fi
if ! [ " $depEnvLocalVer " = = " $depEnvOnlineVer " ] ; then
local instOnlineVer = $( extract_version " $( <" $UPDATES_DIR /install.sh " ) " )
changed = $(( changed + 1 ))
local depEnvOnlineVer = $( extract_version " $( <" $UPDATES_DIR /deployment.env " ) " )
redeploy = $(( redeploy + 1 ))
local nsEnvOnlineVer = $( extract_version " $( <" $UPDATES_DIR /nightscout.env " ) " )
msgDep = " $( printf "\U1F534" ) $depEnvLocalVer $( printf "\U27A1" ) $depEnvOnlineVer "
local compOnlineVer = $( extract_version " $( <" $UPDATES_DIR /docker-compose.yml " ) " )
fi
if ! [ " $nsEnvLocalVer " = = " $nsEnvOnlineVer " ] ; then
local instLocalVer = $( extract_version " $( <" $TOOL_FILE " ) " )
changed = $(( changed + 1 ))
local depEnvLocalVer = $( extract_version " $( <" $ENV_FILE_DEP " ) " )
redeploy = $(( redeploy + 1 ))
local nsEnvLocalVer = $( extract_version " $( <" $ENV_FILE_NS " ) " )
msgNs = " $( printf "\U1F534" ) $nsEnvLocalVer $( printf "\U27A1" ) $nsEnvOnlineVer "
local compLocalVer = $( extract_version " $( <" $DOCKER_COMPOSE_FILE " ) " )
fi
if ! [ " $compLocalVer " = = " $compOnlineVer " ] ; then
local msgInst = " $( printf "\U1F7E2" ) $instLocalVer "
changed = $(( changed + 1 ))
local msgDep = " $( printf "\U1F7E2" ) $depEnvLocalVer "
redeploy = $(( redeploy + 1 ))
local msgNs = " $( printf "\U1F7E2" ) $nsEnvLocalVer "
msgComp = " $( printf "\U1F534" ) $compLocalVer $( printf "\U27A1" ) $compOnlineVer "
local msgComp = " $( printf "\U1F7E2" ) $compLocalVer "
fi
if [ " $changed " -eq 0 ] ; then
if ! [ " $instOnlineVer " = = " $instLocalVer " ] || ! [ " $lastDownload " = = " $updateInstalled " ] ; then
if [ $# -eq 1 ] ; then
changed = $(( changed + 1 ))
msgok "Scripts and config files are up to date"
msgInst = " $( printf "\U1F534" ) $instLocalVer $( printf "\U27A1" ) $instOnlineVer "
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 } "
fi
fi
local versionMsg = " ${ TL } Build: ${ updateInstalled } "
if ! [ " $depEnvLocalVer " = = " $depEnvOnlineVer " ] ; then
if [ ! " $lastDownload " = = " $updateInstalled " ] ; then
changed = $(( changed + 1 ))
versionMsg = " $( pad_multiline " ${ TL } Masz build: ${ updateInstalled } ${ NL } Dostępny: ${ lastDownload } " ) "
redeploy = $(( redeploy + 1 ))
msgDep = " $( printf "\U1F534" ) $depEnvLocalVer $( printf "\U27A1" ) $depEnvOnlineVer "
fi
fi
yesnodlg "Aktualizacja skryptów" " $uni_confirm_upd " " $uni_resign " \
if ! [ " $nsEnvLocalVer " = = " $nsEnvOnlineVer " ] ; then
" Zalecana jest aktualizacja plików: ${ versionMsg } " \
changed = $(( changed + 1 ))
" $(
redeploy = $(( redeploy + 1 ))
pad_multiline \
msgNs = " $( printf "\U1F534" ) $nsEnvLocalVer $( printf "\U27A1" ) $nsEnvOnlineVer "
" ${ TL } ${ uni_bullet } Skrypt instalacyjny: $msgInst " \
fi
" ${ 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
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
if [ " $redeploy " -gt 0 ] ; then
docker_compose_down
okTxt = " ${ TL } ${ uni_warn } Aktualizacja zrestartuje i zaktualizuje kontenery ${ uni_warn } "
fi
fi
if ! [ " $compOnlineVer " = = " $compLocalVer " ] ; then
local versionMsg = " ${ TL } Build: ${ updateInstalled } "
ohai " Updating $DOCKER_COMPOSE_FILE "
if [ ! " $lastDownload " = = " $updateInstalled " ] ; then
cp -fr " $UPDATES_DIR /docker-compose.yml " " $DOCKER_COMPOSE_FILE "
versionMsg = " $( pad_multiline " ${ TL } Masz build: ${ updateInstalled } ${ NL } Dostępny: ${ lastDownload } " ) "
fi
fi
if ! [ " $depEnvLocalVer " = = " $depEnvOnlineVer " ] ; then
yesnodlg "Aktualizacja skryptów" " $uni_confirm_upd " " $uni_resign " \
ohai " Updating $ENV_FILE_DEP "
" Zalecana jest aktualizacja plików: ${ versionMsg } " \
dotenv-tool -pr -o " $ENV_FILE_DEP " -i " $UPDATES_DIR /deployment.env " " $ENV_FILE_DEP "
" $(
fi
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
if ! [ $? -eq 1 ] ; 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 "
clear_last_time "update_needed"
if ! [ " $instOnlineVer " = = " $instLocalVer " ] || ! [ " $lastDownload " = = " $updateInstalled " ] ; then
if [ " $redeploy " -gt 0 ] ; then
ohai " Updating $TOOL_FILE "
docker_compose_down
cp -fr " $UPDATES_DIR /install.sh " " $TOOL_FILE "
fi
okdlg "Aktualizacja zakończona" "Narzędzie zostanie uruchomione ponownie"
ohai "Restarting tool"
exec " $TOOL_FILE "
fi
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 ! [ " $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
fi
fi
fi
fi