fix source path and improve systemd directivees
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
Include ${SSH_CFG_PATH}
|
||||
Host default
|
||||
IdentitiesOnly yes
|
||||
StreamLocalBindMask 0111 # TODO: check this
|
||||
StreamLocalBindMask 0117
|
||||
StreamLocalBindUnlink yes
|
||||
DynamicForward ${RUNTIME_DIRECTORY}/sock
|
||||
SessionType none
|
||||
|
||||
16
diyvpn.sh
16
diyvpn.sh
@@ -13,6 +13,7 @@ check_file_exists() {
|
||||
return 1
|
||||
}
|
||||
|
||||
script_path="$0"
|
||||
script_dir=$(dirname "$(realpath "$0")")
|
||||
common_ssh_cfg_path="${DIYVPN_SSH_CFG:-$script_dir/common_sshconfig}"
|
||||
diyvpn_cfg="${DIYVPN_CFG:-$HOME/.config/diyvpn/servers}"
|
||||
@@ -30,31 +31,34 @@ generate() {
|
||||
check_file_exists "$server_ssh_cfg" || return 0
|
||||
check_file_exists "$server_config_rc" || return 0
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
source "server_config_rc"
|
||||
# shellcheck disable=SC1090
|
||||
source "$server_config_rc"
|
||||
|
||||
idle_timeout="${IDLE_TIMEOUT:-10min}"
|
||||
listen_address="${LISTEN_ADDRESS:?LISTEN_ADDRESS should be set}"
|
||||
header="# Automatically generated by $script_path"
|
||||
|
||||
cat >"$opdir/diyvpnssh-$name.service" <<-EOF
|
||||
$header
|
||||
[Unit]
|
||||
Description=ssh to $name
|
||||
SourcePath=$server_config_rc
|
||||
StopWhenUnneeded=yes
|
||||
|
||||
[Service]
|
||||
Type=notify
|
||||
NotifyAccess=all
|
||||
|
||||
# TODO change to yes?
|
||||
Restart=no
|
||||
RuntimeDirectory=diyvpn-$name
|
||||
Environment=SSH_CFG_PATH=$server_ssh_cfg
|
||||
ExecStart=ssh -F "$common_ssh_cfg_path" default
|
||||
EOF
|
||||
|
||||
cat >"$opdir/diyvpnact-$name.service" <<-EOF
|
||||
$header
|
||||
[Unit]
|
||||
Description=Socket activator for diyvpn to server $name
|
||||
SourcePath=$server_config_rc
|
||||
Requires=diyvpnssh-$name.service
|
||||
After=diyvpnssh-$name.service
|
||||
BindsTo=diyvpnssh-$name.service
|
||||
@@ -64,8 +68,10 @@ generate() {
|
||||
EOF
|
||||
|
||||
cat >"$opdir/diyvpnact-$name.socket" <<-EOF
|
||||
$header
|
||||
[Unit]
|
||||
Description=Socket for diyvpn to server $name
|
||||
SourcePath=$server_config_rc
|
||||
|
||||
[Socket]
|
||||
ListenStream=$listen_address
|
||||
@@ -80,7 +86,7 @@ generate() {
|
||||
|
||||
for server in "$diyvpn_cfg"/*; do
|
||||
if [[ -d "$server" ]]; then
|
||||
(generate "$server" "$opdir")
|
||||
(generate "$server")
|
||||
else
|
||||
echo "Ignoring $server. Not a directory."
|
||||
fi
|
||||
|
||||
@@ -7,7 +7,7 @@ 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
|
||||
read -rp "Server name [e.g. vps1] [required] : " name
|
||||
if [[ -d "$diyvpn_cfg/$name" ]]; then
|
||||
echo "Warning: $diyvpn_cfg/$name already exists. Exising files will be overwritten. [Ctrl+C to quit]"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user