92 lines
3.6 KiB
Bash
92 lines
3.6 KiB
Bash
#!/bin/ash
|
|
|
|
process_template ( ) {
|
|
processed_filename=$(dirname $1)/$(basename $1 .tmpl)
|
|
echo "Processing template $1 -> $processed_filename with args $2"
|
|
sh -c "sigil -f $1 -p $2 > $processed_filename"
|
|
rm $1
|
|
}
|
|
|
|
function join_by { local IFS="$1"; shift; echo "$*"; }
|
|
|
|
process_templates ( ) {
|
|
for template_filename in `find $1 -type f -name '*.tmpl'`
|
|
do
|
|
process_template $template_filename "$2"
|
|
done
|
|
}
|
|
|
|
topdir=`pwd`
|
|
|
|
for dir in `find /etc/lixonet/* -type d -maxdepth 0`
|
|
do
|
|
dir=${dir%*/} # remove the trailing "/"
|
|
netname=${dir##*/} # print everything after the final "/"
|
|
|
|
# Load relevant environment variables from lixonet.conf
|
|
unset git
|
|
source $dir/lixonet.conf
|
|
if [ -z "$git" ]; then echo "Missing 'git' variable in $dir/lixonet.conf"; exit 1; fi
|
|
sigil_vars=$(cat /etc/lixonet/${netname}/lixonet.conf | tr "\\n" " ")
|
|
|
|
# Parse subnets into a collection of IP reverse zones
|
|
root_reverse_zones=$(echo '${network_address}/${global_prefix:-16}' | sigil -p $sigil_vars | xargs -I '{}' netcalc split {} 24 | sed 's/.0\/24$//' | awk 'BEGIN{FS="."}{print $3"."$2"."$1".in-addr.arpa"}' | sed -e ':a;N;$!ba;s/\n/,/g')
|
|
sigil_vars=$(echo "$sigil_vars root_reverse_zones=$root_reverse_zones")
|
|
local_reverse_zones=$(echo "$bgp_routes" | tr "," "\n" | xargs -I '{}' netcalc split {} 24 | sed 's/.0\/24$//' | awk 'BEGIN{FS="."}{print $3"."$2"."$1".in-addr.arpa"}' | sed -e ':a;N;$!ba;s/\n/,/g')
|
|
sigil_vars=$(echo "$sigil_vars local_reverse_zones=$local_reverse_zones")
|
|
|
|
echo "Configuring Lixonet3 network $netname from $git..."
|
|
echo "Variables: $sigil_vars"
|
|
|
|
# Clone and enter the repository
|
|
rm -rf "$(basename "$git" .git)"
|
|
git clone $git || { echo "clone $git failed, quitting" ; exit 1; }
|
|
cd "$(basename "$git" .git)"
|
|
|
|
# Copy default files
|
|
cp -r ../tinc/* tinc/
|
|
cp -r ../bird/* bird/
|
|
cp -r ../bind/* bind/
|
|
|
|
# Tinc
|
|
# Remove existing configuration
|
|
rm -v -rf /etc/tinc/$netname/*
|
|
# Copy all tinc default files to /etc/(tinc)
|
|
find tinc -type d | sed -e "s@tinc@tinc/${netname}@g" | xargs -I '{}' mkdir --verbose -p /etc/{}
|
|
find tinc -type f | sed -e "s@tinc/@@g" | xargs -I '{}' cp --verbose tinc/{} /etc/tinc/$netname/{}
|
|
# Fill out templates and remove them after
|
|
process_templates "/etc/tinc/$netname/" "$sigil_vars"
|
|
# Copy private key
|
|
cp /etc/lixonet/$netname/tinc.key /etc/tinc/$netname/rsa_key.priv
|
|
# Set permissions for tinc scripts
|
|
chmod +x /etc/tinc/$netname/tinc-up
|
|
chmod +x /etc/tinc/$netname/tinc-down
|
|
chmod +x /etc/tinc/$netname/subnet-up
|
|
chmod +x /etc/tinc/$netname/subnet-down
|
|
|
|
# Bird
|
|
# Remove existing configuration
|
|
rm -v -rf /etc/bird/$netname/*
|
|
# Copy all bird default files to /etc/(bird)
|
|
find bird -type d | sed -e "s@bird@bird/${netname}@g" | xargs -I '{}' mkdir --verbose -p /etc/{}
|
|
find bird -type f | sed -e "s@bird/@@g" | xargs -I '{}' cp --verbose bird/{} /etc/bird/$netname/{}
|
|
# Fill out templates and remove them after
|
|
process_templates "/etc/bird/$netname/" "$sigil_vars"
|
|
|
|
# BIND
|
|
# Remove existing configuration
|
|
rm -v -rf /etc/bind/$netname/*
|
|
# Copy all bind default files to /etc/(bind)
|
|
find bind -type d | sed -e "s@bind@bind/${netname}@g" | xargs -I '{}' mkdir --verbose -p /etc/{}
|
|
find bind -type f | sed -e "s@bind/@@g" | xargs -I '{}' cp --verbose bind/{} /etc/bind/$netname/{}
|
|
# Fill out templates and remove them after
|
|
process_templates "/etc/bind/$netname/" "$sigil_vars"
|
|
|
|
echo "COMPOSE_PROJECT_NAME=$netname" > .env
|
|
docker-compose -p $netname up -d --build
|
|
rm .env
|
|
|
|
# Pop directory
|
|
cd $topdir
|
|
done
|