Files
glorytun/systemd/glorytun-setup
Adrien Gallouët 495138ffe4 Try to guess pref in glorytun-run
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
2017-11-27 11:12:48 +00:00

44 lines
746 B
Bash
Executable File

#!/bin/sh
set -e
_ask() {
printf "%s: " "$1"
read -r "$2"
}
_ask "Config filename (tun0)" NAME
NAME=${NAME:-tun0}
if [ -f /etc/glorytun/"$NAME" ]; then
echo "This config already exit!"
exit 1
fi
_ask "Server ip (enter for server conf)" HOST
_ask "Server key (enter to generate a new one)" KEY
if [ -z "$KEY" ]; then
KEY=$(glorytun keygen)
echo "Your new key: $KEY"
fi
# install files
mkdir -p /etc/glorytun
cat > /etc/glorytun/"$NAME" <<EOF
${HOST:+HOST="$HOST"}
EOF
( umask 077; echo "$KEY" > /etc/glorytun/"$NAME".key )
# always reload
systemctl daemon-reload
# start services
_ask "Start glorytun now ? (enter to skip)" START
case "$START" in y*|Y*)
systemctl start systemd-networkd
systemctl start glorytun@"$NAME" ;;
esac