From 579487db912daa17074c85fdad195b4862ff08e0 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Fri, 9 Feb 2024 20:38:42 +0100 Subject: [PATCH] add prompt --- Makefile | 2 ++ scripts/is_root_namespace.py | 11 +++++++++++ scripts/vpn_prompt.sh | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 scripts/is_root_namespace.py create mode 100644 scripts/vpn_prompt.sh diff --git a/Makefile b/Makefile index 1a12481..f118069 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,8 @@ install_basic: systemd scripts bin cp systemd/vpnclient-wg-basic.service /etc/systemd/system/vpnclient-wg-basic.service cp scripts/connect_basic.py /snacks/wireguard/scripts/connect_basic.py cp scripts/inner_basic.sh /snacks/wireguard/scripts/inner_basic.sh + cp scripts/is_root_namespace.py /snacks/wireguard/scripts/is_root_namespace.py + cp scripts/vpn_prompt.sh /etc/profile.d/vpn_prompt.sh cp bin/vpn /usr/local/bin/vpn setcap cap_sys_admin,cap_sys_ptrace=ep /usr/local/bin/vpn chmod -R 755 /snacks/wireguard diff --git a/scripts/is_root_namespace.py b/scripts/is_root_namespace.py new file mode 100644 index 0000000..b65c593 --- /dev/null +++ b/scripts/is_root_namespace.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 +import sys +import re + +with open("/proc/self/net/dev", "r") as f: + data = f.read() + match = re.search("^enp[0-9a-z]+:", data, re.MULTILINE) + if match is None: + sys.exit(1) + else: + sys.exit(0) diff --git a/scripts/vpn_prompt.sh b/scripts/vpn_prompt.sh new file mode 100644 index 0000000..7b8df75 --- /dev/null +++ b/scripts/vpn_prompt.sh @@ -0,0 +1,4 @@ +if ! /snacks/wireguard_scripts/is_root_namespace.py +then + export PS1='%F{red}%f %n@%m % %c %#' +fi