improvements
This commit is contained in:
25
diyvpn.sh
Normal file → Executable file
25
diyvpn.sh
Normal file → Executable file
@@ -1,17 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -xeuo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
opdir="$1"
|
opdir="${1?Output dir missing}"
|
||||||
|
|
||||||
common_ssh_cfg_path="$HOME/diyvpn_sshconfig"
|
: "${HOME?HOME is not set}"
|
||||||
diyvpn_cfg="$HOME/.config/diyvpn/servers"
|
|
||||||
|
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() {
|
generate() {
|
||||||
local cfgpath opdir name server_ssh_cfg idle_timeout listen_port
|
local cfgpath name server_ssh_cfg idle_timeout listen_port
|
||||||
cfgpath="$1"
|
cfgpath="$1"
|
||||||
opdir="$2"
|
name=$(basename "$cfgpath" | tr -d '[:space:]')
|
||||||
name=$(basename "$cfgpath")
|
|
||||||
server_ssh_cfg="$cfgpath"/ssh_config # TODO validate
|
server_ssh_cfg="$cfgpath"/ssh_config # TODO validate
|
||||||
|
|
||||||
source "$cfgpath/config.rc"
|
source "$cfgpath/config.rc"
|
||||||
|
|
||||||
idle_timeout="${IDLE_TIMEOUT:-10min}"
|
idle_timeout="${IDLE_TIMEOUT:-10min}"
|
||||||
@@ -26,14 +29,16 @@ generate() {
|
|||||||
Type=notify
|
Type=notify
|
||||||
NotifyAccess=all
|
NotifyAccess=all
|
||||||
|
|
||||||
Restart=no # TODO change to yes
|
# TODO change to yes?
|
||||||
|
Restart=no
|
||||||
RuntimeDirectory=diyvpn-$name
|
RuntimeDirectory=diyvpn-$name
|
||||||
Environment=SSH_CFG_PATH=$server_ssh_cfg
|
Environment=SSH_CFG_PATH=$server_ssh_cfg
|
||||||
ExecStart=ssh -F $common_ssh_cfg_path default
|
ExecStart=ssh -F "$common_ssh_cfg_path" default
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat > "$opdir/diyvpnact-$name.service" <<-EOF
|
cat > "$opdir/diyvpnact-$name.service" <<-EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
|
Description=Socket activator for diyvpn to server $name
|
||||||
Requires=diyvpnssh-$name.service
|
Requires=diyvpnssh-$name.service
|
||||||
After=diyvpnssh-$name.service
|
After=diyvpnssh-$name.service
|
||||||
BindsTo=diyvpnssh-$name.service
|
BindsTo=diyvpnssh-$name.service
|
||||||
@@ -44,7 +49,7 @@ generate() {
|
|||||||
|
|
||||||
cat > "$opdir/diyvpnact-$name.socket" <<-EOF
|
cat > "$opdir/diyvpnact-$name.socket" <<-EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Socket activation for diyvpn
|
Description=Socket for diyvpn to server $name
|
||||||
|
|
||||||
[Socket]
|
[Socket]
|
||||||
ListenStream=$listen_port
|
ListenStream=$listen_port
|
||||||
|
|||||||
Reference in New Issue
Block a user