Update mm-scripts.sh

This commit is contained in:
2023-03-25 13:21:11 -05:00
parent f7ad06ab63
commit 10c58f1964

View File

@@ -586,66 +586,71 @@ GETVPNINFO(){
}
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
if [ "${1}" != "" ]; then
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
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
/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
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]}"
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
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
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]}"
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}
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
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
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]}"
echo
echo -e "${idsCL[Green]}${usrvc} Service has been updated${idsCL[Default]}"
else
echo -e "${idsCL[Red]}No service selected for update${idsCL[Default]}"
fi
}
@@ -723,6 +728,10 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
;;
update);;
update-service)
UPDATESERVICE ${2}
;;
clear) echo -e "${idsCL[LightCyan]}Clearing all mm.* files ${idsCL[Default]}"
echo
;;
@@ -733,6 +742,8 @@ if [ ! -f ${MMFOLDER}/mm.update.stop ]; then
echo -e " ${idsCL[Yellow]}start${idsCL[Default]} --> Start services"
echo -e " ${idsCL[Yellow]}stop${idsCL[Default]} --> Stop services"
echo -e " ${idsCL[Yellow]}restart${idsCL[Default]} --> Restart services"
echo -e " ${idsCL[Yellow]}update-service <service>${idsCL[Default]} --> Update services"
echo
echo -e " ${idsCL[Yellow]}status${idsCL[Default]} --> Check Status on VPN and Media Services"
echo -e " ${idsCL[Yellow]}vpninfo${idsCL[Default]} --> Show VPN Info"
echo