@@ -1045,11 +1045,18 @@ run_uninstall_scheduler() {
10451045 local service_file=" /etc/systemd/system/restic-backup.service"
10461046 local timer_file=" /etc/systemd/system/restic-backup.timer"
10471047 local cron_file=" /etc/cron.d/restic-backup"
1048+ local was_systemd=false
1049+ local was_cron=false
10481050 local -a files_to_remove=()
1049- [ -f " $timer_file " ] && files_to_remove+=(" $timer_file " )
1050- [ -f " $service_file " ] && files_to_remove+=(" $service_file " )
1051- [ -f " $cron_file " ] && files_to_remove+=(" $cron_file " )
1052-
1051+ if [ -f " $timer_file " ]; then
1052+ was_systemd=true
1053+ files_to_remove+=(" $timer_file " )
1054+ [ -f " $service_file " ] && files_to_remove+=(" $service_file " )
1055+ fi
1056+ if [ -f " $cron_file " ]; then
1057+ was_cron=true
1058+ files_to_remove+=(" $cron_file " )
1059+ fi
10531060 if [ ${# files_to_remove[@]} -eq 0 ]; then
10541061 echo -e " ${C_YELLOW} No scheduled backup tasks found to uninstall.${C_RESET} "
10551062 return 0
@@ -1064,18 +1071,18 @@ run_uninstall_scheduler() {
10641071 echo " Aborted by user."
10651072 return 0
10661073 fi
1067- if [ -f " $timer_file " ]; then
1074+ if [[ " $was_systemd " == " true " ] ]; then
10681075 echo " Stopping and disabling systemd timer..."
10691076 systemctl stop restic-backup.timer > /dev/null 2>&1 || true
10701077 systemctl disable restic-backup.timer > /dev/null 2>&1 || true
10711078 fi
10721079 echo " Removing files..."
10731080 rm -f " ${files_to_remove[@]} "
1074- if [ -f " $timer_file " ]; then
1081+ if [[ " $was_systemd " == " true " ] ]; then
10751082 systemctl daemon-reload
10761083 echo -e " ${C_GREEN} ✅ systemd timer and service files removed.${C_RESET} "
1077- fi
1078- if [ -f " $cron_file " ]; then
1084+ fi
1085+ if [[ " $was_cron " == " true " ] ]; then
10791086 echo -e " ${C_GREEN} ✅ Cron file removed.${C_RESET} "
10801087 fi
10811088}
0 commit comments