#!/bin/bash

# Copyright © 2012-2026 ScriptFanix
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# A copy of the GNU General Public License v3 is includded in the LICENSE file
# at the root of the project.

setupRegen() {
	(( regen )) && return 0
	echo "Parameter $1 for destination $destination changed."
	read -p'Regenerate all files? [y/n] '
	case $REPLY in
		y)
			regen=1
			openDatabase
			if forcedestid=$(Select destinations id <<<"name = $destination")
			then
				echo "Resetting destination files timestamps on"	\
					"$destination ($forcedestid)..."
				Update destination_files last_change 0	\
					<<<"destination_id = $forcedestid"
			else
				echo "Destination $destination does not exist!" >&2
			fi
			closeDatabase
		;;
		n)
		;;
		*)
			setupRegen $1
		;;
	esac
}
