From cbef9f4253fb0bc2a243571c0adfc3d7d8d66867 Mon Sep 17 00:00:00 2001 From: Jimmy Axenhus Date: Sun, 4 Apr 2021 16:39:43 +0200 Subject: Initial commit. --- prepare-vpn-usb.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 prepare-vpn-usb.sh (limited to 'prepare-vpn-usb.sh') diff --git a/prepare-vpn-usb.sh b/prepare-vpn-usb.sh new file mode 100755 index 0000000..5d8815a --- /dev/null +++ b/prepare-vpn-usb.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -o errexit + +if [ ! -e /tmp/vpn-ramdisk ]; then + mkdir /tmp/vpn-ramdisk + mount -t ramfs -o size=1M ramfs /tmp/vpn-ramdisk + chmod 0700 /tmp/vpn-ramdisk +fi + +if [ ! -e /tmp/vpn-ramdisk/usb-mounted ]; then + read -r -p "Enter path to USB device (empty for /dev/xvdi1 or /dev/xvdi, in that order): " usbdevice + if [ -z "$usbdevice" ]; then + if [ -e /dev/xvdi1 ]; then + usbdevice="/dev/xvdi1" + elif [ -e /dev/xvdi ]; then + usbdevice="/dev/xvdi" + fi + fi + mount "$usbdevice" /rw/config/vpn/ + touch /rw/config/vpn/no-userpassword.txt + if [ -L /rw/config/vpn/vpn-client.conf ]; then + echo "Relinking /rw/config/vpn/vpn-client.conf to" /rw/config/vpn/*.ovpn + rm /rw/config/vpn/vpn-client.conf + ln -s /rw/config/vpn/*.ovpn /rw/config/vpn/vpn-client.conf + elif [ ! -e /rw/config/vpn/vpn-client.conf ]; then + echo "Creating link /rw/config/vpn/vpn-client.conf to" /rw/config/vpn/*.ovpn + ln -s /rw/config/vpn/*.ovpn /rw/config/vpn/vpn-client.conf + else + echo "vpn-client is probably a regular file. Doing nothing." + fi + touch /tmp/vpn-ramdisk/usb-mounted +fi + +if [ ! -e /tmp/vpn-ramdisk/key-pass.txt ]; then + read -s -r -p "Key password: " keypassword + echo + touch /tmp/vpn-ramdisk/key-pass.txt + chmod 0600 /tmp/vpn-ramdisk/key-pass.txt + cat <<< "$keypassword" > /tmp/vpn-ramdisk/key-pass.txt +fi + +if [ ! -e /tmp/vpn-ramdisk/userpassword.txt ]; then + read -p "Username: " username + read -s -r -p "Password: " upassword + echo + touch /tmp/vpn-ramdisk/userpassword.txt + chmod 0600 /tmp/vpn-ramdisk/userpassword.txt + cat <<< "$username" > /tmp/vpn-ramdisk/userpassword.txt + cat <<< "$upassword" >> /tmp/vpn-ramdisk/userpassword.txt +fi -- cgit v1.2.3