This commit is contained in:
2025-12-02 23:01:44 -05:00
parent 4c29f51fc0
commit a0b0ccfaa1

View File

@@ -10,17 +10,17 @@ common_ssh_cfg_path="${DIYVPN_SSH_CFG:-$script_dir/common_sshconfig}"
diyvpn_cfg="${DIYVPN_CFG:-$HOME/.config/diyvpn/servers}"
generate() {
local cfgpath name server_ssh_cfg idle_timeout listen_port
cfgpath="$1"
name=$(basename "$cfgpath" | tr -d '[:space:]')
server_ssh_cfg="$cfgpath"/ssh_config # TODO validate
local cfgpath name server_ssh_cfg idle_timeout listen_port
cfgpath="$1"
name=$(basename "$cfgpath" | tr -d '[:space:]')
server_ssh_cfg="$cfgpath"/ssh_config # TODO validate
source "$cfgpath/config.rc"
source "$cfgpath/config.rc"
idle_timeout="${IDLE_TIMEOUT:-10min}"
listen_port="${LISTEN_PORT:?LISTEN_PORT should be set}"
idle_timeout="${IDLE_TIMEOUT:-10min}"
listen_port="${LISTEN_PORT:?LISTEN_PORT should be set}"
cat > "$opdir/diyvpnssh-$name.service" <<-EOF
cat >"$opdir/diyvpnssh-$name.service" <<-EOF
[Unit]
Description=ssh to $name
StopWhenUnneeded=yes
@@ -34,9 +34,9 @@ generate() {
RuntimeDirectory=diyvpn-$name
Environment=SSH_CFG_PATH=$server_ssh_cfg
ExecStart=ssh -F "$common_ssh_cfg_path" default
EOF
EOF
cat > "$opdir/diyvpnact-$name.service" <<-EOF
cat >"$opdir/diyvpnact-$name.service" <<-EOF
[Unit]
Description=Socket activator for diyvpn to server $name
Requires=diyvpnssh-$name.service
@@ -45,9 +45,9 @@ generate() {
[Service]
ExecStart=/usr/lib/systemd/systemd-socket-proxyd --exit-idle-time=$idle_timeout %t/diyvpn-$name/sock
EOF
EOF
cat > "$opdir/diyvpnact-$name.socket" <<-EOF
cat >"$opdir/diyvpnact-$name.socket" <<-EOF
[Unit]
Description=Socket for diyvpn to server $name
@@ -56,10 +56,16 @@ generate() {
[Install]
WantedBy=sockets.target
EOF
EOF
mkdir -p "$opdir/sockets.target.wants"
ln -snf "../diyvpnact-$name.socket" "$opdir/sockets.target.wants"
}
for server in "$diyvpn_cfg"/*
do
for server in "$diyvpn_cfg"/*; do
if [[ -d "$server" ]]; then
(generate "$server" "$opdir")
else
echo "Ignoring $server. Not a directory."
fi
done