#!/bin/bash # Wireguard configs dir WG_CONF_DIR="$HOME/.wireguard" # Action handler case "$@" in *'Stop wireguard ('*')') iface="${@##*Stop wireguard (}" iface="${iface%')'*}" if [[ "$iface" == "/etc" ]]; then conf="/etc/wireguard/wg0.conf" else conf="$WG_CONF_DIR/$iface.conf" fi coproc (wg-quick down "$conf" >/dev/null 2>&1) & exit 0 ;; *'Start wireguard ('*')') iface="${@##*Start wireguard (}" iface="${iface%')'*}" if [[ "$iface" == "/etc" ]]; then conf="/etc/wireguard/wg0.conf" else conf="$WG_CONF_DIR/$iface.conf" fi coproc (wg-quick up "$conf" >/dev/null 2>&1) & exit 0 ;; *'Stop netbird'*) coproc (netbird down >/dev/null 2>&1) & exit 0 ;; *'Start netbird'*) coproc (netbird up >/dev/null 2>&1) & exit 0 ;; *'Stop sing-box'*) coproc (sudo systemctl stop sing-box >/dev/null 2>&1) & exit 0 ;; *'Start sing-box'*) coproc (sudo systemctl start sing-box >/dev/null 2>&1) & exit 0 ;; esac # Find wireguard configs wg_configs=() if [ -d "$WG_CONF_DIR" ]; then for conf in "$WG_CONF_DIR"/*.conf; do [ -f "$conf" ] && wg_configs+=("$conf") done fi # Build menu index=0 active_indices=() # wireguard if command -v wg-quick >/dev/null 2>&1; then if [ ${#wg_configs[@]} -gt 0 ]; then for conf in "${wg_configs[@]}"; do iface=$(basename "$conf" .conf) if sudo wg show "$iface" &>/dev/null; then echo " Stop wireguard ($iface)" active_indices+=($index) else echo " Start wireguard ($iface)" fi ((index++)) done else # use /etc/wireguard/wg0.conf if no files found if sudo wg show wg0 &>/dev/null; then echo " Stop wireguard (/etc)" active_indices+=($index) else echo " Start wireguard (/etc)" fi ((index++)) fi else echo " Wireguard not installed" ((index++)) fi # netbird if command -v netbird >/dev/null 2>&1; then netbird_status="" if timeout 0.3 netbird status >/dev/null 2>&1; then netbird_status=$(netbird status | grep "Networks" | cut -d: -f2 | sed "s/ -//") fi if [ -z "$netbird_status" ]; then echo " Start netbird" else echo " Stop netbird" active_indices+=($index) fi ((index++)) else echo " Netbird not installed" ((index++)) fi # sing-box if systemctl list-unit-files -q sing-box.service >/dev/null 2>&1; then if systemctl status sing-box >/dev/null 2>&1; then echo " Stop sing-box" active_indices+=($index) else echo " Start sing-box" fi ((index++)) else echo " Sing-box not installed" ((index++)) fi # Tell rofi which lines are active if [ ${#active_indices[@]} -gt 0 ]; then active_str=$(printf "%s" "${active_indices[@]}") echo -en "\0active\x1f$active_str\n" fi