Start the socket file. Add file validation and cleanup

This commit is contained in:
2025-12-09 12:29:54 -05:00
parent 420798b783
commit 614f694fbd
2 changed files with 32 additions and 17 deletions

View File

@@ -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