Skip to content

Instantly share code, notes, and snippets.

@xenithorb
Last active June 14, 2022 21:25
Show Gist options
  • Save xenithorb/720c85fe1afafb135419 to your computer and use it in GitHub Desktop.
Save xenithorb/720c85fe1afafb135419 to your computer and use it in GitHub Desktop.
OpenWRT rc.local post upgrade for C7 Archer - this belongs as /etc/rc.local
#!/bin/sh
# vim: filetype=sh
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
LUCI_THEME="material"
OPKG_INSTALL="
# kmod-ath10k
# ath10k-firmware-qca988x
luci
luci-theme-material
vim
git
"
OPKG_REMOVE="
mwifiex-sdio-firmware
kmod-mwifiex-sdio
"
SERVICES_DISABLED="
odhcpd
# dnsmasq
"
SERVICES_ENABLED="
uhttpd
"
###########################
isPostUpgrade() {
[ ! -f "/etc/post_upgrade_complete" ]
}
setPostUpgradeComplete() {
date > "/etc/post_upgrade_complete"
}
# First parameter is action enable/disable/etc
handleService() {
action=$1
shift
argProc "${@}"
for i in "${ARGS}"; do
"/etc/init.d/${i}" "$action"
done
}
argProc() {
unset args
for arg in "${@}"; do
if [ "${1}" -eq '#' ]; then
shift; shift
fi
if [ -z $args ]; then
ARGS="$( echo "$1" )"
else
ARGS="$( echo "$args" "$1" )"
fi
done
}
installPackages() {
argProc "${@}"
opkg update || return 1
opkg install "${ARGS}"
}
removePackages() {
argProc "${@}"
opkg remove "${ARGS}"
}
isOnline() {
for i in $(seq 3); do
ping -qc1 8.8.8.8 >/dev/null 2>&1 &&
break
done
}
setLuciTheme() {
installPackages "luci-theme-${1}" || { echo "ERROR: LUCI_THEME opkgs not installed properly"; return 1; }
uci set luci.main.mediaurlbase="/luci-static/${1}" || return 1
uci commit || return 1
# Apparently getting the right luci perms on the build
# server is asking too much, so we set them here anyway
{ chmod -R +rX /www && chmod +x /www/cgi-bin/luci; } || return 1
}
if isPostUpgrade; then
failed=0
if isOnline; then
installPackages ${OPKG_INSTALL} || failed=1
removePackages ${OPKG_REMOVE} || failed=1
handleService disable ${SERVICES_DISABLED} || failed=1
handleService enable ${SERVICES_ENABLED} || failed=1
setLuciTheme "${LUCI_THEME}" || failed=1
setPostUpgradeComplete || failed=1
fi
fi
if [ "$failed" -eq 0 ]; then
reboot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment