lixonet-ee/build.sh

56 lines
2.1 KiB
Bash
Raw Normal View History

2020-04-27 21:01:19 +00:00
#!/bin/ash
2020-04-27 20:08:55 +00:00
topdir=`pwd`
2020-05-21 21:27:20 +00:00
for dir in `find /etc/lixonet/* -type d -maxdepth 0`
2020-05-21 21:27:39 +00:00
do
# Pop directory
cd $topdir
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
echo "Configuring Lixonet3 network $netname from $git..."
# Clone and enter the repository
git clone $git
cd "$(basename "$git" .git)"
# Copy default files
cp -r ../tinc/* tinc/
cp -r ../bird/* bird/
# 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@tinc/${netname}@g" | xargs -I '{}' cp --verbose {} /etc/{}
# Fill out templates and remove them after
find /etc/tinc/$netname/ -type f -name '*.tmpl' -exec sh -c 'sigil -f {} -p $(cat /etc/lixonet/$netname/lixonet.conf | tr "\\n" " ") > "$(dirname {})/$(basename {} .tmpl)"' {} \;
find /etc/tinc/$netname/ -type f -name '*.tmpl' | xargs -I '{}' rm -f {}
# 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 tinc 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@bird/${netname}@g" | xargs -I '{}' cp --verbose {} /etc/{}
# Fill out templates and remove them after
find /etc/bird/$netname/ -type f -name '*.tmpl' -exec sh -c 'sigil -f {} -p $(cat /etc/lixonet/$netname/lixonet.conf | tr "\\n" " ") > "$(dirname {})/$(basename {} .tmpl)"' {} \;
find /etc/bird/$netname/ -type f -name '*.tmpl' | xargs -I '{}' rm -f {}
#docker-compose up -d --build
done