aboutsummaryrefslogtreecommitdiffstats
path: root/prepare-vpn-usb.sh
diff options
context:
space:
mode:
authorJimmy Axenhus <github att axenhus doot com>2021-04-04 16:39:43 +0200
committerJimmy Axenhus <github att axenhus doot com>2021-04-04 16:39:43 +0200
commitcbef9f4253fb0bc2a243571c0adfc3d7d8d66867 (patch)
tree5c8581b43acce269cac38e267386b46720d947fb /prepare-vpn-usb.sh
downloadqubes-vpn-2fa-certificate-cbef9f4253fb0bc2a243571c0adfc3d7d8d66867.tar.bz2
qubes-vpn-2fa-certificate-cbef9f4253fb0bc2a243571c0adfc3d7d8d66867.tar.zst
qubes-vpn-2fa-certificate-cbef9f4253fb0bc2a243571c0adfc3d7d8d66867.zip
Initial commit.
Diffstat (limited to 'prepare-vpn-usb.sh')
-rwxr-xr-xprepare-vpn-usb.sh51
1 files changed, 51 insertions, 0 deletions
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

Code dump for some of my projects as well as a mirror for other random or interesting projects. You can find my site at jimmy.axenhus.com