improvements

This commit is contained in:
2025-12-02 22:20:56 -05:00
parent 23d2a524a2
commit 4c29f51fc0
2 changed files with 15 additions and 10 deletions

25
diyvpn.sh Normal file → Executable file
View File

@@ -1,17 +1,20 @@
#!/bin/bash
set -xeuo pipefail
set -euo pipefail
opdir="$1"
opdir="${1?Output dir missing}"
common_ssh_cfg_path="$HOME/diyvpn_sshconfig"
diyvpn_cfg="$HOME/.config/diyvpn/servers"
: "${HOME?HOME is not set}"
script_dir=$(dirname "$(realpath "$0")")
common_ssh_cfg_path="${DIYVPN_SSH_CFG:-$script_dir/common_sshconfig}"
diyvpn_cfg="${DIYVPN_CFG:-$HOME/.config/diyvpn/servers}"
generate() {
local cfgpath opdir name server_ssh_cfg idle_timeout listen_port
local cfgpath name server_ssh_cfg idle_timeout listen_port
cfgpath="$1"
opdir="$2"
name=$(basename "$cfgpath")
name=$(basename "$cfgpath" | tr -d '[:space:]')
server_ssh_cfg="$cfgpath"/ssh_config # TODO validate
source "$cfgpath/config.rc"
idle_timeout="${IDLE_TIMEOUT:-10min}"
@@ -26,14 +29,16 @@ generate() {
Type=notify
NotifyAccess=all
Restart=no # TODO change to yes
# TODO change to yes?
Restart=no
RuntimeDirectory=diyvpn-$name
Environment=SSH_CFG_PATH=$server_ssh_cfg
ExecStart=ssh -F $common_ssh_cfg_path default
ExecStart=ssh -F "$common_ssh_cfg_path" default
EOF
cat > "$opdir/diyvpnact-$name.service" <<-EOF
[Unit]
Description=Socket activator for diyvpn to server $name
Requires=diyvpnssh-$name.service
After=diyvpnssh-$name.service
BindsTo=diyvpnssh-$name.service
@@ -44,7 +49,7 @@ generate() {
cat > "$opdir/diyvpnact-$name.socket" <<-EOF
[Unit]
Description=Socket activation for diyvpn
Description=Socket for diyvpn to server $name
[Socket]
ListenStream=$listen_port