Start the socket file. Add file validation and cleanup
This commit is contained in:
29
diyvpnctl.sh
29
diyvpnctl.sh
@@ -5,6 +5,8 @@ set -euo pipefail
|
||||
diyvpn_cfg="${DIYVPN_CFG:-$HOME/.config/diyvpn/servers}"
|
||||
|
||||
add() {
|
||||
local name listen_address idle_timeout hostname port username identityfile
|
||||
|
||||
read -rp "Server name [e.g. foobar] [required] : " name
|
||||
if [[ -d "$diyvpn_cfg/$name" ]]; then
|
||||
echo "Warning: $diyvpn_cfg/$name already exists. Exising files will be overwritten. [Ctrl+C to quit]"
|
||||
@@ -32,24 +34,19 @@ add() {
|
||||
Port $port
|
||||
User $username
|
||||
IdentityFile $identityfile
|
||||
|
||||
# vim: set filetype=sshconfig:
|
||||
EOF
|
||||
|
||||
echo "Diyvpn config for $name added. Edit below configs for further changes"
|
||||
|
||||
head -100 "$diyvpn_cfg/$name/"*
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user start "diyvpnact-$name.socket"
|
||||
}
|
||||
|
||||
action="${1:-none}"
|
||||
|
||||
case "$action" in
|
||||
|
||||
add)
|
||||
|
||||
add
|
||||
;;
|
||||
|
||||
list)
|
||||
|
||||
list() {
|
||||
echo "config path: $diyvpn_cfg"
|
||||
paste <(
|
||||
echo "servers"
|
||||
@@ -59,10 +56,12 @@ list)
|
||||
echo "ListenAddress"
|
||||
sed -n '/LISTEN/s/.*=\(.*\)/\1/p' "$diyvpn_cfg"/*/config.rc
|
||||
) | column -t
|
||||
;;
|
||||
}
|
||||
|
||||
*)
|
||||
echo "Usage: diyvpnctl.sh [add|list]"
|
||||
;;
|
||||
action="${1:-none}"
|
||||
|
||||
case "$action" in
|
||||
add) add ;;
|
||||
list) list ;;
|
||||
*) echo "Usage: diyvpnctl.sh [add|list]" ;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user