element-web - retain only 10 old backups
element-web - modernize implementation, backup of config.json
This commit is contained in:
@@ -18,23 +18,21 @@ step_1_alias() { echo "updatecheck"; }
|
|||||||
step_1() {
|
step_1() {
|
||||||
shift
|
shift
|
||||||
local latestVersion=
|
local latestVersion=
|
||||||
if [ ! -z "${1:-}" ] ; then
|
if [ -n "${1:-}" ] ; then
|
||||||
latestVersion="$1"
|
latestVersion="$1"
|
||||||
else
|
else
|
||||||
latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
|
latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local isInstalled=$(grep -E "${latestVersion}" "${ELEMENT_WEB_LOC:-}/version" >>/dev/null 2>&1 && echo "1" || echo "0")
|
if grep -E "${latestVersion}" "${ELEMENT_WEB_LOC:-}/version" >>/dev/null 2>&1 ; then
|
||||||
if (( isInstalled )) ; then
|
info "Version $latestVersion is already installed"
|
||||||
echo " [I] Version $latestVersion is already installed"
|
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
echo " [I] Update to $latestVersion available"
|
info "Update to $latestVersion available"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
step_20_info() {
|
step_20_info() {
|
||||||
echo -n "Create a backup"
|
echo -n "Create a backup"
|
||||||
if (( sq_config )) ; then
|
if (( sq_config )) ; then
|
||||||
@@ -52,7 +50,7 @@ step_20() {
|
|||||||
error -e "No configuration file found"
|
error -e "No configuration file found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ ! -z $ELEMENT_WEB_BACKUP ] ; then
|
if [ -n "$ELEMENT_WEB_BACKUP" ] ; then
|
||||||
exe mkdir -p "$ELEMENT_WEB_BACKUP"
|
exe mkdir -p "$ELEMENT_WEB_BACKUP"
|
||||||
fi
|
fi
|
||||||
if [ -n "${1:-}" ] ; then
|
if [ -n "${1:-}" ] ; then
|
||||||
@@ -61,10 +59,14 @@ step_20() {
|
|||||||
tempRoot="$ELEMENT_WEB_LOC"
|
tempRoot="$ELEMENT_WEB_LOC"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local wwwBackup="$ELEMENT_WEB_BACKUP/${toolName}_www_`date +%Y%m%d-%H%M%S`.tar.gz"
|
# Clear old backups
|
||||||
echo " [I] Backing up webserver directory to $wwwBackup"
|
rmold -r 10 "${ELEMENT_WEB_BACKUP}" || true
|
||||||
|
|
||||||
|
local wwwBackup
|
||||||
|
wwwBackup="$ELEMENT_WEB_BACKUP/${toolName}_www_$(date +%Y%m%d-%H%M%S).tar.gz"
|
||||||
|
info "Backing up webserver directory to $wwwBackup"
|
||||||
exe cd "$tempRoot/.."
|
exe cd "$tempRoot/.."
|
||||||
exe tar czf "$wwwBackup" $(basename "$tempRoot")
|
exe tar czf "$wwwBackup" "$(basename -- "$tempRoot")"
|
||||||
}
|
}
|
||||||
|
|
||||||
step_22_info() {
|
step_22_info() {
|
||||||
@@ -72,7 +74,7 @@ step_22_info() {
|
|||||||
if [ -z "${1:-}" ] ; then
|
if [ -z "${1:-}" ] ; then
|
||||||
echo -n "Get latest version from github"
|
echo -n "Get latest version from github"
|
||||||
if ! contextHelp ; then
|
if ! contextHelp ; then
|
||||||
echo ": $(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")')"
|
echo ": $(curl --silent "$latestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')"
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
@@ -85,31 +87,25 @@ step_22_alias() { echo "upgrade"; }
|
|||||||
step_22() {
|
step_22() {
|
||||||
shift # don't need step number
|
shift # don't need step number
|
||||||
local latestVersion=
|
local latestVersion=
|
||||||
if [ ! -z "${1:-}" ] ; then
|
if [ -n "${1:-}" ] ; then
|
||||||
latestVersion="$1"
|
latestVersion="$1"
|
||||||
else
|
else
|
||||||
latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
|
latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z $latestVersion ] ; then
|
if [ -z "$latestVersion" ] ; then
|
||||||
error -e "Cannot determine latest version from github repository"
|
error -e "Cannot determine latest version from github repository"
|
||||||
return 1
|
return 1
|
||||||
elif interactive ; then
|
elif interactive ; then
|
||||||
echo
|
echo
|
||||||
exe read -p "Install $latestVersion to $ELEMENT_WEB_LOC [n]o/(y)es? " answer
|
if ! confirm "Install $latestVersion to $ELEMENT_WEB_LOC" ; then
|
||||||
case $answer in
|
|
||||||
[yY])
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
info -e "Upgrade aborted"
|
info -e "Upgrade aborted"
|
||||||
return 1
|
return 1
|
||||||
;;
|
fi
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local isInstalled=$(grep -E "${latestVersion}" "${ELEMENT_WEB_LOC}/version" >>/dev/null && echo "1" || echo "0")
|
if grep -E "${latestVersion}" "${ELEMENT_WEB_LOC}/version" >>/dev/null 2>&1 ; then
|
||||||
if [ $isInstalled -eq 1 ] ; then
|
info "Version $latestVersion is already installed"
|
||||||
echo " [I] Version $latestVersion is already installed"
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -119,29 +115,30 @@ step_22() {
|
|||||||
|
|
||||||
if [ ! -e "$tempExtract" ] ; then
|
if [ ! -e "$tempExtract" ] ; then
|
||||||
exe mkdir -p "$tempDown"
|
exe mkdir -p "$tempDown"
|
||||||
exe wget -O "$tempLoc" $downUrl
|
exe wget -O "$tempLoc" "$downUrl"
|
||||||
endReturn -o $? "Download failed: $downUrl"
|
endReturn -o $? "Download failed: $downUrl"
|
||||||
exe cd "$tempDown"
|
exe cd "$tempDown"
|
||||||
exe tar -xf "$tempLoc"
|
exe tar -xf "$tempLoc"
|
||||||
endReturn -o $? "Extract failed: $tempLoc"
|
endReturn -o $? "Extract failed: $tempLoc"
|
||||||
else
|
else
|
||||||
echo " [I] Found existing download: $tempExtract"
|
info "Found existing download: $tempExtract"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
local tempBu="${ELEMENT_WEB_LOC}_bu_`date +%Y%m%d-%H%M%S`"
|
local tempBu
|
||||||
|
tempBu="${ELEMENT_WEB_LOC}_bu_$(date +%Y%m%d-%H%M%S)"
|
||||||
|
|
||||||
exe mv "$ELEMENT_WEB_LOC" "$tempBu"
|
exe mv "$ELEMENT_WEB_LOC" "$tempBu"
|
||||||
step backup "$tempBu"
|
step backup "$tempBu"
|
||||||
endReturn -o $? "Backup failed; $ELEMENT_WEB_LOC renamed!"
|
endReturn -o $? "Backup failed; $ELEMENT_WEB_LOC renamed!"
|
||||||
echo " [I] Installing version $latestVersion to $ELEMENT_WEB_LOC"
|
info "Installing version $latestVersion to $ELEMENT_WEB_LOC"
|
||||||
exe mv "$tempExtract" "$ELEMENT_WEB_LOC"
|
exe mv "$tempExtract" "$ELEMENT_WEB_LOC"
|
||||||
exe chown -R www-data: "$ELEMENT_WEB_LOC"
|
exe chown -R www-data: "$ELEMENT_WEB_LOC"
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
echo " [I] Copying configuration"
|
info "Copying configuration"
|
||||||
exe cp -ar "$tempBu/config.json" "$ELEMENT_WEB_LOC/"
|
addConf -c -f "$tempBu/config.json" "$ELEMENT_WEB_LOC/config.json"
|
||||||
echo " [I] Copying login background"
|
info "Copying login background"
|
||||||
exe cp -ar "$tempBu/$tempBackImg/"* "$ELEMENT_WEB_LOC/$tempBackImg/"
|
exe cp -ar "$tempBu/$tempBackImg/"* "$ELEMENT_WEB_LOC/$tempBackImg/"
|
||||||
|
|
||||||
exe rm -rf "$tempBu"
|
exe rm -rf "$tempBu"
|
||||||
|
Reference in New Issue
Block a user