Update build.sh

This commit is contained in:
Manevolent 2023-04-23 17:57:58 -06:00 committed by GitHub
parent 9aa82a8008
commit d6c1c22c65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,7 @@ for dir in `find /etc/lixonet/* -type d -maxdepth 0`
do
dir=${dir%*/} # remove the trailing "/"
netname=${dir##*/} # print everything after the final "/"
config_out="/etc/lixonet/${netname}/.config/"
# Load relevant environment variables from lixonet.conf
unset git
@ -91,47 +92,47 @@ do
# Tinc
# Remove existing configuration
rm -v -rf /etc/tinc/$netname/*
rm -v -rf $config_out/tinc/*
# 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/{}
find tinc -type d | xargs -I '{}' mkdir --verbose -p $config_out/{}
find tinc -type f | sed -e "s@tinc/@@g" | xargs -I '{}' cp --verbose tinc/{} $config_out/tinc{}
# Build list of all peer IP addresses
tinc_peers=$(cat /etc/tinc/$netname/hosts/* | grep 'Subnet' | grep '/32' | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | sed -e ':a;N;$!ba;s/\n/,/g')
tinc_peers=$(cat $config_out/tinc/hosts/* | grep 'Subnet' | grep '/32' | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | sed -e ':a;N;$!ba;s/\n/,/g')
sigil_vars=$(echo "$sigil_vars tinc_peers=$tinc_peers")
# Fill out templates and remove them after
process_templates "/etc/tinc/$netname/" "$sigil_vars"
process_templates "$config_out/tinc/" "$sigil_vars"
# Copy private key
cp -v /etc/lixonet/$netname/tinc.key /etc/tinc/$netname/rsa_key.priv
cp -v /etc/lixonet/$netname/tinc.key $config_out/tinc/rsa_key.priv
# Set permissions for tinc scripts
chmod +x /etc/tinc/$netname/tinc-up /etc/tinc/$netname/tinc-down /etc/tinc/$netname/subnet-up /etc/tinc/$netname/subnet-down /etc/tinc/$netname/host-up /etc/tinc/$netname/host-down /etc/tinc/$netname/check-node
chmod +x $config_out/tinc/tinc-up $config_out/tinc/tinc-down $config_out/tinc/subnet-up $config_out/tinc/subnet-down $config_out/tinc/host-up $config_out/tinc/host-down $config_out/tinc/check-node
# Bird
# Remove existing configuration
rm -v -rf /etc/bird/$netname/*
rm -v -rf $config_out/bird/*
# 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/{}
find bird -type d | xargs -I '{}' mkdir --verbose -p $config_out/{}
find bird -type f | sed -e "s@bird/@@g" | xargs -I '{}' cp --verbose bird/{} $config_out/bird/{}
# Fill out templates and remove them after
process_templates "/etc/bird/$netname/" "$sigil_vars"
process_templates "$config_out/bird/" "$sigil_vars"
# BIND
# Remove existing configuration
rm -v -rf /etc/bind/$netname/*
rm -v -rf $config_out/bind/*
# 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/{}
find bind -type d | xargs -I '{}' mkdir --verbose -p $config_out/bind/{}
find bind -type f | sed -e "s@bind/@@g" | xargs -I '{}' cp --verbose bind/{} $config_out/bind/{}
# Fill out templates and remove them after
process_templates "/etc/bind/$netname/" "$sigil_vars"
process_templates "$config_out/bind/" "$sigil_vars"
# Wireguard
if [ "${wg_enabled:-0}" -eq "1" ]; then
# Remove existing configuration
rm -v -rf /etc/wireguard/$netname/*
rm -v -rf $config_out/wireguard/*
# Copy all wireguard default files to /etc/(wireguard)
find wireguard -type d | sed -e "s@wireguard@wireguard/${netname}@g" | xargs -I '{}' mkdir --verbose -p /etc/{}
find wireguard -type f | sed -e "s@wireguard/@@g" | xargs -I '{}' cp --verbose wireguard/{} /etc/wireguard/$netname/{}
find wireguard -type d | xargs -I '{}' mkdir --verbose -p $config_out/wireguard/{}
find wireguard -type f | sed -e "s@wireguard/@@g" | xargs -I '{}' cp --verbose wireguard/{} $config_out/wireguard/{}
# Fill out templates and remove them after
process_templates "/etc/wireguard/$netname/" "$sigil_vars"
process_templates "$config_out/wireguard/" "$sigil_vars"
fi
# Docker
@ -159,10 +160,10 @@ do
echo $sigil_vars | tr ' ' '\n' > .env
cat docker-compose.yml
set -e
set -e
docker-compose -p $netname down
docker-compose -p $netname up -d --build --remove-orphans
set +e
set +e
rm -v .env