ninedocker/misc/tools/dicos.sh

42 lines
1.2 KiB
Bash
Raw Normal View History

2024-07-26 22:34:20 +02:00
dir=$1
if [ -f "$dir/dicos/.env.dicos" ]; then
2024-09-21 17:42:47 +02:00
2024-07-26 22:34:20 +02:00
dicos="$dir/dicos/.env.dicos"
# Exporter la variable
2024-09-21 17:42:47 +02:00
set -o allexport; source <(grep -v '^#' $dir/env/.env.merge | sed 's/^/export /'); set +o allexport
2024-07-26 22:34:20 +02:00
# Initialisation des tableaux
templates=()
destinations=()
# Lecture du fichier de configuration
while IFS='=' read -r key value; do
case "$key" in
templates)
IFS=',' read -ra templates <<< "$value"
;;
destinations)
IFS=',' read -ra destinations <<< "$value"
;;
*)
esac
done < "$dicos"
# Boucle sur les templates et leurs destinations
for i in "${!templates[@]}"; do
template="${templates[$i]}"
destination="${destinations[$i]}"
2024-07-27 10:19:39 +02:00
# Extraire le répertoire de destination
folder=$(dirname "$destination")
# Créer le répertoire de destination
mkdir -p "$folder"
2024-07-26 22:34:20 +02:00
# Copier le template vers l'emplacement de destination
cp "$template" "$destination"
envsubst < "$destination" > temp.conf && mv temp.conf "$destination"
done
fi