element-web - retain only 10 old backups

element-web - modernize implementation, backup of config.json
This commit is contained in:
2022-12-19 22:26:10 +01:00
parent f6a06a9696
commit 423d95a6b3

View File

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