-
-
Save damianhodgkiss/a25db0c554ea0af4d3082a3207e2813f to your computer and use it in GitHub Desktop.
#!/bin/sh | |
function install_wireguard () { | |
echo "Downloading Wireguard ($RELEASE)..." | |
FILENAME="wireguard-$BOARD-$RELEASE.deb" | |
DEB_URL="https://github.com/Lochnair/vyatta-wireguard/releases/download/$RELEASE/$FILENAME" | |
if (/usr/bin/curl -s -L -o /tmp/$FILENAME $DEB_URL); then | |
echo "Installing $FILENAME..." | |
dpkg -i /tmp/$FILENAME | |
rm -f /tmp/$FILENAME | |
else | |
echo "Error downloading Wireguard package" | |
exit 1 | |
fi | |
} | |
BOARD=`cat /etc/version | egrep -o '(e100|e1000|e200|e300|e50|ugw3|ugw4|ugwxg)'` | |
if [ "$BOARD" = "" ]; then | |
echo "Unsupported board" | |
exit 1 | |
fi | |
PKG=`dpkg-query --show --showformat='${version},${status}' wireguard` | |
INSTALLED_VERSION=`echo $PKG | cut -d, -f1` | |
INSTALLED_STATUS=`echo $PKG | cut -d, -f2 | egrep -o installed` | |
RELEASE=$(/usr/bin/curl -s https://api.github.com/repos/Lochnair/vyatta-wireguard/releases | /usr/bin/jq -r '.[0].tag_name') | |
if [ "$INSTALLED_STATUS" = "installed" ] && [ "$INSTALLED_VERSION" = "$RELEASE" ]; then | |
echo "Latest Wireguard already installed" | |
exit 0 | |
elif [ "$INSTALLED_STATUS" != "installed" ]; then | |
echo "Wireguard not installed yet" | |
install_wireguard | |
elif [ "$INSTALLED_VERSION" != "$RELEASE" ]; then | |
echo "Wireguard install differs from latest release, upgrading" | |
install_wireguard | |
fi |
thanks mate will take a look.
Hey, this thing is just awesome! We use USG Pro 4s and unfortunately the board name changed:
cat /etc/version
-> UniFiSecurityGateway.ER-e220.v4.4.44.5213871.190726.1717
...the problem with the script currently is, that e220 translates to ugw4 when it comes to the naming of the deb package that needs to be downloaded: wireguard-ugw4-0.0.20190913-1.deb
Do you know why this is the case? How do you suggest solving this issue?
sounds like just a naming thing mate. I guess two possible solutions would be allow you to override the autodetect and pass in the variant in the command line such as ./install... ugw4 .. or improve the autodetect... do you know if there is another command that shows the router model ugw4 in a string?
For choosing v2.0 fw, i modified the script as
#!/bin/sh
function install_wireguard () {
VER=$(cat /opt/vyatta/etc/version | grep Version | grep -q 'v2.0' && echo '-v2.0' || echo '')
echo "Downloading Wireguard$VER ($BOARD-$RELEASE)..."
FILENAME="wireguard$VER-$BOARD-$RELEASE.deb"
DEB_URL="https://github.com/Lochnair/vyatta-wireguard/releases/download/$RELEASE/$FILENAME"
if (/usr/bin/curl -s -L -o /tmp/$FILENAME $DEB_URL); then
echo "Installing $FILENAME..."
dpkg -i /tmp/$FILENAME
rm -f /tmp/$FILENAME
else
echo "Error downloading Wireguard package"
exit 1
fi
}
BOARD=`cat /etc/version | egrep -o '(e100|e1000|e200|e300|e50|ugw3|ugw4|ugwxg)'`
if [ "$BOARD" = "" ]; then
echo "Unsupported board"
exit 1
fi
PKG=`dpkg-query --show --showformat='${version},${status}' wireguard`
INSTALLED_VERSION=`echo $PKG | cut -d, -f1`
INSTALLED_STATUS=`echo $PKG | cut -d, -f2 | egrep -o installed`
RELEASE=$(/usr/bin/curl -sSL https://api.github.com/repos/Lochnair/vyatta-wireguard/releases | /usr/bin/jq -r '.[0].tag_name')
if [ "$INSTALLED_STATUS" = "installed" ] && [ "$INSTALLED_VERSION" = "$RELEASE" ]; then
echo "Latest Wireguard already installed"
exit 0
elif [ "$INSTALLED_STATUS" != "installed" ]; then
echo "Wireguard not installed yet"
install_wireguard
elif [ "$INSTALLED_VERSION" != "$RELEASE" ]; then
echo "Wireguard install differs from latest release, upgrading"
install_wireguard
fi
Thanks for this @damianhodgkiss - one minor note, there are now Wireguard deb packages to support v2 of edgeOS. Took me a few minutes to figure out why I was getting RTNETLINK errors while setting up the interface...
Filenames for v2 are now
wireguard-v2.0-$BOARD-$RELEASE.deb