Created
March 1, 2019 11:57
-
-
Save mafredri/d601e5fe26a898fbe6784f48efe4da69 to your computer and use it in GitHub Desktop.
Expect script to automate WireGuard upgrade on UniFi Security Gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env expect -f | |
# Description: Expect script to automate WireGuard upgrade on UniFi Security Gateway | |
# Author: Mathias Fredriksson <[email protected]> | |
# This script assumes non-interactive ssh login. | |
# Usage upgrade.expect <[user@]usg> <https://github.com/Lochnair/vyatta-wireguard/releases/download/${RELEASE}/wireguard-${BOARD}-${RELEASE}.deb> | |
set timeout 60 | |
spawn ssh [lindex $argv 0] | |
expect -exact ":~$ " | |
send -- "sudo su -\r" | |
expect -exact ":~# " | |
send -- "curl -sSL '" | |
send -- [lindex $argv 1] | |
send -- "' -o /tmp/wireguard-latest.deb\r" | |
expect -exact ":~# " | |
send -- "configure\r" | |
expect -exact "\[edit\]" | |
expect -exact "# " | |
send -- "set interfaces wireguard wg0 route-allowed-ips false\r" | |
expect -exact "\[edit\]" | |
expect -exact "# " | |
send -- "commit\r" | |
expect -exact "\[edit\]" | |
expect -exact "# " | |
# Precautionary measure, in case wg0 is missing so that next step can succeed. | |
send -- "ip link add dev wg0 type wireguard\r" | |
expect -exact "\[edit\]" | |
expect -exact "# " | |
send -- "delete interfaces wireguard\r" | |
expect -exact "\[edit\]" | |
expect -exact "# " | |
send -- "commit\r" | |
expect -exact "\[edit\]" | |
expect -exact "# " | |
send -- "dpkg -i /tmp/wireguard-latest.deb\r" | |
expect -exact "# " | |
send -- "rm /tmp/wireguard-latest.deb\r" | |
expect -exact "# " | |
send -- "modprobe -r wireguard\r" | |
expect -exact "# " | |
send -- "modprobe wireguard\r" | |
expect -exact "# " | |
send -- "load\r" | |
expect -exact "# " | |
send -- "commit\r" | |
expect -exact "# " | |
# Exit configure. | |
send -- "exit\r" | |
expect -exact ":~# " | |
# Exit sudo. | |
send -- "exit\r" | |
expect -exact ":~$ " | |
# Exit ssh session. | |
send -- "exit\r" | |
expect -exact ":~$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment