improvements to configure

This commit is contained in:
2026-10-29 06:36:51 -06:00
parent 1bd73df94f
commit 7209f7424c
7 changed files with 348 additions and 22 deletions
+77 -2
View File
@@ -13,11 +13,16 @@ is_installed() {
command -v restic > /dev/null && command -v rclone > /dev/null && command -v secret-tool > /dev/null
}
is_configured() {
backups_on() {
source "$COREDESKTOP/system/backup-env.sh" > /dev/null || return 1
[ -n "$RESTIC_PASSWORD_COMMAND" ] && systemctl --user is-enabled -q coredesktop-backup.timer
}
# Done when backing up to the main Core
is_configured() {
backups_on && [ "$BACKUP_WEBDAV" = "https://nextcloud.$CORE_DOMAIN/remote.php/dav/files/${CORE_EMAIL%@*}" ]
}
save_secret() {
printf '%s' "$3" | secret-tool store --label "CoreDesktop backup $1 ($2)" \
coredesktop backup item "$1" url "$2"
@@ -59,8 +64,78 @@ new_passphrase() {
save_secret passphrase "$WEBDAV/$BACKUP_DIR" "$pass"
}
# Stop the daily backup and any running now, and remove its units
stop_backups() {
systemctl --user disable --now coredesktop-backup.timer 2> /dev/null
systemctl --user stop coredesktop-backup.service 2> /dev/null
rm -f "$UNITS"/coredesktop-backup.{service,timer}
systemctl --user daemon-reload
}
# Delete the backup from Nextcloud, then what's on this computer for it:
# without the backup, the passphrase and app password are no use
delete_backups() {
local app_password
nextcloud_login || { echo "Couldn't sign in to Nextcloud."; return 1; }
echo "Deleting $BACKUP_DIR from your Nextcloud files..."
rclone purge ":webdav:$BACKUP_DIR" \
|| { echo "rclone couldn't delete $BACKUP_DIR."; return 1; }
echo "Deleted. Nextcloud keeps it in its trash bin, where it still uses space, until you empty it."
app_password="$(backup_secret nextcloud "$WEBDAV")"
[ -n "$app_password" ] && nextcloud_revoke_app_password "$app_password"
secret-tool clear coredesktop backup item nextcloud url "$WEBDAV"
secret-tool clear coredesktop backup item passphrase url "$WEBDAV/$BACKUP_DIR"
rm -f "$BACKUP_CONF"
}
turn_off() {
local answer
WEBDAV="$BACKUP_WEBDAV"
CORE_USER="$BACKUP_USER"
NEXTCLOUD="${BACKUP_WEBDAV%%/remote.php/*}"
stop_backups
echo "Backups are off."
echo
echo "The backups made so far are still in $BACKUP_DIR in your Nextcloud files."
if ! confirm "Delete them? They can't be restored from after that."; then
echo "Kept them. To turn backups back on: configure backup"
return 0
fi
read -rp "To delete them, type the folder name ($BACKUP_DIR): " answer
if [ "$answer" != "$BACKUP_DIR" ]; then
echo "That's not the folder name, so the backups were kept."
return 0
fi
delete_backups
}
run_configure() {
local pass
local pass choice
if backups_on &> /dev/null; then
if is_configured &> /dev/null; then
echo "Your home folder is backed up daily to $BACKUP_DIR in your Nextcloud files."
echo
echo " 1) Set it up again"
else
echo "Your home folder is backed up daily to $BACKUP_DIR on ${BACKUP_WEBDAV%%/remote.php/*},"
echo "which isn't your main Core."
echo
echo " 1) Back up to your main Core ($CORE_DOMAIN) instead; the backups so far stay where they are"
fi
echo " 2) Turn backups off"
echo " q) Leave it as it is"
echo
read -rp "Choose: " choice
case "$choice" in
1) ;;
2) turn_off; return ;;
*) return 0 ;;
esac
fi
if [ -z "$CORE_DOMAIN" ] || [ -z "$CORE_EMAIL" ]; then
echo "Backups go to your Nextcloud files, so set up your Core first: configure core"
return 1