From f7ad06ab637cb136d94414175a909865e1a25dd3 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sat, 25 Mar 2023 13:18:37 -0500 Subject: [PATCH] update --- defaults.inc | 6 ++++ mm-scripts.sh | 99 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 82 insertions(+), 23 deletions(-) diff --git a/defaults.inc b/defaults.inc index 03c2655..58439a1 100755 --- a/defaults.inc +++ b/defaults.inc @@ -36,6 +36,12 @@ MM_SERVICE_PORTS['lidarr']='8686' MM_SERVICE_PORTS['jackett']='9117' MM_SERVICE_PORTS['bazarr']='6767' +declare -A MM_UPDATE_URLS +MM_UPDATE_URLS['ombi']='Ombi-app' +MM_UPDATE_URLS['radarr']='radarr' +MM_UPDATE_URLS['lidarr']='lidarr' +MM_UPDATE_URLS['jackett']='jackett' +MM_UPDATE_URLS['bazarr']='morpheus65535' if [ "${VPN_INTERFACE}" = "tun0" ]; then #openvpn VPN_START=(/bin/systemctl start openvpn) diff --git a/mm-scripts.sh b/mm-scripts.sh index 454eb74..a4a6035 100755 --- a/mm-scripts.sh +++ b/mm-scripts.sh @@ -575,31 +575,84 @@ MMSTATUS(){ } GETVPNINFO(){ - # JSON=$(curl https://${VPN_SERVER}:1443/api/v1/setup?public-key=${vpn_publickey} --user "${VPN_USER}:${VPN_PASS}" -sk) - # vpn_server_ipv4=`echo ${JSON} | jq -r '.server_ipv4'` - # vpn_client_ipv4=`echo ${JSON} | jq -r '.client_ipv4'` - # vpn_routes=`echo ${JSON} | jq -r '.routes'` - # vpn_server_address=`echo ${JSON} | jq -r '.vpn_server_address'` - # vpn_server_port=`echo ${JSON} | jq -r '.vpn_server_port'` - # - # echo -e "${idsCL[Green]}VPN Connection Info${idsCL[Default]}" - # echo - # - # msg="Server Network" - # c=0; spc=''; spc1=$((${cw_spc}-${#msg})) - # until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done - # echo -en "${idsCL[LightCyan]}${msg}${spc}${idsCL[White]}: ${idsCL[Default]}" - # - # echo -e "${idsCL[Green]}${VPN_SERVER}${idsCL[Default]}" - # - # - # echo ${JSON} | jq - - # source ${MMFOLDER}/vpninfo - - echo $vpn_publickey + echo -e "${idsCL[Green]}VPN Connection Info${idsCL[Default]}" + echo + + msg="Server Network" + c=0; spc=''; spc1=$((${cw_spc}-${#msg})) + until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done + echo -n "${idsCL[LightCyan]}${msg}${spc}${idsCL[White]}: ${idsCL[Green]}${VPN_SERVER}${idsCL[Default]}" + } +UPDATESERVICE(){ + usrvc=${1} + echo "${usrvc} Update" > ${MMFOLDER}/mm.update.stop + echo "$(date) - Updating Service (${usrvc}) : Starting" >> $logfile + echo + echo -e "${idsCL[Green]}Updating ${usrvc^} Service${idsCL[Default]}" + echo + + rm -f ${MMFOLDER}/logs/${usrvc}.update + touch ${MMFOLDER}/logs/${usrvc}.update + + /bin/systemctl stop ${usrvc} >> ${MMFOLDER}/logs/${usrvc}.update + [ "${usrvc}" == "radarr" ] && /bin/systemctl stop radarr3d >> ${MMFOLDER}/logs/${usrvc}.update + + tmpfile=/tmp/${usrvc}-update.tar.gz + bak=/opt/{usrvc}.bak.tgz + [[ -f ${bak} ]] && rm -f "${bak}" &>/dev/null + [[ -f ${tmpfile} ]] && rm -f "${tmpfile}" &>/dev/null + + msg="Finding latest update url" + c=0; spc=''; spc1=$((${cw_spc}-${#msg})) + until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done + echo -en "${idsCL[White]}${msg}${spc} : ${idsCL[Default]}" + + latest_release_url=`curl -s https://api.github.com/repos/${MM_UPDATE_URLS[${usrvc}]}/${usrvc}/releases/latest | jq -r '.assets[].browser_download_url' | grep "linux-x64" | cut -d '"' -f 4 | grep -i 'https://'` + echo "$(date) - Updating Service (${usrvc}) : UPDATEURL = ${latest_release_url}" >> $logfile + + echo -e "${idsCL[Green]}Done${idsCL[Default]}" + echo -e "${idsCL[LightCyan]}Download URL: ${idsCL[LightGreen]}${latest_release_url}${idsCL[Default]}" + echo + + msg="Downloading and updating" + c=0; spc=''; spc1=$((${cw_spc}-${#msg})) + until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done + echo -en "${idsCL[White]}${msg}${spc} : ${idsCL[Default]}" + + if curl --output /dev/null --silent --head --fail $latest_release_url; then + wget -qO ${tmpfile} $latest_release_url >> ${MMFOLDER}/logs/${usrvc}.update + if [[ ( $? -eq 0 ) && ( -f ${tmpfile} ) ]]; then + rm -Rf /opt/${usrvc} >> ${MMFOLDER}/logs/${usrvc}.update + /bin/tar czpf $bak /opt/${usrvc^} >> ${MMFOLDER}/logs/${usrvc}.update + /bin/tar xf ${tmpfile} -C /opt/${usrvc^} >> ${MMFOLDER}/logs/${usrvc}.update + chown -R user:users /opt/${usrvc} + fi + fi + + echo -e "${idsCL[Green]}Done${idsCL[Default]}" + + rm -f ${tmpfile} &>/dev/null + + OUT=$(ip link | grep "$VPN_INTERFACE") >/dev/null 2>&1 + if [ ${#OUT} -ne 0 ] && [ ! -f ${MMFOLDER}/mm.stop ] && [[ " ${SERVICES_CHECK[*]} " =~ " ${usrvc} " ]]; then + /bin/systemctl start ${usrvc} >> ${MMFOLDER}/logs/${usrvc}.update + [ "${usrvc}" == "radarr" ] && /bin/systemctl start radarr3d >> ${MMFOLDER}/logs/${usrvc}.update + fi + + rm -f ${MMFOLDER}/mm.update.stop + echo "$(date) - Updating Service (${usrvc}) : Completed" >> $logfile + + echo + echo -e "${idsCL[Green]}${usrvc} Service has been updated${idsCL[Default]}" + + +} + + + + if [ ! -f ${MMFOLDER}/mm.update.stop ]; then if [ -f ${MMFOLDER}/mm.stop ]; then stoppedsince=`date +%s`-$(stat -c %Y ${MMFOLDER}/mm.stop)