64 lines
2.0 KiB
Bash
Executable File
64 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Maintenance operations at once a day.
|
|
# This script called usually by the cron (but indirectly).
|
|
#
|
|
# Uses the rotate_folder utility which must be available on path.
|
|
# Uses the acme wrapper script which have to exist in same folder
|
|
# as this script.
|
|
#
|
|
# Author: Kovács Zoltán <kovacs.zoltan@smartfront.hu>
|
|
# Kovács Zoltán <kovacsz@marcusconsulting.hu>
|
|
# License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html)
|
|
# 2023-06-18 v1.0
|
|
# new: forked from the "Smartfront's DOCKER_skeleton" repository.
|
|
# 2021-09-14 v0.2
|
|
# add: Checks the SSL web certificate (if any), renews it if necessary.
|
|
# 2021-09-01 v0.1 Initial release
|
|
|
|
# Checks the components.
|
|
[[ -z "$(which dirname)" ]] && exit 1
|
|
[[ -z "$(which readlink)" ]] && exit 1
|
|
[[ -z "$(which xargs)" ]] && exit 1
|
|
|
|
# Where I'm?
|
|
SCRPATH="$( cd -P "$( "$(which dirname)" "$0" )" && echo "$PWD" )"
|
|
|
|
# Checks the SSL web certificate, renews it if necessery.
|
|
#
|
|
# Uses the acme wrapper script located in the same directory.
|
|
ACME="$SCRPATH/acme"
|
|
ACMELOG="$($(which dirname) "$SCRPATH")/logs/web/acme.log"
|
|
if [ -n "$ACME" -a -x "$ACME" ]; then
|
|
"$ACME" --cron >> "$ACMELOG" 2>&1
|
|
fi
|
|
# Done with the certificate.
|
|
|
|
# Daily backup operations.
|
|
#
|
|
# Launches the backup script.
|
|
[[ -x "$SCRPATH/backup" ]] && "$SCRPATH/backup"
|
|
# Done with backups.
|
|
|
|
# Rotates the backup folders.
|
|
#
|
|
# Enumerates the folders and tries to rotate they content.
|
|
BACKUPSROOT="$("$(which dirname)" "$SCRPATH")/storage/backups" #"
|
|
for folder in $(ls -1 "$BACKUPSROOT" 2>/dev/null | $(which xargs) -0 ) ""
|
|
do
|
|
if [ -n "$folder" ]; then
|
|
# Dereferenced absolute path.
|
|
folder="$("$(which readlink)" -e "$BACKUPSROOT/$folder")" #"
|
|
# Does it a folder with a prepared configuration?
|
|
if [ -d "$folder" -a -r "$folder/.rotate_folder.conf" ]; then
|
|
# Does the rotate job.
|
|
if [ -x "$SCRPATH/rotate_folder" ]; then
|
|
"$SCRPATH/rotate_folder" -f "$folder" >/dev/null
|
|
elif [ -x "$(which rotate_folder)" ]; then
|
|
"$(which rotate_folder)" -f "$folder" >/dev/null
|
|
fi
|
|
fi
|
|
fi
|
|
done
|
|
# Done with rotating.
|