Skip to content

Instantly share code, notes, and snippets.

@skleeschulte
Last active December 1, 2021 22:19
Show Gist options
  • Save skleeschulte/2dce21e1ed601f2fd41802964f421397 to your computer and use it in GitHub Desktop.
Save skleeschulte/2dce21e1ed601f2fd41802964f421397 to your computer and use it in GitHub Desktop.
Keep the package luci-app-wireguard installed on OpenWrt. Useful to automatically (re)install the package after a sysupgrade.
#!/bin/sh
[ "${FLOCKER}" != "$0" ] && { exec sh -c "FLOCKER='$0' flock -n '$0' '$0' '$@' || if [ \"\$?\" -eq 1 ]; then echo 'Error: Script is already running.'; fi; exit 1"; } || :
if ! (opkg list-installed | grep -q "^luci-app-wireguard ")
then
echo "luci-app-wireguard is not installed. Installing and rebooting..."
logger "$0: luci-app-wireguard is not installed. Installing and rebooting..."
opkg update && opkg install luci-app-wireguard && echo "Going to reboot in 15 seconds..." && sleep 15 && reboot
else
echo "luci-app-wireguard is already installed. Doing nothing."
logger "$0: luci-app-wireguard is already installed. Doing nothing."
fi
Usage:
1. Save install-luci-app-wireguard.sh in /root folder (e.g. with vi or with WinScp).
2. Make file executable:
chmod +x /root/install-luci-app-wireguard.sh
3. Add file to crontab (execute every 5th minute, but then sleep another two minutes before execution):
echo '*/5 * * * * sleep 120 && /root/install-luci-app-wireguard.sh' >> /etc/crontabs/root
4. Add /root folder to /etc/sysupgrade.conf to keep it when upgrading:
echo '/root' >> /etc/sysupgrade.conf
5. When upgrading, keep "Keep settings and retain the current configuration" selected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment