[Feature Request] Restore opkg packages

I'd like to suggest that OpenWrt restores previously installed opkg packages when possible. This should be true for both manual restoration using a backup archive and when flashing a new firmware image while preserving configs.

I know that this has been suggested a few times before and was rejected due to technical limitations. However, in my opinion there are rather easy solutions to circumvent the technical limitations I am aware of, so I'd like to suggest this again.

  1. The backup shouldn't include the opkg packages itself, but a list of installed packages. When restoring a backup, opkg should try to re-install all previously installed packages from the package repository. This avoids incompatibilities between OpenWrt versions.

  2. The backup shouldn't include a full list of opkg packages installed, but a list of manually installed packages. Dependency trees change from time to time, and not every package that was required before might still be required or even exist in a later version of OpenWrt. Thus opkg should start to distinguish between a automatically and manually installed package.

    This doesn't have to be bulletproof: opkg install should write the package names it received to a file, and opkg remove should remove matching entries from this file. This should be limited to packages from a package repository, not for packages fetched using a FQDN, because we can't guarantee that they match. I don't think that this limitation is a real problem: Restoring backups was considered a convenience feature from the beginning, possibly requiring manual interference, not as a bulletproof solution to restore exact copies of the saved system. Thus I'd consider this a valid design decision.

  3. If opkg fails to restore previously installed packages (e.g. due to a missing internet connection, because the package doesn't exist anymore, or the user previously installed a opkg package using a FQDN) OpenWrt should print a (dismissable) warning, e.g. via /etc/banner and a notice in LuCI. It's up to the user to resolve these issues.

  4. Restoring opkg packages should be a separate choice for the user. I'd vote for enabling it by default, but the user should be able to disable this option, e.g. if the user already knows that it won't work properly (e.g. due to a missing internet connection).

Why am I suggesting this? Because I manage various OpenWrt devices remotely which I access via OpenVPN. Doing a firmware upgrade via a VPN connection works just fine. However, it's one of the OpenWrt devices that provides the OpenVPN connection - making it very hard for me to do a firmware upgrade of this device. The only thing I do after upgrade is executing opkg update and opkg install openvpn-openssl - that's it. Everything else (esp. the configs) is already included in the backup.

Another issue is me forgetting to install a package after firmware upgrade: Just today I wondered why one of my smart home devices wasn't accessible even though everything looked fine. The issue: I forgot to install the driver of a USB wifi dongle connected to one of my OpenWrt devices. This is, without any question, my mistake, but restoring previously installed opkg packages would solve it nevertheless.

Isn't that already available? See https://openwrt.org/docs/guide-user/installation/generic.sysupgrade#reinstall_user-installed_packages

1 Like

Sure, this is indeed possible (more or less), however, it requires manual interference (or a custom firmware image). I suggest to automatically reinstall previously installed opkg packages without any manual interference.

The main issue is that opkg doesn't distinguish between user installed packages (let's call it "class A"), packages installed just to fulfill dependencies (call it "class B") and pre-installed packages (call it "class C"). opkg list-installed includes all packages, no matter why they have been installed. opkg_list_dest can only distinguish the installation target, i.e. between "class C" and "class A+B" (even though this isn't strictly correct). However, to automate this we solely need "class A" packages. Not doing so will cause issues at some point - which is, following the previous discussions I've read, the reason why this idea was rejected in the past. By keeping track of just user installed packages (i.e. "class A") we can circumvent these issues.

Everything else, i.e. the actual process of installing the packages, isn't really a big deal. It's already there, it's just not being used yet.

1 Like

part of the issue here are the stacked multiple layers... some more ambiguous than others...

lets say you make it the default...

then someone from a small memory device with extroot-overlay re-installs and BOOM, disk full....

hang-on.... we can differentiate between previous install dest and make sure we only restore to equivalent install dest..., you've just added about 12 layers of complexity... as even the install dest determination needs un-ambuigification...

I fully agree about the medium term need for proper 'user post-install' added packages... and some package name / changes dbs... i.e.

ddns-scripts_cloudflare.com-v4 >> ddns-scripts-cloudflare

could probably use a category for 'internet-critical' packages... and on that point... i'd propose this step when implemented is a 'pre-sysupgrade' step... a'la 'chef-imagebuilder'...

handles the no-internet component... and a user is warned pre-upgrade if the supplimental package.zip could not be made / packages could not be resolved / were too large in total etc... of course this would exclude many low ram devices... but it's the smartest way to do it... and also offers gui based tick-deselect or even tick-ignore-config per-package...

1 Like

Would adding critical user installed packages from rc.local so that opkg is updated after every boot or upgrade work.

in a simple sense... yup... so long as;

  • internet connectivity is fairly predictable, not dependant on said pkg/s ( and said packages dont pose significant risk of breaking connectivity i.e. mwan / pbr etc... )
  • checks for 'for pkg is-installed?' ( before opkg update so you are not wasting time / repeat installs )
  • some logger action to keep notifying the user on repeated fails so they can find out say a package name changed / the system is failing again and again...
  • possible space pre/post checks

but yes, for a few packages on most devices... a pretty simple 'for pkg; if not-installed > install; done' should work pretty well...

2 Likes

this log shows a little about the complexities;

[root@dca632 /usbstick 42°]#  rpi-support.sh | grep -E '(^###|^opkg)'
##################################################### 20200827183202
opkg install libattr #[ok] #customapp
opkg install libacl #[ok] #customapp
opkg install libcap #[ok] #customapp
opkg install coreutils-vdir #[ok] #customapp
##################################################### 20200827205715
opkg install libattr #[ok] #customapp
opkg install libacl #[ok] #customapp
opkg install libcap #[ok] #customapp
opkg install coreutils-vdir #[ok] #customapp
##################################################### 20200828002028
opkg install libattr #[ok] #customapp
opkg install libacl #[ok] #customapp
opkg install libcap #[ok] #customapp
opkg install collectd-mod-contextswitch #[ok] #customapp
##################################################### 20200828010216
opkg install libattr #[ok] #customapp
opkg install libacl #[ok] #customapp
opkg install libcap #[ok] #customapp
opkg install collectd-mod-contextswitch #[ok] #customapp
##################################################### 20200828013929
opkg install libattr #[ok] #customapp
opkg install libacl #[ok] #customapp
opkg install libcap #[ok] #customapp
opkg install collectd-mod-contextswitch #[ok] #customapp
opkg install kmod-lib-zlib-inflate #[ok] #customapp
opkg install kmod-fs-isofs #[ok] #customapp
opkg install kmod-scsi-core #[ok] #customapp
opkg install kmod-scsi-cdrom #[ok] #customapp
opkg install kmod-scsi-generic #[ok] #customapp
opkg install kmod-nls-iso8859-13 #[ok] #customapp
opkg install kmod-nls-iso8859-15 #[ok] #customapp
opkg install kmod-usb-storage #[ok] #customapp
opkg install kmod-usb-storage #[ok]-extras #customapp
opkg install kmod-usb-storage #[ok]-uas #customapp
##################################################### 20200828021421
opkg install libattr #[ok] #customapp
opkg install libacl #[ok] #customapp
opkg install kmod-usb-ohci #[ok]#customapp
opkg install kmod-rabies #[fail]#customapp
##################################################### 20200828034911
opkg install libattr #[ok]#customapp
opkg install libacl #[ok]#customapp
opkg install libcap #[ok]#customapp
opkg install collectd-mod-contextswitch #[ok]#customapp
opkg install kmod-lib-zlib-inflate #[ok]#customapp
opkg install kmod-fs-isofs #[ok]#customapp
opkg install kmod-scsi-core #[ok]#customapp
opkg install kmod-scsi-cdrom #[ok]#customapp
opkg install kmod-scsi-generic #[ok]#customapp
opkg install kmod-nls-iso8859-13 #[ok]#customapp
opkg install kmod-nls-iso8859-15 #[ok]#customapp
opkg install kmod-usb-storage #[ok]#customapp
opkg install kmod-usb-storage-extras #[ok]#customapp
opkg install kmod-usb-storage-uas #[ok]#customapp
opkg install kmod-usb-ehci #[ok]#customapp
opkg install kmod-usb2 #[ok]#customapp
opkg install kmod-usb-ohci #[ok]#customapp
##################################################### 20200829012154
##################################################### 20200829025025
##################################################### 20200829031711
##################################################### 20200829034221
##################################################### 20200829044631
##################################################### 20200829055500
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200829172024
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200829174910
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200829180249
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200829182627
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200829190943
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200829192818
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200830023231
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200830025454
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200831075109
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200831100323
opkg install resize2fs #[ok]#customapp
opkg install collectd-mod-contextswitch #[ok]#customapp
##################################################### 20200901031143
opkg remove --force-removal-of-dependent-packages libwolfssl24 #[ok]#997-remtxt-removed-previously
opkg install libmbedtls12 #[ok]#customapp
opkg install collectd-mod-contextswitch #[ok]#customapp
opkg install fping #[ok]#customapp
##################################################### 20200901032049
##################################################### 20200901032925
##################################################### 20200901035054
##################################################### 20200903010617
opkg install libcap #[fail]#customapp
opkg install collectd-mod-contextswitch #[fail]#customapp
opkg install libwebsockets-full #[fail]#customapp
opkg install ttyd #[fail]#customapp
opkg install luci-app-ttyd #[fail]#customapp
##################################################### 20200903031950
##################################################### 20200903033521
##################################################### 20200903040123
##################################################### 20200903043223
##################################################### 20200903055331
##################################################### 20200903123222
##################################################### 20200903133328
##################################################### 20200905140544
opkg install ncdu #[ok]#customapp
opkg install libncurses-dev #[ok]#customapp
##################################################### 20200907045429
opkg install ncdu #[ok]#customapp
opkg install libncurses-dev #[ok]#customapp
opkg install libminiupnpc #[ok]#customapp
opkg install libnatpmp1 #[ok]#customapp
opkg install zerotier #[ok]#customapp
##################################################### 20200908141948
##################################################### 20200909084853
opkg remove --force-removal-of-dependent-packages luci-mod-dashboard #[ok]#997-remtxt-removed-previously
opkg install kmod-sched-cake-virtual #[fail]#customapp
##################################################### 20200909090212
##################################################### 20200928112436
##################################################### 20200928122234
##################################################### 20200928122302
##################################################### 20200928125907
##################################################### 20200928131452
##################################################### 20200928131900
##################################################### 20200928151156
##################################################### 20200928154450
##################################################### 20200928155550
##################################################### 20200928163251
##################################################### 20200928165009
##################################################### 20200928171107
##################################################### 20200928173016
##################################################### 20200928173427
##################################################### 20200928175554
##################################################### 20200928180102
opkg install coreutils-users #[ok]#customapp
##################################################### 20200929004000
opkg install coreutils-users #[ok]#customapp
##################################################### 20200929170904
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001195949
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001200545
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001201715
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001204048
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001210134
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001211823
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001214035
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001224835
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001231740
opkg install coreutils-users #[ok]#customapp
##################################################### 20201001232211
opkg install coreutils-users #[ok]#customapp
##################################################### 20201010162825
opkg install coreutils-users #[ok]#customapp
opkg install python3-base #[ok]#customapp
opkg install libffi #[ok]#customapp
opkg install python3-light #[ok]#customapp
opkg install python3-unittest #[ok]#customapp
opkg install python3-ncurses #[ok]#customapp
opkg install python3-ctypes #[ok]#customapp
opkg install python3-pydoc #[ok]#customapp
opkg install python3-logging #[ok]#customapp
opkg install python3-decimal #[ok]#customapp
opkg install python3-multiprocessing #[ok]#customapp
opkg install python3-codecs #[ok]#customapp
opkg install python3-email #[ok]#customapp
opkg install python3-urllib #[ok]#customapp
opkg install python3-xml #[ok]#customapp
opkg install libsqlite3-0 #[ok]#customapp
opkg install python3-sqlite3 #[ok]#customapp
opkg install libgdbm #[ok]#customapp
opkg install python3-gdbm #[ok]#customapp
opkg install python3-distutils #[ok]#customapp
opkg install python3-openssl #[ok]#customapp
opkg install python3-cgi #[ok]#customapp
opkg install python3-cgitb #[ok]#customapp
opkg install libxml2 #[ok]#customapp
opkg install libdb47 #[ok]#customapp
opkg install python3-dbm #[ok]#customapp
opkg install python3-lzma #[ok]#customapp
opkg install python3-asyncio #[ok]#customapp
opkg install python3 #[ok]#customapp
opkg install perl #[ok]#customapp
opkg install perlbase-config #[ok]#customapp
opkg install perlbase-essential #[ok]#customapp
opkg install perlbase-xsloader #[ok]#customapp
opkg install perlbase-socket #[ok]#customapp
opkg install perlbase-base #[ok]#customapp
opkg install perlbase-bytes #[ok]#customapp
opkg install perlbase-errno #[ok]#customapp
opkg install perlbase-fcntl #[ok]#customapp
opkg install perlbase-list #[ok]#customapp
opkg install perlbase-tie #[ok]#customapp
opkg install perlbase-posix #[ok]#customapp
opkg install perlbase-scalar #[ok]#customapp
opkg install perlbase-symbol #[ok]#customapp
opkg install perlbase-selectsaver #[ok]#customapp
opkg install perlbase-io #[ok]#customapp
opkg install perlbase-class #[ok]#customapp
opkg install perlbase-cwd #[ok]#customapp
opkg install perlbase-filehandle #[ok]#customapp
opkg install perlbase-i18n #[ok]#customapp
opkg install perlbase-integer #[ok]#customapp
opkg install perlbase-re #[ok]#customapp
opkg install perlbase-unicore #[ok]#customapp
opkg install perlbase-utf8 #[ok]#customapp
opkg install perlbase-locale #[ok]#customapp
opkg install perlbase-params #[ok]#customapp
opkg install perlbase-file #[ok]#customapp
opkg install perlbase-sys #[ok]#customapp
opkg install perlbase-data #[ok]#customapp
opkg install perlbase-getopt #[ok]#customapp
opkg install luci-lib-iptparser #[ok]#customapp
opkg install libexpat #[ok]#customapp
opkg install perlbase-dynaloader #[ok]#customapp
opkg install perl-xml-parser #[ok]#customapp
opkg install perlbase-feature #[ok]#customapp
opkg install perlbase-b #[ok]#customapp
opkg install perlbase-dirhandle #[ok]#customapp
opkg install perlbase-autosplit #[ok]#customapp
opkg install perlbase-mime #[ok]#customapp
opkg install perlbase-encode #[ok]#customapp
opkg install perlbase-selfloader #[ok]#customapp
opkg install perlbase-text #[ok]#customapp
opkg install perlbase-ipc #[ok]#customapp
opkg install perlbase-ostype #[ok]#customapp
opkg install perlbase-extutils #[ok]#customapp
opkg install perlbase-http-tiny #[ok]#customapp
opkg install perlbase-time #[ok]#customapp
opkg install perlbase-net #[ok]#customapp
opkg install perlbase-opcode #[ok]#customapp
opkg install perlbase-safe #[ok]#customapp
opkg install perlbase-cpan #[ok]#customapp
opkg install perl-net-cidr-lite #[ok]#customapp
opkg install perlbase-autoloader #[ok]#customapp
opkg install libplist #[ok]#customapp
opkg install libusbmuxd #[ok]#customapp
opkg install libimobiledevice #[ok]#customapp
opkg install usbmuxd #[ok]#customapp
opkg install libusbmuxd-utils #[ok]#customapp
opkg install git #[ok]#customapp
opkg install libimobiledevice-utils #[ok]#customapp
opkg install kmod-usb-net-ipheth #[ok]#customapp
opkg install kmod-rtl8812au-ct #[ok]#customapp
opkg install kmod-ipt-hashlimit #[ok]#customapp
opkg install iptables-mod-hashlimit #[ok]#customapp
##################################################### 20201010164112
##################################################### 20201010171012
##################################################### 20201011040125
##################################################### 20201011043046
##################################################### 20201011045621
##################################################### 20201011053212
##################################################### 20201011154353
##################################################### 20201014173224
opkg install mtr #[ok]#customapp
opkg install kmod-sched-connmark #[ok]#customapp
opkg install iftop #[ok]#customapp
opkg install kmod-lib-textsearch #[ok]#customapp
opkg install kmod-asn1-decoder #[ok]#customapp
opkg install kmod-nf-nathelper-extra #[ok]#customapp
opkg install kmod-ipt-extra #[ok]#customapp
opkg install iptables-mod-extra #[ok]#customapp
opkg install kmod-ipt-nat-extra #[ok]#customapp
opkg install iptables-mod-nat-extra #[ok]#customapp
opkg install libdnet #[ok]#customapp
opkg install libdaq #[ok]#customapp
opkg install libpciaccess #[ok]#customapp
opkg install libhwloc #[ok]#customapp
opkg install luajit #[ok]#customapp
opkg install libnghttp2-14 #[ok]#customapp
opkg install snort #[ok]#customapp
##################################################### 20201016132614
##################################################### 20201017161821
##################################################### 20201017170524
##################################################### 20201017201523

What happens if a user chooses to run opkg install with a number of large packages on a small storage device? opkg will bail. Since restoring packages is post sysupgrade it won't damage the device - one just has to perform a factory reset and try again, this time without ticking the "Reinstall opkg packages" checkbox.

The goal is not to make firmware flashing and restoring backups bulletproof, they never were and will likely never be, the goal is best effort and improving the current situation. Just take packages installed using a FQDN (see original post): We can't be sure that the installed package matches the one in the package repository, thus we should notify the user and skip this package. You brought up packages with new names, which is basically a special case of a package not being available anymore (see original post). Let's notify the user, the user will deal with it.

All these issues are edge cases. I assume >90% of restorations will run just fine. What matters is that introducing this process won't ever make the situation worse. An example of making the situation worse would be to brick a device due to installing incompatible packages, or installing unnecessary packages eating up valuable storage. My suggestion targets these major issues by providing a way to ensure compatibility, and ensuring that only packages the user chose are being installed.

I don't think waiting for the "perfect solution" with checking the device beforehand, providing a database of alternative packages, introducing package categories, adding a GUI allowing one to (un)tick single packages, etc. is a good thing. This "perfect solution" will likely never happen from the start. Let's start with a best effort solution in the short term and improve it over time.

1 Like
only tested on snapshot... turned out a teency bit over simple
PACKAGES="coreutils-shred coreutils-shuf coreutils-sleep coreutils-sort coreutils-split coreutils-stat"

i=$(basename $0)

echL() {
	logger $i "${1}"
	echo "${1}"
}


reinstallpackages() {

	#local DEBUG=1
	local pINSTALL=
	local addPKG=

	if [ -f "/root/.$i.ok" ]; then echL "ok"; return 0; fi

	#if ! command -v curl &>/dev/null; then echL "install curl" && return 1; fi
	if ! command -v wget &>/dev/null; then echL "install wget" && return 1; fi

	eval $(grep '^BUILD_ID' /etc/os-release)
	urlK=$(dirname $(cat /etc/opkg/distfeeds.conf | sed 's!^#!!g' | grep openwrt_core | cut -d' ' -f3))
	urlPKG=$(dirname $(cat /etc/opkg/distfeeds.conf | sed 's!^#!!g' | grep openwrt_luci | cut -d' ' -f3))
	manifest="openwrt-$(grep '^OPENWRT_BOARD' /etc/os-release | cut -d'=' -f2 | sed 's!"!!g' | sed 's!\/!-!g').manifest"
	if ! echo $urlK | grep -q 'https'; then urlK=$(echo $urlK | sed 's!^http!https!g'); fi; [ -n "$DEBUG" ] && echo "$urlK/$manifest"

	if [ -n "$DEBUG" ]; then
		echo "#################################################################"
		echo "       build: $BUILD_ID"
		echo "      urlTGT: $urlK"
		echo "      urlPKG: $urlPKG"
		echo "    PACKAGES: $PACKAGES"
		echo "#################################################################"
	fi


	#if ! curl $urlK/$manifest 2>/dev/null > /tmp/manifest; then echL "nointernet"; return 1; fi
	if ! wget $urlK/$manifest 2>/dev/null > /tmp/manifest; then echL "nointernet"; return 1; fi
	rm $manifest

	for chkPKG in ${*}; do
		if [ "$(opkg status ${chkPKG} | wc -l)" -eq 0 ]; then
			pINSTALL="${pINSTALL} ${chkPKG}"
			[ -n "$DEBUG" ] && echL "$FN> ${chkPKG} [installqueue]" msg
		else
			[ -n "$DEBUG" ] && echL "${chkPKG} [onsys]" msg
		fi
	done


	if [ ! -z "$pINSTALL" ]; then
       
		ATTEMPTSMAX=10
		ATTEMPTS=1
		BACKOFF=1
		LOCKf="/var/lock/opkg.lock"
		if [ ! -e "$LOCKf" ]; then NOLOCK=1; fi
		while [ -z "$NOLOCK" ] && [ "$ATTEMPTS" -lt "$ATTEMPTSMAX" ] && [ -e "$LOCKf" ]; do
    		DNET=$(date +%Y%m%d%H%M%S)
    		echo "lockf: $LOCKf ATTEMPTS:$ATTEMPTS($ATTEMPTSMAX)"
    		#if [ ! -z "$ALLOK" ]; then echo "SWEET"; touch /tmp/.internetok; sleep 2; break
    		ATTEMPTS=$(($ATTEMPTS + 1))
    		sleep $BACKOFF
		done
        
        echL "$FN> adding: ${pINSTALL}" msg
		[ -n "$DEBUG" ] && echL "Updating opkg..." msg
		if ! opkg update 1>/dev/null 2>/dev/null; then echL "$FN> opkgupdatefail" msg && return 1; fi
	else
		echL "$FN> allinstalled"; touch /root/.$i.ok; return 0
	fi

	for addPKG in ${pINSTALL}; do
		if ! opkg install ${addPKG} 1>/dev/null 2>/dev/null; then
			echL "install ${addPKG} [fail]"
            PKGISSUES="${PKGISSUES} ${addPKG}"
        else
			echL "install ${addPKG} [success]"
		fi
	done

    if [ -z "$PKGISSUES" ]; then
	    touch /root/.$i.ok; echo "$i> pkgrestore: [complete]"; return 0
    else
        echo "$i> issues: ${PKGISSUES}"; return 1
    fi

}


reinstallpackages ${PACKAGES}
1 Like

I'm afraid transaction tracking requires patching the Opkg code.
However, you can mostly solve the issue by using a custom profile:
https://openwrt.org/docs/guide-user/advanced/opkg_extras

1 Like

just adding a small note on this thread as it's kind of related... ( not packages but streamlining conf backups @ handling of ext4 or pure extroot systems )

sysupgrade needs some tweaks for non rom based installs... at the moment the 'help' is not specific about which features are ROM only features...

i.e.;

[root@dca632 /usbstick 43°]# sysupgrade -c -l
Cannot find '/overlay/upper/etc', required for '-c'
[root@dca632 /usbstick 43°]# sysupgrade -o -l
Cannot find '/overlay/upper/etc', required for '-c'

###### this is the only help line re: rom
#	-u           skip from backup files that are equal to those in /rom

might create a new thread regarding improvements to config migration etc. as above in the future...( ext4 tweaks ) if anyone else is interested, create a thread and tag me...

1 Like

Automatic install of manual selection of opkg packages after sysupgrade

/etc/config/package

config package
	option name 'wireguard-tools'

config package
	option name 'luci-app-wireguard'

/etc/rc.local

# wait for ntp to get current date and time
sleep 120 && \
package-automatic-installation >/dev/null 2>&1 && \
package-reboot-after-sysupgrade &

exit 0

/etc/sysupgrade.conf

/usr/bin/package-automatic-installation
/usr/bin/package-reboot-after-sysupgrade

/usr/bin/package-automatic-installation

#! /bin/sh

result=0
i=0
package="$(uci -q get package.@package[$i].name)"

while [ -n "$package" ]; do
	if [ ! -e /usr/lib/opkg/info/"$package".control ]; then
		if [ ! -e /tmp/opkg-lists ]; then
			opkg update || exit 1
		fi

		package_remove="$(uci -q get package.@package[$i].package_remove)"
		if [ -n "$package_remove" ]; then
			if [ -e /usr/lib/opkg/info/"$package_remove".control ]; then
				if ! opkg remove "$package_remove"; then
					result=1
				fi
			fi
		fi

		if ! opkg install "$package"; then
			result=1
		fi
	fi

	i="$((i+1))"
	package="$(uci -q get package.@package[$i].name)"
done

exit "$result"

/usr/bin/package-reboot-after-sysupgrade

#! /bin/sh

if [ ! -f /etc/os-release ]; then
	echo "$0: /etc/os-release: File not found" >&2
	exit 1
else
	VERSION="$(sed -n '/^VERSION=/{ s/^VERSION="//; s/"$//; p; }' < /etc/os-release)"
	if [ -z "$VERSION" ]; then
		echo "$0: /etc/os-release: No version found" >&2
		exit 1
	else
		VERSION_OLD="$(uci -q get package.@rebooted_after_sysupgrade[-1].os_release_version)"

		if [ "$VERSION_OLD" != "$VERSION" ]; then
			if [ ! -e /etc/config/package ]; then
				touch /etc/config/package
			fi
			uci -q delete package.@rebooted_after_sysupgrade[-1]
			uci add package rebooted_after_sysupgrade >/dev/null
			uci set package.@rebooted_after_sysupgrade[-1].os_release_version="$VERSION"
			uci commit package
			sync
			reboot
		else
			exit 0
		fi
	fi
fi

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.