aboutsummaryrefslogtreecommitdiff
path: root/zeno-wifi.sh
blob: 36fa3d411e33d79477edb7d2fea64cc8ab017e82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

source ~/zeno-wifi.config

sudo ifconfig wlan0 up
sudo iw dev wlan0 scan | grep -Po "(?<=SSID: ).*" | sort -u >/tmp/visible.networks
sudo ifconfig wlan0 down

KNOWN="$({
  cat /tmp/visible.networks
  netctl list | cut -b3-
} | sort | uniq -d | head -1)"


if [[ -n "$KNOWN" ]]; then
  echo "Connecting to $KNOWN"
  sudo netctl start "$KNOWN"
  netctl wait-online "$KNOWN"

  autossh -M $JUMP_PORT_BASE -f -N -T \
    -R "$((JUMP_PORT_BASE + 22)):localhost:22" \
    -R "$((JUMP_PORT_BASE + 80)):localhost:80" \
    -o "ServerAliveInterval 30" \
    -o "ServerAliveCountMax 2" \
    "$JUMP_HOST"

  ssh "$JUMP_HOST" bash "$JUMP_ONCONNECT"

else
  echo "No known networks available, starting AP"
  sudo create_ap -n --no-virt -d -g 10.0.0.1 wlan0 "$WIFI_SSID" "$WIFI_PASS"
fi