Update mm-scripts.sh

This commit is contained in:
2023-05-18 21:51:01 -05:00
parent dfad92b0be
commit 22f48828a0

View File

@@ -827,144 +827,150 @@ VPNSPEEDTEST(){
}
UPDATESERVICE(){
if [ "${1}" == "all" ]; then
for usrvc in "${UPDATE_SERVICES[@]}"; do
[ "${MM_UPDATE_REPO[${usrvc}]}" != "" ] && UPDATESERVICE ${usrvc} ${2}
done
if [ "${1}" == "service" ]; then
if [ "${2}" == "all" ]; then
for usrvc in "${UPDATE_SERVICES[@]}"; do
[ "${MM_UPDATE_REPO[${usrvc}]}" != "" ] && UPDATESERVICE service ${usrvc} ${3}
done
elif [ "${1}" != "" ]; then
usrvc=${1}
echo "${usrvc} Update" > ${TMPFOLDER}/mm.update.stop
echo "$(date) - Updating Service (${usrvc}) : Starting" >> $logfile
echo
echo -e "${idsCL[Green]}Updating ${usrvc^} Service${idsCL[Default]}"
DIVIDER . lightGreen
if [ "${usrvc}" == "organizr" ]; then
msg="Checking for update"; 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]}"
cd /var/www/media.scity.us/html >/dev/null 2>&1
if [ "`git log --pretty=%H ...refs/heads/v2-master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/v2-master |cut -f1`" ] || [ "${2}" == "-f" ]; then
[ "${2}" == "-f" ] && echo -e "${idsCL[LightCyan]}Update Not Needed, forcing anyway${idsCL[Default]}" || echo -e "${idsCL[Green]}Update Available${idsCL[Default]}"
msg="Updating service"; c=0; spc=''; spc1=$((${cw_spc}-${#msg})); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
elif [ "${2}" != "" ]; then
usrvc=${2}
echo "${usrvc} Update" > ${TMPFOLDER}/mm.update.stop
echo "$(date) - Updating Service (${usrvc}) : Starting" >> $logfile
echo
echo -e "${idsCL[Green]}Updating ${usrvc^} Service${idsCL[Default]}"
DIVIDER . lightGreen
if [ "${usrvc}" == "organizr" ]; then
msg="Checking for update"; 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]}"
/usr/bin/git stash >/dev/null 2>&1
/usr/bin/git pull >/dev/null 2>&1
/bin/chown -Rf www-data:www-data /var/www/media.scity.us/html
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
msg="Restarting NGINX"; 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]}"
/bin/systemctl restart nginx >/dev/null 2>&1
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Completed" >> $logfile
else
echo -e "${idsCL[LightCyan]}Update Not Available${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Update Not Needed" >> $logfile
fi
else
if [[ " ${UPDATE_SERVICES[*]} " =~ " ${usrvc} " ]]; then
if [ "${MM_UPDATE_REPO[${usrvc}]}" != "" ] && [ "${MM_UPDATE_REPO[${usrvc}]}" != "systemd" ]; then
msg="Checking for update"; c=0; spc=''; spc1=$((${cw_spc}-${#msg})); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
cd /var/www/media.scity.us/html >/dev/null 2>&1
if [ "`git log --pretty=%H ...refs/heads/v2-master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/v2-master |cut -f1`" ] || [ "${3}" == "-f" ]; then
[ "${3}" == "-f" ] && echo -e "${idsCL[LightCyan]}Update Not Needed, forcing anyway${idsCL[Default]}" || echo -e "${idsCL[Green]}Update Available${idsCL[Default]}"
msg="Updating service"; 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 [[ $BETA_SERVICES == *${usrvc}* ]]; then
latest_release_url=`curl -s https://api.github.com/repos/${MM_UPDATE_REPO[${usrvc}]}/${usrvc}/releases | jq -r '.[0].assets[].browser_download_url' | grep "${MM_UPDATE_REPO_GREP[${usrvc}]}" | cut -d '"' -f 4 | grep -i 'https://'`
echo "$(date) - Updating Service (${usrvc}) : BETA UPDATEURL = ${latest_release_url}" >> $logfile
beta="BETA "
else
latest_release_url=`curl -s https://api.github.com/repos/${MM_UPDATE_REPO[${usrvc}]}/${usrvc}/releases/latest | jq -r '.assets[].browser_download_url' | grep "${MM_UPDATE_REPO_GREP[${usrvc}]}" | cut -d '"' -f 4 | grep -i 'https://'`
echo "$(date) - Updating Service (${usrvc}) : UPDATEURL = ${latest_release_url}" >> $logfile
beta=""
fi
latest_ver=`echo ${latest_release_url} | cut -d/ -f8`
cver=${usrvc}_VER
if [ "${!cver}" != "${latest_ver}" ] || [ "${2}" == "-f" ]; then
[ "${2}" == "-f" ] && echo -e "${idsCL[LightCyan]}Update Not Needed, forcing anyway${idsCL[Default]}" || echo -e "${idsCL[Green]}Update Available${idsCL[Default]}"
# rm -f ${MMFOLDER}/logs/update.${usrvc}
touch ${MMFOLDER}/logs/update.${usrvc}
SERVICEBACKUP ${usrvc}
msg="Updating Service"
c=0; spc=''; spc1=$((${cw_spc}-${#msg}))
until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
/usr/bin/git stash >/dev/null 2>&1
/usr/bin/git pull >/dev/null 2>&1
/bin/chown -Rf www-data:www-data /var/www/media.scity.us/html
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
msg="Restarting NGINX"; 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]}"
/bin/systemctl restart nginx >/dev/null 2>&1
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Completed" >> $logfile
else
echo -e "${idsCL[LightCyan]}Update Not Available${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Update Not Needed" >> $logfile
fi
else
if [[ " ${UPDATE_SERVICES[*]} " =~ " ${usrvc} " ]]; then
if [ "${MM_UPDATE_REPO[${usrvc}]}" != "" ] && [ "${MM_UPDATE_REPO[${usrvc}]}" != "systemd" ]; then
msg="Checking for update"; 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 [[ $BETA_SERVICES == *${usrvc}* ]]; then
latest_release_url=`curl -s https://api.github.com/repos/${MM_UPDATE_REPO[${usrvc}]}/${usrvc}/releases | jq -r '.[0].assets[].browser_download_url' | grep "${MM_UPDATE_REPO_GREP[${usrvc}]}" | cut -d '"' -f 4 | grep -i 'https://'`
echo "$(date) - Updating Service (${usrvc}) : BETA UPDATEURL = ${latest_release_url}" >> $logfile
beta="BETA "
else
latest_release_url=`curl -s https://api.github.com/repos/${MM_UPDATE_REPO[${usrvc}]}/${usrvc}/releases/latest | jq -r '.assets[].browser_download_url' | grep "${MM_UPDATE_REPO_GREP[${usrvc}]}" | cut -d '"' -f 4 | grep -i 'https://'`
echo "$(date) - Updating Service (${usrvc}) : UPDATEURL = ${latest_release_url}" >> $logfile
beta=""
fi
latest_ver=`echo ${latest_release_url} | cut -d/ -f8`
cver=${usrvc}_VER
if [ "${!cver}" != "${latest_ver}" ] || [ "${3}" == "-f" ]; then
[ "${3}" == "-f" ] && echo -e "${idsCL[LightCyan]}Update Not Needed, forcing anyway${idsCL[Default]}" || echo -e "${idsCL[Green]}Update Available${idsCL[Default]}"
# rm -f ${MMFOLDER}/logs/update.${usrvc}
touch ${MMFOLDER}/logs/update.${usrvc}
SERVICEBACKUP ${usrvc}
msg="Updating Service"
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/update.${usrvc}
if [[ ( $? -eq 0 ) && ( -f ${tmpfile} ) ]]; then
if [ "${usrvc}" != "bazarr" ]; then
rm -Rf /opt/${usrvc^} >> ${MMFOLDER}/logs/update.${usrvc}
mkdir /opt/${usrvc^} >> ${MMFOLDER}/logs/update.${usrvc}
fi
if curl --output /dev/null --silent --head --fail $latest_release_url; then
wget -qO ${tmpfile} $latest_release_url >> ${MMFOLDER}/logs/update.${usrvc}
if [[ ( $? -eq 0 ) && ( -f ${tmpfile} ) ]]; then
if [ "${usrvc}" != "bazarr" ]; then
rm -Rf /opt/${usrvc^} >> ${MMFOLDER}/logs/update.${usrvc}
mkdir /opt/${usrvc^} >> ${MMFOLDER}/logs/update.${usrvc}
fi
if [ "${usrvc}" == "ombi" ]; then
/bin/tar xfP ${tmpfile} -C /opt/${usrvc^} >> ${MMFOLDER}/logs/update.${usrvc}
elif [ "${usrvc}" == "bazarr" ]; then
/usr/bin/unzip -oqq ${tmpfile} -d /opt/${usrvc^}
else
/bin/tar xfP ${tmpfile} -C /opt >> ${MMFOLDER}/logs/update.${usrvc}
if [ "${usrvc}" == "ombi" ]; then
/bin/tar xfP ${tmpfile} -C /opt/${usrvc^} >> ${MMFOLDER}/logs/update.${usrvc}
elif [ "${usrvc}" == "bazarr" ]; then
/usr/bin/unzip -oqq ${tmpfile} -d /opt/${usrvc^}
else
/bin/tar xfP ${tmpfile} -C /opt >> ${MMFOLDER}/logs/update.${usrvc}
fi
chown -R user:users /opt/${usrvc^} >> ${MMFOLDER}/logs/update.${usrvc}
fi
chown -R user:users /opt/${usrvc^} >> ${MMFOLDER}/logs/update.${usrvc}
fi
rm -f ${tmpfile} &>/dev/null
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
[ ! -f ${TMPFOLDER}/vers.info ] && touch ${TMPFOLDER}/vers.info
/bin/sed -i /${usrvc}/d ${TMPFOLDER}/vers.info
echo "${usrvc}_VER=\"${latest_ver}\"" >> ${TMPFOLDER}/vers.info
SERVICEBACKUPSTART ${usrvc}
echo "$(date) - Updating Service (${usrvc}) : Completed" >> $logfile
echo -e "${idsCL[Green]}${usrvc^} Service has been updated${idsCL[Default]}"
else
echo -e "${idsCL[LightCyan]}Update Not Available${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Update Not Needed" >> $logfile
fi
rm -f ${tmpfile} &>/dev/null
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
[ ! -f ${TMPFOLDER}/vers.info ] && touch ${TMPFOLDER}/vers.info
/bin/sed -i /${usrvc}/d ${TMPFOLDER}/vers.info
echo "${usrvc}_VER=\"${latest_ver}\"" >> ${TMPFOLDER}/vers.info
SERVICEBACKUPSTART ${usrvc}
echo "$(date) - Updating Service (${usrvc}) : Completed" >> $logfile
echo -e "${idsCL[Green]}${usrvc^} Service has been updated${idsCL[Default]}"
else
echo -e "${idsCL[LightCyan]}Update Not Available${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Update Not Needed" >> $logfile
fi
elif [ "${MM_UPDATE_REPO[${usrvc}]}" == "systemd" ]; then
msg="Checking for update"; 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]}"
[ "${usrvc}" == "qbittorrent" ] && ausrvc="qbittorrent-nox" || ausrvc=${usrvc}
if [ "$(apt-get -s upgrade | grep ${ausrvc})" != "" ] || [ "${2}" == "-f" ]; then
echo -e "${idsCL[Green]}Update Available${idsCL[Default]}"
SERVICEBACKUP ${usrvc}
msg="Updating service"; c=0; spc=''; spc1=$((${cw_spc}-${#msg})); until [ $c = ${spc1} ]; do spc="${spc} "; c=`expr $c + 1`; done
elif [ "${MM_UPDATE_REPO[${usrvc}]}" == "systemd" ]; then
msg="Checking for update"; 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]}"
/usr/bin/apt install ${ausrvc} -y >/dev/null 2>&1
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Completed" >> $logfile
SERVICEBACKUPSTART ${usrvc}
else
echo -e "${idsCL[LightCyan]}Update Not Available${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Update not needed" >> $logfile
fi
[ "${usrvc}" == "qbittorrent" ] && ausrvc="qbittorrent-nox" || ausrvc=${usrvc}
fi
else
echo -e "${idsCL[Red]}Not currently available to update${idsCL[Default]}"
if [ "$(apt-get -s upgrade | grep ${ausrvc})" != "" ] || [ "${2}" == "-f" ]; then
echo -e "${idsCL[Green]}Update Available${idsCL[Default]}"
SERVICEBACKUP ${usrvc}
msg="Updating service"; 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]}"
/usr/bin/apt install ${ausrvc} -y >/dev/null 2>&1
echo -e "${idsCL[Green]}Done${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Completed" >> $logfile
SERVICEBACKUPSTART ${usrvc}
else
echo -e "${idsCL[LightCyan]}Update Not Available${idsCL[Default]}"
echo "$(date) - Updating Service (${usrvc}) : Update not needed" >> $logfile
fi
fi
else
echo -e "${idsCL[Red]}Not currently available to update${idsCL[Default]}"
fi
fi
else
echo -e "${idsCL[Red]}No service selected for update${idsCL[Default]}"
fi
rm -f ${TMPFOLDER}/mm.update.stop
elif [ "${1}" == "list" ]; then
SHOWSRVCUPDATES
else
echo -e "${idsCL[Red]}No service selected for update${idsCL[Default]}"
fi
rm -f ${TMPFOLDER}/mm.update.stop
}
@@ -1348,7 +1354,7 @@ MMSETUP(){
read -n 1 choice
case "$choice" in
[Yy]) for usrvc in "${UPDATE_SERVICES[@]}"; do
[ "${MM_UPDATE_REPO[${usrvc}]}" != "" ] && UPDATESERVICE ${usrvc}
[ "${MM_UPDATE_REPO[${usrvc}]}" != "" ] && UPDATESERVICE service ${usrvc}
done;;
* ) tmp='';;
esac
@@ -1482,7 +1488,7 @@ if [ ! -f ${TMPFOLDER}/mm.update.stop ]; then
MMSTATUS ${2}
;;
update);;
update) UPDATESERVICE ${2} ${3};;
update-list) SHOWSRVCUPDATES;;
update-service) UPDATESERVICE ${2} ${3};;