#!/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.

createDestinations() {
	for destination in ${destinations[@]}
	do
		# Create destination directory if it doesn't exist yet
		if ! [ -d "${destinationpath["$destination"]}" ]
		then
			if ! mkdir -p "${destinationpath["$destination"]}"
			then
				echo "$destination: Could not create ${destinationpath["$destination"]}!"
				exit $EINVDEST
			fi
		fi
		# Ensure the destination has a DB record; store its numeric ID
		# for later use
		destinationid["$destination"]=$(
			InsertIfUnset destinations <<<"name $destination ${destinationenabled[\"$destination\"]}"
		)
	done
}
