sle() { # sl emacs
local f=/home/iank/.emacs.d/init.el
- sl --sl-test-cmd ". /etc/os-release ; printf %s \${VERSION//[^a-zA-Z0-9]/}; test -e $f && stat -c%Y $f" --sl-test-hook slemacs "$@"
+ sl --sl-test-cmd "sed -rn '/^VERSION=/{s/^.*=//;s/[^[:alnum:]]//gp}' /etc/os-release; test -e $f && stat -c%Y $f" --sl-test-hook slemacs "$@"
}
ccomp ssh sle
host-info-all() {
host-info-update
bindpushb8
+ ssh iank@li.b8.nz conflink
wrt-setup
}
# hosts is that it is for the User part, the IdentityFile part is
# redundant to *.b8.nz. Also note ${host}i, we only setup those for vpn hosts, but there is no harm in overspecifying here.
root_hosts+=($host ${host}i $host.b8.nz ${host}i.b8.nz)
+ root_hosts_a[$host]=t # a for associative array
else
nonroot_hosts+=($host ${host}i)
fi
-
host_ips[$host]=$ip
- host_macs[$host]=$mac
+ if [[ $mac ]]; then
+ host_macs[$host]=$mac
+ fi
+
done </p/c/host-info
{
} | cedit /p/c/subdir_files/.ssh/config || [[ $? == 1 ]]
{
- echo "cat <<EOF"
+ # hack to please emacs parser
+ here_begin="cat <<EOF"
+ echo "$here_begin"
for host in ${!vpn_ips[@]}; do
ipsuf=${vpn_ips[$host]}
i_port=$(( 2200 + ipsuf ))
cat <<EOF
config redirect
- option name ssh$host
- option src wan
- option src_dport $i_port
- option dest_port 22
- option dest_ip \$l.$ipsuf
- option dest lan
+option name ssh$host
+option src wan
+option src_dport $i_port
+option dest_port 22
+option dest_ip \$l.$ipsuf
+option dest lan
config rule
- option src wan
- option target ACCEPT
- option dest_port $i_port
+option src wan
+option target ACCEPT
+option dest_port $i_port
EOF
done
echo "EOF"
# shellcheck disable=SC2016 # shellcheck doesnt know this is sed
sedi '/edits below here are made automatically/,$d' /p/c/machine_specific/li/filesystem/etc/wireguard/wgmail.conf
for host in ${!vpn_ips[@]}; do
- if [[ ${root_ips[$host]} ]]; then
- # root machines dont run transmission
+ if [[ ${root_hosts_a[$host]} ]]; then
+ # root machines dont actually need vpn, but
+ # the classification still helps with other
+ # configurations.
continue
fi
ipsuf=${vpn_ips[$host]}
wghole $host $ipsuf
+ u /b/ds/machine_specific/li/filesystem/etc/openvpn/client-config-hole/$host <<EOF
+ifconfig-push 10.5.5.${vpn_ips[$host]} 255.255.255.0
+EOF
u /a/bin/ds/machine_specific/$host/filesystem/etc/systemd/system/openvpn-client-tr@.service <<EOF
[Unit]
Description=OpenVPN tunnel for %I
{
echo "cat <<EOF"
- for host in ${!host_ips[@]}; do
+ for host in ${!host_macs[@]}; do
ipsuf=${host_ips[$host]}
echo "dhcp-host=${host_macs[$host]},set:$host,\$l.$ipsuf,$host"
done
echo "EOF"
} | u /p/c/dnsmasq-data
+
b8_ip=$(dig +short b8.nz @iankelling.org | tail -1)
if [[ ! $b8_ip ]]; then
echo "$0: error: got empty b8.nz ip. returning 1"
echo checking for stray files:
initial_dir="$PWD"
- cd /a/bin/ds/machine_specific
- ngset
- files=( */filesystem/etc/systemd/system/openvpn-client-tr@.service )
- ngreset
- cd "$initial_dir"
- for f in "${files[@]}"; do
- host=${f%%/*}
- if [[ ! ${vpn_ips[$host]} ]]; then
- e rm /a/bin/ds/machine_specific/$host/filesystem/etc/systemd/system/openvpn-client-tr@.service
- fi
- done
+ while read -r dir path; do
+ cd $dir
+ ngset
+ files=( */$path )
+ ngreset
+ cd "$initial_dir"
+ for f in "${files[@]}"; do
+ host=${f%%/*}
+ if [[ ! ${vpn_ips[$host]} ]]; then
+ e rm $dir/$f
+ fi
+ done
+ done <<'EOF'
+/a/bin/ds/machine_specific filesystem/etc/systemd/system/openvpn-client-tr@.service
+/p/c/machine_specific filesystem/etc/wireguard/wghole.conf
+EOF
- cd /p/c/machine_specific
- ngset
- files=( */filesystem/etc/wireguard/wghole.conf )
- ngreset
- cd $initial_dir
+ files=( /b/ds/machine_specific/li/filesystem/etc/openvpn/client-config-hole/* )
for f in "${files[@]}"; do
- host=${f%%/*}
+ host=${f##*/}
if [[ ! ${vpn_ips[$host]} ]]; then
- e rm /p/c/machine_specific/$host/filesystem/etc/wireguard/wghole.conf
+ e rm $f
+ e ssh root@li.b8.nz rm -f $f
fi
done
+
+
+ {
+ printf "%s" "Host * "
+ sed -n '/^Host /h;/^IdentityFile .*\/home/{g;s/^Host//;s/ / !/gp}' ~/.ssh/config | tr '\n' ' '
+ echo "IdentityFile ~/.ssh/work"
+ } | cedit work-identity ~/.ssh/config || [[ $? == 1 ]]
+
+
}
# usage host ipsuf [extrahost]