Updated formatting tags to descriptive names

This commit is contained in:
Asif Bacchus 2018-09-30 21:32:26 -06:00
parent 91b53f1c35
commit ec70de618c

View File

@ -5,11 +5,12 @@
normal="\e[0m" normal="\e[0m"
bold="\e[1m" bold="\e[1m"
default="\e[39m" default="\e[39m"
red="\e[31m" err="\e[1;31m"
green="\e[32m" warn="\e[1;93m"
yellow="\e[93m" ok="\e[32m"
magenta="\e[35m" lit="\e[93m"
cyan="\e[96m" op="\e[35m"
info="\e[96m"
stamp="[`date +%Y-%m-%d` `date +%H:%M:%S`]" stamp="[`date +%Y-%m-%d` `date +%H:%M:%S`]"
@ -26,21 +27,21 @@ function scriptHelp {
function quit { function quit {
# list generated warnings, if any # list generated warnings, if any
if [ ${#exitWarn[@]} -gt 0 ]; then if [ ${#exitWarn[@]} -gt 0 ]; then
echo -e "${bold}${yellow}Script generated the following" \ echo -e "${warn}${scriptName} generated the following warnings:" \
"warnings:${normal}" >> "$logFile" "${normal}" >> "$logFile"
for warn in "${exitWarn[@]}"; do for warnCode in "${exitWarn[@]}"; do
echo -e "${yellow}-- [WARNING] ${warningExplain[$warn]}" \ echo -e "${warn}-- [WARNING] ${warningExplain[$warnCode]}" \
"(code: ${warn}) --${normal}" >> "$logFile" "(code: ${warnCode}) --${normal}" >> "$logFile"
done done
fi fi
if [ -z "$1" ]; then if [ -z "$1" ]; then
# exit cleanly # exit cleanly
echo -e "${bold}${magenta}${stamp} -- Script completed" \ echo -e "${bold}${op}${stamp} -- ${scriptName} completed" \
"--$normal" >> "$logFile" "--${normal}" >> "$logFile"
exit 0 exit 0
else else
# log error code and exit with said code # log error code and exit with said code
echo -e "${bold}${red}${stamp} -- [ERROR] ${errorExplain[$1]}" \ echo -e "${err}${stamp} -- [ERROR] ${errorExplain[$1]}" \
"(code: $1) --$normal" >> "$logFile" "(code: $1) --$normal" >> "$logFile"
exit "$1" exit "$1"
fi fi
@ -71,15 +72,15 @@ function checkExist {
### ncMaint - perform NextCloud maintenance mode entry and exit ### ncMaint - perform NextCloud maintenance mode entry and exit
function ncMaint { function ncMaint {
if [ "$1" = "on" ]; then if [ "$1" = "on" ]; then
echo -e "${bold}${cyan}${stamp}Putting NextCloud in maintenance" \ echo -e "${info}${stamp} -- [INFO] Putting NextCloud in maintenance" \
"mode..." >> "$logFile" "mode --${normal}" >> "$logFile"
su -c "php ${ncRoot}/occ maintenance:mode --on" - ${webUser} \ su -c "php ${ncRoot}/occ maintenance:mode --on" - ${webUser} \
>> "$logFile" 2>&1 >> "$logFile" 2>&1
maintResult="$?" maintResult="$?"
return "$maintResult" return "$maintResult"
elif [ "$1" = "off" ]; then elif [ "$1" = "off" ]; then
echo -e "${bold}${cyan}${stamp}Exiting NextCloud maintenance mode..." \ echo -e "${info}${stamp} -- [INFO] Exiting NextCloud maintenance" \
>> "$logFile" "mode --${normal}" >> "$logFile"
su -c "php ${ncRoot}/occ maintenance:mode --off" - ${webUser} \ su -c "php ${ncRoot}/occ maintenance:mode --off" - ${webUser} \
>> "$logFile" 2>&1 >> "$logFile" 2>&1
maintResult="$?" maintResult="$?"
@ -99,7 +100,7 @@ function cleanup {
exitWarn+=('111') exitWarn+=('111')
else else
# directory removed # directory removed
echo -e "${bold}${cyan}${stamp} Removed SQL temp directory${normal}" \ echo -e "${op}${stamp} Removed SQL temp directory${normal}" \
>> "$logFile" >> "$logFile"
fi fi
@ -116,7 +117,7 @@ function cleanup {
exitWarn+=('5030') exitWarn+=('5030')
else else
# file removed # file removed
echo -e "${bold}${cyan}${stamp} Removed 503 error page" \ echo -e "${op}${stamp} Removed 503 error page" \
"from webroot${normal}" >> "$logFile" "from webroot${normal}" >> "$logFile"
fi fi
fi fi
@ -158,7 +159,7 @@ warningExplain[5032]="The specified 503 error page could not be found"
warningExplain[5033]="No webroot path was specified (-r parameter missing)" warningExplain[5033]="No webroot path was specified (-r parameter missing)"
warningExplain[5034]="The specified webroot could not be found" warningExplain[5034]="The specified webroot could not be found"
warningExplain[5035]="Error copying 503 error page to webroot" warningExplain[5035]="Error copying 503 error page to webroot"
warn503="${cyan}${stamp}-- [INFO] Web users will NOT be informed the server is down! --${normal}" warn503="Web users will NOT be informed the server is down!"
### Process script parameters ### Process script parameters
@ -205,17 +206,17 @@ done
### Verify script pre-requisties ### Verify script pre-requisties
# If not running as root, display error on console and exit # If not running as root, display error on console and exit
if [ $(id -u) -ne 0 ]; then if [ $(id -u) -ne 0 ]; then
echo -e "${red}This script MUST be run as ROOT. Exiting.${normal}" echo -e "${err}This script MUST be run as ROOT. Exiting.${normal}"
exit 2 exit 2
elif [ -z "$webroot" ]; then elif [ -z "$webroot" ]; then
echo -e "\n${red}The NextCloud webroot must be specified (-r parameter)" \ echo -e "\n${err}The NextCloud webroot must be specified (-r parameter)" \
"${normal}\n" "${normal}\n"
exit 1 exit 1
fi fi
### Log start of script operations ### Log start of script operations
echo -e "${bold}${magenta}${stamp}-- Start $scriptName execution ---" >> "$logFile" echo -e "${bold}${op}${stamp}-- Start $scriptName execution ---" >> "$logFile"
### Export logFile variable for use by Borg ### Export logFile variable for use by Borg
@ -225,8 +226,8 @@ export logFile="$logFile"
### Create sqlDump temporary directory and sqlDumpFile name ### Create sqlDump temporary directory and sqlDumpFile name
sqlDumpDir=$( mktemp -d ) sqlDumpDir=$( mktemp -d )
sqlDumpFile="backup-`date +%Y%m%d_%H%M%S`.sql" sqlDumpFile="backup-`date +%Y%m%d_%H%M%S`.sql"
echo -e "${normal}${stamp} mySQL dump file will be stored at:" >> "$logFile" echo -e "${info}${stamp} -- [INFO] mySQL dump file will be stored" \
echo -e "${ltYellow}${sqlDumpDir}/${sqlDumpFile}${normal}" >> "$logFile" "at: ${lit}${sqlDumpDir}/${sqlDumpFile}${normal}" >> "$logFile"
### 503 error page ### 503 error page
@ -248,7 +249,8 @@ else
# verify webroot exists # verify webroot exists
if [ -z "$webroot" ]; then if [ -z "$webroot" ]; then
# no webroot path provided # no webroot path provided
echo -e "$warn503" >> "$logFile" echo -e "${warn}${stamp} -- [WARNING] $warn503 --${normal}" \
>> "$logFile"
exitWarn+=('5033') exitWarn+=('5033')
else else
# verify provided webroot path exists # verify provided webroot path exists
@ -256,7 +258,8 @@ else
checkResult="$?" checkResult="$?"
if [ "$checkResult" = "1" ]; then if [ "$checkResult" = "1" ]; then
# webroot directory specified could not be found # webroot directory specified could not be found
echo -e "$warn503" >> "$logFile" echo -e "${warn}${stamp} -- [WARNING] $warn503 --${normal}" \
>> "$logFile"
exitWarn+=('5034') exitWarn+=('5034')
else else
# webroot exists and 503 exists, copy 503 to webroot # webroot exists and 503 exists, copy 503 to webroot
@ -265,11 +268,12 @@ else
# verify copy was successful # verify copy was successful
if [ "$copyResult" = "1" ]; then if [ "$copyResult" = "1" ]; then
# copy was unsuccessful # copy was unsuccessful
echo -e "$warn503" >> "$logFile" echo -e "${warn}${stamp} -- [WARNING] $warn503" \
"--${normal}" >> "$logFile"
exitWarn+=('5035') exitWarn+=('5035')
else else
# copy was successful # copy was successful
echo -e "${bold}${cyan}${stamp} 503 error page" \ echo -e "${op}${stamp} 503 error page" \
"copied to webroot${normal}" >> "$logFile" "copied to webroot${normal}" >> "$logFile"
fi fi
fi fi