1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #! /bin/bash
- usage() {
- printf "Usage: %s [-t <namespace suffix>]\n" "$0"
- }
- namespace=ns-vpn
- while getopts t:h opt; do
- case $opt in
- h) usage
- exit
- ;;
- ?) 2>&1 usage
- exit 1
- ;;
- esac
- done
- netns_list=( $( find /run/netns/ -type f -regex ".*ns-vpn.*" -exec basename -a {} + | sort ) )
- case "${#netns_list[@]}" in
- 0)
- exit 0
- ;;
- 1)
- namespace="${netns_list[0]}"
- ;;
- [1-9]*)
- namespace=$( for ns in "${netns_list[@]}"; do printf '%s\n' "$ns"; done | dmenu -l -8 )
- ;;
- *)
- exit 1
- ;;
- esac
- task=$(dmenu -l 8 << EOF
- browser
- screen
- terminal
- EOF
- )
- cmd=
- case $task in
- browser)
- cmd="firefox"
- ;;
- screen)
- cmd="st -e screen -S $namespace"
- ;;
- terminal)
- cmd="tabbed -cr2 st -w '' -e /bin/bash -l"
- ;;
- *)
- exit 1
- ;;
- esac
- exec sudo /usr/bin/ip netns exec $namespace su -c "DISPLAY=$DISPLAY $cmd" $USER
|