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