qubes-apply

python script to automate qubes saltstack

git clone https://9o.is/git/qubes-apply.git

connect

(981B)


      1 #!/usr/bin/env bash
      2 
      3 if [ "${EUID}" -ne 0 ]; then
      4     echo "Please run as root"
      5     exit 1
      6 fi
      7 
      8 declare -g match=1
      9 declare -g active=$(wg show | awk -F ': ' '/^interface/{ print $2 }')
     10 mapfile -t available < <(find /etc/wireguard/ -type f | \
     11     awk '{ match($0,/.*\/(.*)\.conf$/,a); print a[1] }')
     12 
     13 print_status() {
     14   local cyan='\033[0;36m'
     15   local nocolor='\033[0m'
     16 
     17   for connection in "${available[@]}"; do
     18     if [ "$connection" == "$active" ]; then
     19       echo -e "${cyan}$connection${nocolor}"
     20     else
     21       echo "$connection"
     22     fi
     23   done
     24 
     25   if [ "${#available[@]}" -eq 0 ]; then
     26       echo "No wireguard configurations available"
     27   fi
     28 }
     29 
     30 if [ $# -ne 1 ]; then
     31   print_status
     32   exit 1
     33 fi
     34 
     35 for connection in "${available[@]}"; do
     36   if [ "$connection" == "$1" ]; then
     37     match=0
     38     break
     39   fi
     40 done
     41 
     42 if [ $match -eq 1 ]; then
     43   echo "err: $1 is not an existing connection"
     44   print_status
     45   exit 1
     46 fi
     47 
     48 
     49 if [ "$active" ]; then
     50   wg-quick down "$active"
     51 fi
     52 
     53 wg-quick up "$1"