Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packaging/scripts/preremove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,22 @@ set -e
if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
deb-systemd-invoke stop evcc.service > /dev/null || true
fi

# If package is upgraded, back up the database
if [ "$1" = "upgrade" ]; then
# Get the currently installed version of evcc package
CURRENT_VERSION=$(dpkg-query -W -f='${Version}' evcc 2> /dev/null)
if [ -z "${CURRENT_VERSION}" ]; then
CURRENT_VERSION="unknown"
fi

# Backup database
EVCC_DB="/var/lib/evcc/evcc.db"
if [ -f "$EVCC_DB" ]; then
BACKUP_DIR="/var/backups/evcc"
mkdir -p "$BACKUP_DIR"
BACKUP_FILE="$BACKUP_DIR/evcc.db.${CURRENT_VERSION}.$(date +%Y%m%d-%H%M%S).bak"
echo "Backing up evcc database to $BACKUP_FILE"
cp -p "$EVCC_DB" "$BACKUP_FILE"
fi
fi
Loading