2024-01-01 11:21:22 +01:00
|
|
|
#!/usr/bin/with-contenv bash
|
|
|
|
# shellcheck shell=bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2024-01-01 17:42:17 +01:00
|
|
|
function with_set_x() {
|
|
|
|
set -x
|
|
|
|
"$@"
|
2024-01-02 05:16:22 +01:00
|
|
|
{
|
|
|
|
ec=$?
|
|
|
|
set +x
|
|
|
|
return $ec
|
|
|
|
} 2>/dev/null
|
2024-01-01 17:42:17 +01:00
|
|
|
}
|
|
|
|
|
2024-01-10 11:54:33 +01:00
|
|
|
|
|
|
|
function log() {
|
|
|
|
echo "$*" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
log ">>> Setting up $(hostname) | id: $(id)\nIP:\n$(ip a)\nRoutes:\n$(ip r)\npyenv:\n$(pyenv versions)"
|
|
|
|
|
|
|
|
echo "
|
|
|
|
AcceptEnv PYENV_VERSION
|
|
|
|
" >> /etc/ssh/sshd_config
|
|
|
|
|
2024-01-01 11:21:22 +01:00
|
|
|
iface="$(ip route | awk '/default/ { print $5 }')"
|
|
|
|
default_gw="$(ip route | awk '/default/ { print $3 }')"
|
2024-01-02 18:43:06 +01:00
|
|
|
for addr in ${ADD_IP_ADDRESSES//,/ }; do
|
2024-01-10 11:54:33 +01:00
|
|
|
log ">>> Adding $addr to interface $iface"
|
2024-01-01 11:21:22 +01:00
|
|
|
net_addr=$(ipcalc -n "$addr" | awk -F= '{print $2}')
|
2024-01-01 17:42:17 +01:00
|
|
|
with_set_x ip addr add "$addr" dev "$iface"
|
|
|
|
with_set_x ip route add "$net_addr" via "$default_gw" dev "$iface" # so that sshuttle -N can discover routes
|
2024-01-01 11:21:22 +01:00
|
|
|
done
|
|
|
|
|
2024-01-10 11:54:33 +01:00
|
|
|
log ">>> Starting iperf3 server"
|
2024-01-01 11:21:22 +01:00
|
|
|
iperf3 --server --port 5001 &
|
|
|
|
|
|
|
|
mkdir -p /www
|
2024-01-10 11:54:33 +01:00
|
|
|
echo "<h5>Hello from $(hostname)</h5>
|
2024-01-01 11:21:22 +01:00
|
|
|
<pre>
|
|
|
|
<u>ip address</u>
|
|
|
|
$(ip address)
|
|
|
|
<u>ip route</u>
|
|
|
|
$(ip route)
|
|
|
|
</pre>" >/www/index.html
|
|
|
|
echo "
|
|
|
|
daemon off;
|
|
|
|
worker_processes 1;
|
|
|
|
error_log /dev/stdout info;
|
|
|
|
events {
|
|
|
|
worker_connections 1024;
|
|
|
|
}
|
|
|
|
http {
|
|
|
|
include /etc/nginx/mime.types;
|
|
|
|
server {
|
|
|
|
access_log /dev/stdout;
|
|
|
|
listen 8080 default_server;
|
|
|
|
listen [::]:8080 default_server;
|
|
|
|
root /www;
|
|
|
|
}
|
|
|
|
}" >/etc/nginx/nginx.conf
|
|
|
|
|
2024-01-10 11:54:33 +01:00
|
|
|
log ">>> Starting nginx"
|
|
|
|
nginx &
|