#!/bin/bash
# Creates the repo structure defined in config

source "$(dirname "$(readlink -e "$0")")/config"

umask 002

mkdir -pv -- "${FTP_BASE}"/{"${PKGPOOL}","${SRCPOOL}"} "${CLEANUP_DESTDIR}" "${SOURCE_CLEANUP_DESTDIR}"

for repo in "${PKGREPOS[@]}"; do
	for arch in "${ARCHES[@]}"; do
		mkdir -pv -- "${FTP_BASE}/${repo}/os/${arch}"
		if ! [[ -f "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}" ]]; then
			touch -- "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}"
			printf 'created file %q\n' "${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}"
		fi
		if ! [[ -f "${FTP_BASE}/${repo}/os/${arch}/${repo}${FILESEXT}" ]]; then
			touch -- "${FTP_BASE}/${repo}/os/${arch}/${repo}${FILESEXT}"
			printf 'created file %q\n' "${FTP_BASE}/${repo}/os/${arch}/${repo}${FILESEXT}"
		fi
		if ! [[ -L "${FTP_BASE}/${repo}/os/${arch}/${repo}.db" ]]; then
			ln -svT -- "${repo}${DBEXT}" "${FTP_BASE}/${repo}/os/${arch}/${repo}.db"
		fi
		if ! [[ -L "${FTP_BASE}/${repo}/os/${arch}/${repo}.files" ]]; then
			ln -svT -- "${repo}${FILESEXT}" "${FTP_BASE}/${repo}/os/${arch}/${repo}.files"
		fi
	done
done
