#!/usr/bin/env bash # PowerWall Management Loader source /opt/idssys/defaults/colors.inc source /opt/idssys/defaults/default.inc source /opt/idssys/powerwall/defaults.inc if [ "${1}" == "update" ]; then if [ "${2}" == "-a" ] || [ "${2}" == "all" ]; then echo -e "${idsCL[White]}Updating the Mainsite Monitor...${idsCL[Default]}" fi if curl -m 5 -s --head --request GET https://git.schroedercity.com | grep "HTTP/2 200" > /dev/null; then if [ "${2}" != "q" ]; then echo -en "${idsCL[LightCyan]}Checking for updates...${idsCL[Default]}" echo "" fi cd /opt/idssys/defaults if [ "`git log --pretty=%H ...refs/heads/master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/master |cut -f1`" ]; then if [ "${2}" != "q" ]; then echo -en "\e[1A"; echo -e "\e[0K\r ${idsCL[LightCyan]}Installing updates...${idsCL[Default]}" fi git fetch origin master >/dev/null 2>&1 git reset --hard origin/master >/dev/null 2>&1 git reflog expire --expire=now --all >/dev/null 2>&1 git repack -ad >/dev/null 2>&1 git prune >/dev/null 2>&1 git pull >/dev/null 2>&1 git submodule update --remote >/dev/null 2>&1 fi cd ${PW_FOLDER} if [ "`git log --pretty=%H ...refs/heads/master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/master |cut -f1`" ]; then if [ "${2}" != "q" ]; then echo -en "\e[1A"; echo -e "\e[0K\r ${idsCL[LightCyan]}Installing updates...${idsCL[Default]}" fi git fetch origin master >/dev/null 2>&1 git reset --hard origin/master >/dev/null 2>&1 git reflog expire --expire=now --all >/dev/null 2>&1 git repack -ad >/dev/null 2>&1 git prune >/dev/null 2>&1 git pull >/dev/null 2>&1 git submodule update --remote >/dev/null 2>&1 /bin/chmod +x /opt/idssys/powerwall/powerwall.sh 2>&1 source /opt/idssys/powerwall/defaults.inc if [ "${2}" != "q" ]; then echo -en "\e[1A"; echo -e "\e[0K\r ${idsCL[Green]}Update to v${PW_VERS} complete${idsCL[Default]}" fi touch ${PW_TMPFOLDER}/.nosend_update if [ "${2}" != "q" ] && [ "${2}" != "y" ] && [ "${2}" != "n" ]; then if [ -f ${NM_TMPFOLDER}/.singleserver.PW.primary ] || [ -f ${NM_TMPFOLDER}/.singleserver.PWO.primary ]; then echo -en "${idsCL[LightCyan]}Do you want to restart PowerWall Services as well? (y/N): " read -n 1 choice case "$choice" in [Yy]) echo -e "\n\n${idsCL[Yellow]}Restarting Powerwall services to apply update ..." ${PW_SCRIPT} service all restart ;; *) echo;; esac fi elif [ "${2}" == "y" ]; then ([ -f ${NM_TMPFOLDER}/.singleserver.PW.primary ] || [ -f ${NM_TMPFOLDER}/.singleserver.PWO.primary ]) && ${PW_SCRIPT} service all restart elif [ "${2}" == "q" ]; then ([ -f ${NM_TMPFOLDER}/.singleserver.PW.primary ] || [ -f ${NM_TMPFOLDER}/.singleserver.PWO.primary ]) && ${PW_SCRIPT} service all restart >/dev/null 2>&1 fi sleep 30s && rm -f ${PW_TMPFOLDER}/.nosend_update & elif [ "${2}" != "q" ]; then echo -en "\e[1A"; echo -e "\e[0K\r ${idsCL[LightCyan]}No Updates Available${idsCL[Default]}\n" fi fi if [ "${2}" == "-a" ] || [ "${2}" == "all" ]; then echo -e "${idsCL[White]}Updating the Offsite Monitor...${idsCL[Default]}" ${SSHCMD} root@${PW_OFFSITE_MONITOR} "pw update" fi else ${PW_SCRIPT} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} fi exit 0