Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask to remove storageDir when removing SD mirroring #1644

Merged
merged 4 commits into from
Jan 12, 2022
Merged
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
14 changes: 14 additions & 0 deletions functions/backup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ setup_mirror_SD() {
local serviceTargetDir="/etc/systemd/system"
local sizeError="your destination SD card device does not have enough space"
local storageDir="${storagedir:-/storage}"
local storageRemovalQuery="Do you also want to remove the storage mount for ${storageDir}?\\nIf you do not but remove the physical device it is located on, you will have trouble every time you restart your system.\\nRemember though it might also contain data you might want to keep such as your Amanda backup data. If ${storageDir} is not where your mount is, stop now and enter your mountpoint in /etc/openhabian.conf as the storagedir= parameter."
local svcname

if ! cond_redirect install -m 755 "${sdIncludesDir}/set-partuuid" /usr/local/sbin; then echo "FAILED (install set-partuuid)"; return 1; fi
echo -n "$(timestamp) [openHABian] Setting up automated SD mirroring and backup... "
Expand All @@ -486,6 +488,18 @@ setup_mirror_SD() {
if [[ $1 == "remove" ]]; then
cond_redirect systemctl disable sdrsync.service sdrawcopy.service sdrsync.timer sdrawcopy.timer
rm -f "$serviceTargetDir"/sdr*.{service,timer}

# ATTENTION: the mountpoint may also have a different name than the default "/storage"
svcname="${${storageDir:1}//[\/]/\\x2d}.mount" # remove leading '/' and replace all '/' by \\x2d as required by systemd for full pathnames
if [[ -f "$serviceTargetDir"/"$svcname" ]]; then
# ATTENTION: may not be desired to remove on SD mirror disabling because it may still be in use for Amanda storage => ask for confirmation
# [is there a possibility that this routine might be run non-interactively ?]
if (whiptail --title "Remove $storageDir" --yes-button "Remove" --no-button "Keep" --yesno "$storageRemovalQuery" 12 116); then
cond_redirect systemctl disable --now "${svcname}"
rm -f "$serviceTargetDir"/"$svcname"
fi
ecdye marked this conversation as resolved.
Show resolved Hide resolved
fi

cond_redirect systemctl -q daemon-reload
return 0
fi
Expand Down