1
0
mirror of https://github.com/vimagick/dockerfiles.git synced 2024-12-12 11:15:04 +02:00
dockerfiles/openvpn/setup.sh

53 lines
1.6 KiB
Bash
Raw Normal View History

2015-07-06 02:35:53 +02:00
#!/bin/bash
#
2015-09-01 03:53:21 +02:00
# setup script for vimagick/openvpn
2015-07-06 02:35:53 +02:00
#
2015-07-16 11:55:42 +02:00
OVPN_DIR=./ovpn
2015-09-01 03:53:21 +02:00
OVPN_IMG=vimagick/openvpn
2015-07-16 11:55:42 +02:00
OVPN_DATA=openvpn_data_1
2015-09-01 04:38:12 +02:00
OVPN_BACKUP=openvpn.tgz
2016-05-01 03:06:20 +02:00
OVPN_SERVER=tcp://vpn.easypi.info
2015-07-06 02:35:53 +02:00
2015-07-16 11:55:42 +02:00
mkdir -p $OVPN_DIR
2015-09-01 05:00:28 +02:00
select opt in server client revoke backup restore quit
2015-07-06 02:35:53 +02:00
do
if [[ $opt == "server" ]]
then
echo "setup server ..."
2015-09-01 05:00:28 +02:00
docker run --rm --volumes-from $OVPN_DATA $OVPN_IMG ovpn_genconfig -u $OVPN_SERVER
docker run -it --rm --volumes-from $OVPN_DATA $OVPN_IMG ovpn_initpki
2015-07-06 02:35:53 +02:00
elif [[ $opt == "client" ]]
then
echo "setup client ..."
2015-07-16 11:55:42 +02:00
read -p '>>> ' OVPN_CLIENT
2015-09-01 05:00:28 +02:00
docker run -it --rm --volumes-from $OVPN_DATA $OVPN_IMG easyrsa build-client-full ${OVPN_CLIENT:?client is empty} nopass
docker run --rm --volumes-from $OVPN_DATA $OVPN_IMG ovpn_getclient $OVPN_CLIENT > $OVPN_DIR/$OVPN_CLIENT.ovpn
elif [[ $opt == "revoke" ]]
then
read -p '>>> ' OVPN_CLIENT
docker run -it --rm --volumes-from $OVPN_DATA $OVPN_IMG easyrsa revoke ${OVPN_CLIENT:?client is empty}
docker run -it --rm --volumes-from $OVPN_DATA $OVPN_IMG easyrsa gen-crl
2015-07-16 11:55:42 +02:00
elif [[ $opt == "backup" ]]
then
echo "backup volume ..."
2015-09-01 04:38:12 +02:00
docker run --rm --volumes-from $OVPN_DATA alpine tar cvzf - -C /etc openvpn > $OVPN_DIR/$OVPN_BACKUP
elif [[ $opt == "restore" ]]
then
echo "restore volume ..."
if docker inspect $OVPN_DATA >& /dev/null
then
docker run --rm --volumes-from $OVPN_DATA -i alpine tar xvzf - -C /etc < $OVPN_DIR/$OVPN_BACKUP
else
docker run --name $OVPN_DATA -v /etc/openvpn -i alpine tar xvzf - -C /etc < $OVPN_DIR/$OVPN_BACKUP
fi
2015-07-06 02:35:53 +02:00
elif [[ $opt == "quit" ]]
then
echo "bye"
exit
else
echo "invalid"
fi
done