summaryrefslogtreecommitdiffstats
path: root/.root
diff options
context:
space:
mode:
Diffstat (limited to '.root')
-rw-r--r--.root/README.md9
-rwxr-xr-x.root/boot/efi/grub-workaround.sh25
-rw-r--r--.root/etc/default/grub73
-rw-r--r--.root/etc/mkinitcpio.conf26
-rw-r--r--.root/etc/pacman.conf73
-rw-r--r--.root/etc/pacman.d/mirrorlist-archzfs13
-rw-r--r--.root/etc/profile48
-rwxr-xr-x.root/etc/profile.d/aliases.sh12
-rwxr-xr-x.root/etc/profile.d/proxy.sh42
-rwxr-xr-x.root/etc/profile.d/var.sh11
-rwxr-xr-x.root/etc/sing-box/json_to_libconfig.py62
-rwxr-xr-x.root/etc/sing-box/libconfig_to_json.py63
-rw-r--r--.root/tracked17
-rwxr-xr-x.root/update.sh11
-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
17 files changed, 619 insertions, 0 deletions
diff --git a/.root/README.md b/.root/README.md
new file mode 100644
index 0000000..a9e8cd4
--- /dev/null
+++ b/.root/README.md
@@ -0,0 +1,9 @@
+# /
+This is a directory relative to which I will be storing system-wide configuration, scripts e.t.c.
+# update.sh
+This script will be used to copy all of the tracked files from system to this folder
+# tracked
+a file which contains list of tracked files
+# Why?
+I don't want to add separate repo for my scripts. also, this way i will not forget what I wrote and where I placed my scripts
+
diff --git a/.root/boot/efi/grub-workaround.sh b/.root/boot/efi/grub-workaround.sh
new file mode 100755
index 0000000..97ded5b
--- /dev/null
+++ b/.root/boot/efi/grub-workaround.sh
@@ -0,0 +1,25 @@
+#/bin/sh
+
+set -e
+
+if [ $UID -ne 0 ]; then
+ echo script must be run as root
+ exit 1
+fi
+
+if [ $# -lt 2 ]; then
+ CFG_PATH=/boot/efi/archlinux/x86_64-efi/grub/grub.cfg
+else
+ CFG_PATH="$1"
+fi
+
+echo -e '\x1b[91;1m WRITING CONFIG TO \x1b[96m'${CFG_PATH}'\x1b[91m!\x1b[0m'
+
+if ! [ -f "${CFG_PATH}" ]; then
+ echo "invalid path"
+ exit 1
+fi
+
+echo substituting
+sed -i 's/root=ZFS=/zfs=zfsroot/g' "${CFG_PATH}"
+echo done
diff --git a/.root/etc/default/grub b/.root/etc/default/grub
new file mode 100644
index 0000000..9afe514
--- /dev/null
+++ b/.root/etc/default/grub
@@ -0,0 +1,73 @@
+# GRUB boot loader configuration
+
+GRUB_DEFAULT="Arch Linux, with Linux linux-custom"
+GRUB_TIMEOUT="5"
+GRUB_DISTRIBUTOR="Arch"
+# GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 video=DP-3:2560x1440 video=HDMI-5:1920x1080"
+GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 nvidia_drm.modeset=1"
+GRUB_CMDLINE_LINUX="zfs_import_dir=/dev/"
+
+# Preload both GPT and MBR modules so that they are not missed
+GRUB_PRELOAD_MODULES="part_gpt part_msdos"
+
+GRUB_CONFIG="/boot/efi/archlinux/x68_64-efi/grub/grub.cfg"
+
+# Uncomment to enable booting from LUKS encrypted devices
+#GRUB_ENABLE_CRYPTODISK="y"
+
+GRUB_SAVEDEFAULT="false"
+GRUB_DEFAULT="default"
+
+# Set to 'countdown' or 'hidden' to change timeout behavior,
+# press ESC key to display menu.
+GRUB_TIMEOUT_STYLE="menu"
+
+# Uncomment to use basic console
+# GRUB_TERMINAL_INPUT="gfxterm"
+
+# Uncomment to disable graphical terminal
+# GRUB_TERMINAL_OUTPUT="gfxterm"
+
+GRUB_TERMINAL="gfxterm"
+
+# The resolution used on graphical terminal
+# note that you can use only modes which your graphic card supports via VBE
+# you can see them in real GRUB with the command `videoinfo'
+# GRUB_GFXMODE="saved"
+# GRUB_GFXMODE="auto"
+GRUB_GFXMODE="1920x1080"
+
+# Uncomment to allow the kernel use the same resolution used by grub
+# GRUB_GFXPAYLOAD_LINUX=keep
+
+# Uncomment if you want GRUB to pass to the Linux kernel the old parameter
+# format "root=/dev/xxx" instead of "root=/dev/disk/by-uuid/xxx"
+#GRUB_DISABLE_LINUX_UUID="true"
+
+# Uncomment to disable generation of recovery mode menu entries
+GRUB_DISABLE_RECOVERY="true"
+
+# Uncomment and set to the desired menu colors. Used by normal and wallpaper
+# modes only. Entries specified as foreground/background.
+# export GRUB_COLOR_NORMAL="light-blue/black"
+# export GRUB_COLOR_HIGHLIGHT="light-cyan/green"
+
+# Uncomment one of them for the gfx desired, a image background or a gfxtheme
+#GRUB_BACKGROUND="/path/to/wallpaper"
+GRUB_THEME="/boot/efi/archlinux/x86_64-efi/grub/themes/SilverWolf/theme.txt"
+
+# Uncomment to get a beep at GRUB start
+#GRUB_INIT_TUNE="480 440 1"
+
+# Uncomment to make GRUB remember the last selection. This requires
+# setting 'GRUB_DEFAULT=saved' above.
+#GRUB_SAVEDEFAULT="true"
+
+# Uncomment to disable submenus in boot menu
+#GRUB_DISABLE_SUBMENU="y"
+
+# Probing for other operating systems is disabled for security reasons. Read
+# documentation on GRUB_DISABLE_OS_PROBER, if still want to enable this
+# functionality install os-prober and uncomment to detect and include other
+# operating systems.
+GRUB_DISABLE_OS_PROBER="false"
diff --git a/.root/etc/mkinitcpio.conf b/.root/etc/mkinitcpio.conf
new file mode 100644
index 0000000..7aa184a
--- /dev/null
+++ b/.root/etc/mkinitcpio.conf
@@ -0,0 +1,26 @@
+# vim:set ft=sh
+
+# MODULES=(zfs nvidia nvidia_modeset nvidia_uvm nvidia_drm)
+MODULES=(zfs nvidia nvidia_modeset nvidia_uvm nvidia_drm)
+
+BINARIES=()
+
+FILES=()
+
+# see wiki.archlinux.org
+HOOKS=(base udev autodetect modconf keyboard keymap kms consolefont block zfs filesystems usr fsck)
+
+# COMPRESSION
+COMPRESSION="zstd"
+#COMPRESSION="gzip"
+#COMPRESSION="bzip2"
+#COMPRESSION="lzma"
+#COMPRESSION="xz"
+#COMPRESSION="lzop"
+#COMPRESSION="lz4"
+
+# COMPRESSION_OPTIONS
+#COMPRESSION_OPTIONS=()
+
+# Decompress kernel modules during initramfs creation.
+MODULES_DECOMPRESS="yes"
diff --git a/.root/etc/pacman.conf b/.root/etc/pacman.conf
new file mode 100644
index 0000000..45ad4ea
--- /dev/null
+++ b/.root/etc/pacman.conf
@@ -0,0 +1,73 @@
+# /etc/pacman.conf
+# See the pacman.conf(5) manpage for option and repository directives
+
+[options]
+#RootDir = /
+#DBPath = /var/lib/pacman/
+#CacheDir = /var/cache/pacman/pkg/
+#LogFile = /var/log/pacman.log
+#GPGDir = /etc/pacman.d/gnupg/
+#HookDir = /etc/pacman.d/hooks/
+HoldPkg = pacman glibc
+#XferCommand = /usr/bin/curl -L -C - -f -o %o %u
+#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
+#CleanMethod = KeepInstalled
+Architecture = auto
+
+IgnorePkg = linux linux-headers grub
+#IgnoreGroup =
+
+#NoUpgrade =
+#NoExtract =
+
+# Misc options
+#UseSyslog
+Color
+#NoProgressBar
+CheckSpace
+#VerbosePkgLists
+ParallelDownloads = 7
+
+# By default, pacman accepts packages signed by keys that its local keyring
+# trusts (see pacman-key and its man page), as well as unsigned packages.
+SigLevel = Required DatabaseOptional
+LocalFileSigLevel = Optional
+#RemoteFileSigLevel = Required
+
+# REPOSITORIES
+# - can be defined here or included from another file
+# - pacman will search repositories in the order defined here
+# - local/custom mirrors can be added here or in separate files
+# - repositories listed first will take precedence when packages
+# have identical names, regardless of version number
+# - URLs will have $repo replaced by the name of the current repo
+# - URLs will have $arch replaced by the name of the architecture
+#
+# Repository entries are of the format:
+# [repo-name]
+# Server = ServerName
+# Include = IncludePath
+#
+# The header [repo-name] is crucial - it must be present and
+# uncommented to enable the repo.
+
+[core]
+Include = /etc/pacman.d/mirrorlist
+
+[extra]
+Include = /etc/pacman.d/mirrorlist
+
+[multilib]
+Include = /etc/pacman.d/mirrorlist
+
+# An example of a custom package repository. See the pacman manpage for
+# tips on creating your own repositories.
+#[custom]
+#SigLevel = Optional TrustAll
+#Server = file:///home/custompkgs
+
+#[archzfs-testing]
+#Include = /etc/pacman.d/mirrorlist-archzfs
+
+[archzfs]
+Include = /etc/pacman.d/mirrorlist-archzfs
diff --git a/.root/etc/pacman.d/mirrorlist-archzfs b/.root/etc/pacman.d/mirrorlist-archzfs
new file mode 100644
index 0000000..dff4ce6
--- /dev/null
+++ b/.root/etc/pacman.d/mirrorlist-archzfs
@@ -0,0 +1,13 @@
+## See https://github.com/archzfs/archzfs/wiki
+## France
+Server = https://archzfs.com/$repo/$arch
+
+## Germany
+Server = https://mirror.sum7.eu/archlinux/archzfs/$repo/$arch
+Server = https://mirror.biocrafting.net/archlinux/archzfs/$repo/$arch
+
+## India
+Server = https://mirror.in.themindsmaze.com/archzfs/$repo/$arch
+
+## United States
+Server = https://zxcvfdsa.com/archzfs/$repo/$arch
diff --git a/.root/etc/profile b/.root/etc/profile
new file mode 100644
index 0000000..21d183c
--- /dev/null
+++ b/.root/etc/profile
@@ -0,0 +1,48 @@
+# /etc/profile
+
+# Append "$1" to $PATH when not already in.
+# This function API is accessible to scripts in /etc/profile.d
+append_path () {
+ case ":$PATH:" in
+ *:"$1":*)
+ ;;
+ *)
+ PATH="${PATH:+$PATH:}$1"
+ esac
+}
+
+# Append default paths
+append_path '/usr/local/sbin'
+append_path '/usr/local/bin'
+append_path '/usr/bin'
+
+export PATH
+
+# Load profiles from /etc/profile.d
+if test -d /etc/profile.d/; then
+ for profile in /etc/profile.d/*.sh; do
+ test -r "$profile" && . "$profile"
+ done
+ unset profile
+fi
+
+# bash completion test
+if test -f /etc/bash_completion; then
+ . /etc/bash_completion
+fi
+
+# Source global bash config, when interactive but not posix or sh mode
+if test "$BASH" &&\
+ test "$PS1" &&\
+ test -z "$POSIXLY_CORRECT" &&\
+ test "${0#-}" != sh &&\
+ test -r /etc/bash.bashrc
+then
+ . /etc/bash.bashrc
+fi
+
+# Termcap is outdated, old, and crusty, kill it.
+unset TERMCAP
+
+# Man is much better than us at figuring this out
+unset MANPATH
diff --git a/.root/etc/profile.d/aliases.sh b/.root/etc/profile.d/aliases.sh
new file mode 100755
index 0000000..6b87e3f
--- /dev/null
+++ b/.root/etc/profile.d/aliases.sh
@@ -0,0 +1,12 @@
+
+alias ls="ls --color"
+alias fucking=sudo
+alias nv=nvim
+alias copy="xclip -selection clipboard"
+alias md=mkdir
+alias ""="g++"
+alias cargo-test="cargo test -- --nocapture"
+# dotfiles
+alias config='/usr/bin/git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
+# proxy control to set env variables
+alias proxyctl=". /usr/local/bin/proxyctl"
diff --git a/.root/etc/profile.d/proxy.sh b/.root/etc/profile.d/proxy.sh
new file mode 100755
index 0000000..b6bbc45
--- /dev/null
+++ b/.root/etc/profile.d/proxy.sh
@@ -0,0 +1,42 @@
+# set environmental variables
+
+function proxy-enable() {
+ R_="http://127.0.0.1:2080"
+ S_="https://127.0.0.1:2080"
+ export HTTP_PROXY="${R_}"
+ export FTP_PROXY="${R_}"
+ export HTTPS_PROXY="${S_}"
+ export http_proxy="${R_}"
+ export ftp_proxy="${R_}"
+ export https_proxy="${S_}"
+
+ # set gsettings
+ gsettings set org.gnome.system.proxy mode manual
+ for i in http https ftp; do
+ gsettings set org.gnome.system.proxy.$i host 127.0.0.1
+ gsettings set org.gnome.system.proxy.$i port 2080
+ done
+
+ export PROXY_ON_JCG=true
+ echo "proxy enabled"
+}
+alias proxy-on=proxy-enable
+
+function proxy-disable() {
+ unset HTTP_PROXY FTP_PROXY HTTPS_PROXY http_proxy ftp_proxy https_proxy
+ export -n HTTP_PROXY FTP_PROXY HTTPS_PROXY http_proxy ftp_proxy https_proxy
+ gsettings reset org.gnome.system.proxy mode
+
+ unset PROXY_ON_JCG
+ echo "proxy disabled"
+}
+alias proxy-off=proxy-disable
+
+function proxy-toggle() {
+ if [ -z $PROXY_ON_JCG ]; then
+ proxy-enable
+ else
+ proxy-disable
+ fi
+}
+
diff --git a/.root/etc/profile.d/var.sh b/.root/etc/profile.d/var.sh
new file mode 100755
index 0000000..95ad714
--- /dev/null
+++ b/.root/etc/profile.d/var.sh
@@ -0,0 +1,11 @@
+
+# editor
+export SUDO_EDITOR=/usr/bin/nvim
+export EDITOR=/usr/bin/nvim
+export VISUAL=/usr/bin/nvim
+
+# miscellaneous
+RUST_BACKTRACE=full
+CXX=/usr/bin/clang++
+
+
diff --git a/.root/etc/sing-box/json_to_libconfig.py b/.root/etc/sing-box/json_to_libconfig.py
new file mode 100755
index 0000000..da56415
--- /dev/null
+++ b/.root/etc/sing-box/json_to_libconfig.py
@@ -0,0 +1,62 @@
+#!/bin/env /pyenv/bin/python3
+
+import argparse
+import json
+import libconf
+
+ENDC = "\033[0m"
+BOLD = "\033[1m"
+UNDERLINE = "\033[4m"
+BLACK = "\033[30m"
+RED = "\033[31m"
+GREEN = "\033[32m"
+YELLOW = "\033[33m"
+BLUE = "\033[34m"
+MAGENTA = "\033[35m"
+CYAN = "\033[36m"
+WHITE = "\033[37m"
+BG_BLACK = "\033[40m"
+BG_RED = "\033[41m"
+BG_GREEN = "\033[42m"
+BG_YELLOW = "\033[43m"
+BG_BLUE = "\033[44m"
+BG_MAGENTA = "\033[45m"
+BG_CYAN = "\033[46m"
+BG_WHITE = "\033[47m"
+
+def json_to_libconfig(json_file, libconfig_file):
+ try:
+ with open(json_file, 'r') as f:
+ data = json.load(f)
+ converted_data = convert_data(data)
+ except Exception as e:
+ print(e)
+ print(f"{RED}Error: Could not read input file '{json_file}'.{ENDC}")
+ exit(1)
+
+ try:
+ with open(libconfig_file, 'w') as f:
+ f.write(libconf.dumps(converted_data))
+ except Exception as e:
+ print(converted_data)
+ print(e)
+ print(f"{RED}Error: Could not write to output file '{libconfig_file}'.{ENDC}")
+ exit(1)
+
+def convert_data(data):
+ if isinstance(data, dict):
+ return {key: convert_data(value) for key, value in data.items()}
+ elif isinstance(data, list):
+ return tuple([convert_data(item) for item in data])
+ else:
+ return data
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="Convert json to libconfig")
+ parser.add_argument("i", help="JSON file to be converted")
+ parser.add_argument("o", help="output file location")
+ args = parser.parse_args()
+ json_file = args.i
+ libconfig_file = args.o
+ json_to_libconfig(json_file, libconfig_file)
+ print(f"{GREEN}Converted JSON to libconfig: {libconfig_file}{ENDC}")
diff --git a/.root/etc/sing-box/libconfig_to_json.py b/.root/etc/sing-box/libconfig_to_json.py
new file mode 100755
index 0000000..7300a7e
--- /dev/null
+++ b/.root/etc/sing-box/libconfig_to_json.py
@@ -0,0 +1,63 @@
+#!/bin/env /pyenv/bin/python3
+
+import argparse
+import json
+from libconf import load
+
+ENDC = "\033[0m"
+BOLD = "\033[1m"
+UNDERLINE = "\033[4m"
+BLACK = "\033[30m"
+RED = "\033[31m"
+GREEN = "\033[32m"
+YELLOW = "\033[33m"
+BLUE = "\033[34m"
+MAGENTA = "\033[35m"
+CYAN = "\033[36m"
+WHITE = "\033[37m"
+BG_BLACK = "\033[40m"
+BG_RED = "\033[41m"
+BG_GREEN = "\033[42m"
+BG_YELLOW = "\033[43m"
+BG_BLUE = "\033[44m"
+BG_MAGENTA = "\033[45m"
+BG_CYAN = "\033[46m"
+BG_WHITE = "\033[47m"
+
+def convert_libconf_to_json(input_file, output_file):
+ try:
+ with open(input_file, 'r') as f:
+ config = load(f)
+ except Exception as e:
+ print(e)
+ print(f"{RED}Error: Could not read input file '{input_file}'.{ENDC}")
+ exit(1)
+
+ json_data = _convert_data(config)
+
+ try:
+ with open(output_file, 'w') as f:
+ json.dump(json_data, f, indent=4)
+ except Exception as e:
+ print(e)
+ print(f"{RED}Error: Could not write to output file '{output_file}'.{ENDC}")
+ exit(1)
+
+ print(f"{GREEN}Successfully converted '{input_file}' to '{output_file}'.{ENDC}")
+
+
+def _convert_data(data):
+ if isinstance(data, dict):
+ return {key: _convert_data(value) for key, value in data.items()}
+ elif isinstance(data, list):
+ return [_convert_data(item) for item in data]
+ else:
+ return data
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="Convert libconfig file to JSON")
+ parser.add_argument("i", help="Path to the libconfig file")
+ parser.add_argument("o", help="Path to the output JSON file")
+ args = parser.parse_args()
+ convert_libconf_to_json(args.i, args.o)
diff --git a/.root/tracked b/.root/tracked
new file mode 100644
index 0000000..e89a45f
--- /dev/null
+++ b/.root/tracked
@@ -0,0 +1,17 @@
+/etc/sing-box/json_to_libconfig.py
+/etc/sing-box/libconfig_to_json.py
+/etc/profile
+/etc/profile.d/aliases.sh
+/etc/profile.d/var.sh
+/etc/profile.d/proxy.sh
+/usr/local/bin/grub-update
+/usr/local/bin/encrypted
+/usr/local/bin/proxyctl
+/boot/efi/grub-workaround.sh
+
+
+/etc/default/grub
+/etc/mkinitcpio.conf
+/etc/pacman.conf
+/etc/pacman.d/mirrorlist-archzfs
+
diff --git a/.root/update.sh b/.root/update.sh
new file mode 100755
index 0000000..4acca3f
--- /dev/null
+++ b/.root/update.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+function cp_into() {
+ for i in $(cat ${0%/*}/tracked); do
+ mkdir -p .root/${i%/*}
+ echo copying $i to .root/$i
+ cp $i .root/${i};
+ done
+}
+
+cp_into
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