summaryrefslogtreecommitdiffstats
path: root/.root/usr
diff options
context:
space:
mode:
Diffstat (limited to '.root/usr')
-rwxr-xr-x.root/usr/local/bin/encrypted54
-rwxr-xr-x.root/usr/local/bin/grub-update15
-rwxr-xr-x.root/usr/local/bin/proxyctl65
3 files changed, 134 insertions, 0 deletions
diff --git a/.root/usr/local/bin/encrypted b/.root/usr/local/bin/encrypted
new file mode 100755
index 0000000..b3132c6
--- /dev/null
+++ b/.root/usr/local/bin/encrypted
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+if [ $UID -ne 0 ]; then
+ echo "This script must be run as root."
+ exit 1
+fi
+
+encrypted_datasets=("zfsroot/encrypted")
+
+function __mount() {
+ for i in "${encrypted_datasets[@]}"; do
+ zfs load-key "$i";
+ if [ $? -ne 0 ]; then
+ echo "Error importing the key! Aborting dataset ${i}"
+ continue
+ fi
+ zfs mount "$i";
+ if [ $? -eq 0 ]; then
+ echo "Successfully mounted dataset ${i}"
+ else
+ echo "Error mounting ${i}."
+ fi
+ done
+}
+function __umount() {
+ for i in "${encrypted_datasets[@]}"; do
+ zfs unmount "$i"
+ if [ $? -ne 0 ]; then
+ echo "Could not unmount partition ${i}"
+ exit 1
+ fi
+ zfs unload-key "$i"
+ done
+
+}
+
+function __help() {
+ echo "Mount and unmount all encrypted zfs partitions"
+ echo "ALL PARTITIONS must be specified in array encrypted_datasets directly in source"
+ echo "Usage: "
+ echo " encrypted [mount|umount]"
+ echo "If volumes are protected with a password, you will be prompted"
+}
+
+if [ $1 = mount ]; then
+ echo "mounting ${encrypted_datasets[@]}"
+ __mount
+elif [ $1 = umount ]; then
+ echo "unmounting ${encrypted_datasets[@]}"
+ __umount
+else
+ echo "Help:"
+ __help
+fi
diff --git a/.root/usr/local/bin/grub-update b/.root/usr/local/bin/grub-update
new file mode 100755
index 0000000..af81a94
--- /dev/null
+++ b/.root/usr/local/bin/grub-update
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+set -e
+
+if [ $UID -ne 0 ]; then
+ echo "Invalid UID! Must be run as root!"
+ exit -1
+fi
+
+mount /dev/nvme0n1p1 /boot/efi
+grub-mkconfig -o /boot/efi/archlinux/x86_64-efi/grub/grub.cfg
+/boot/efi/grub-workaround.sh
+mv -f /boot/efi/grub/grub.cfg /boot/efi/grub/grub.cfg.old
+cp /boot/efi/archlinux/x86_64-efi/grub/grub.cfg /boot/efi/grub/grub.cfg
+umount /boot/efi/
diff --git a/.root/usr/local/bin/proxyctl b/.root/usr/local/bin/proxyctl
new file mode 100755
index 0000000..d46ec4f
--- /dev/null
+++ b/.root/usr/local/bin/proxyctl
@@ -0,0 +1,65 @@
+#!/bin/env /bin/bash
+
+. /etc/profile.d/proxy.sh
+
+function proxy_update_config() {
+ if [ $UID -ne 0 ]; then
+ echo "This command requires root privileges. Aborting..."
+ exit 1
+ fi
+ SRCD=/etc/sing-box
+ ${SRCD}/libconfig_to_json.py ${SRCD}/libconfig ${SRCD}/config.json
+ if [ $? -ne 0 ]; then
+ echo "Failed to write config. Aborting..."
+ exit 1
+ fi
+
+ systemctl restart sing-box
+ status=$(systemctl status sing-box)
+ if [ $? -ne 0 ]; then
+ echo "Failed to start sing-box. Manual intervention needed."
+ exit 1
+ else
+ echo "Success"
+ fi
+}
+
+function __help() {
+ echo "This script controls the sing-box proxy on a system"
+ echo "Usage: "
+ echo " proxyctl [update/reload | on/up | off/down | start | stop | enable | disable]"
+ echo " update or reload: reloads the sing-box configuration (in libconfig)"
+ echo " on or up: sets the environmental variables to tell programs to use proxy on 127.0.0.1:2080"
+ echo " off or down: unsets the proxy-related enviromnental variables"
+ echo " start, stop, enable and disable: corresponding systemctl commands for sing-box service"
+ echo "Return status: "
+ echo " 0: success"
+ echo " any other: something went wrong."
+ echo " [If running systemctl commands]: the return status of 'systemctl status sing-box'"
+}
+
+if [ $# -lt 1 ]; then
+ echo "insufficient arguments. needed: . provided: $#"
+ __help
+ exit 1
+fi
+if [ $1 = update ] || [ $1 = reload ]; then
+ proxy_update_config
+elif [ $1 = on ] || [ $1 = up ]; then
+ proxy-enable
+elif [ $1 = off ] || [ $1 = down ]; then
+ proxy-disable
+elif [ $1 = start ] || [ $1 = stop ] || [ $1 = enable ] || [ $1 = disable ]; then
+ systemctl $1 sing-box
+ STATUS_TEXT=$(systemctl status sing-box)
+ STATUS=$?
+ if [ ${STATUS} -ne 0 ]; then
+ echo "Failed to $1 sing-box"
+ echo "otput of 'systemctl status sing-box':"
+ echo ${STATUS_TEXT}
+ exit ${STATUS}
+ fi
+else
+ echo "Unknown command."
+ exit 1
+fi