[OpenWrt-Devel,v2,4/4] base-files: add sysupgrade -k to save list of pkgs

Message ID 20180404232826.10815-5-luizluca@gmail.com
State New
Delegated to: John Crispin
Headers show
Series
  • base-files: add new backup options
Related show

Commit Message

Luiz Angelo Daros de Luca April 4, 2018, 11:28 p.m.
When '-k' is used, sysupgrade inserts into backup a new file
/etc/sysupgrade.installed which contains pkgname and
origin (rom, overlay, unknown).

It's maily used to reinstall all extra packages:

 # opkg update
 # grep "\toverlay" etc/sysupgrade.installed | cut -f1 | xargs opkg install
 # rm etc/sysupgrade.installed

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
 package/base-files/files/sbin/sysupgrade | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Comments

Philip Prindeville April 21, 2018, 1 a.m. | #1
Inline

> On Apr 4, 2018, at 5:28 PM, Luiz Angelo Daros de Luca <luizluca@gmail.com> wrote:
> 
> When '-k' is used, sysupgrade inserts into backup a new file
> /etc/sysupgrade.installed which contains pkgname and
> origin (rom, overlay, unknown).
> 
> It's maily used to reinstall all extra packages:
> 
> # opkg update
> # grep "\toverlay" etc/sysupgrade.installed | cut -f1 | xargs opkg install
> # rm etc/sysupgrade.installed
> 
> Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
> ---
> package/base-files/files/sbin/sysupgrade | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
> 
> diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
> index 01a942bac6..c5067a757b 100755
> --- a/package/base-files/files/sbin/sysupgrade
> +++ b/package/base-files/files/sbin/sysupgrade
> @@ -11,6 +11,7 @@ export SAVE_CONFIG=1
> export SAVE_OVERLAY=0
> export SAVE_OVERLAY_PATH=
> export SAVE_PARTITIONS=1
> +export SAVE_INSTALLED_PKGS=0
> export SKIP_UNCHANGED=0
> export CONF_IMAGE=
> export CONF_BACKUP_LIST=0
> @@ -31,6 +32,7 @@ while [ -n "$1" ]; do
> 		-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
> 		-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
> 		-p) export SAVE_PARTITIONS=0;;
> +		-k) export SAVE_INSTALLED_PKGS=1;;
> 		-u) export SKIP_UNCHANGED=1;;
> 		-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
> 		-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
> @@ -50,6 +52,7 @@ done
> 
> export CONFFILES=/tmp/sysupgrade.conffiles
> export CONF_TAR=/tmp/sysupgrade.tgz
> +export INSTALLED_PACKAGES=/etc/sysupgrade.installed
> 
> IMAGE="$1"
> 
> @@ -67,6 +70,8 @@ upgrade-option:
> 	-u           skip from backup files that are equals to those in /rom
> 	-n           do not save configuration over reflash
> 	-p           do not attempt to restore the partition table after flash.
> +	-k           include in backup a list of current installed packages at
> +	             $INSTALLED_PACKAGES
> 	-T | --test
> 	             Verify image and config .tar.gz but do not actually flash.
> 	-F | --force
> @@ -203,6 +208,15 @@ fi
> 
> include /lib/upgrade
> 
> +targz_append() {
> +	local tar="$1"
> +	local append_tar="$2"
> +	(	gunzip -c "$tar" | head -c -1024;
> +		gunzip -c $append_tar
> +	) | gzip > $tar.new


This seems a bit fragile…  Isn’t there a better way to do this?


> +	mv -f $tar.new $tar
> +}
> +
> do_save_conffiles() {
> 	local conf_tar="$1"
> 
> @@ -219,6 +233,22 @@ do_save_conffiles() {
> 	[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
> 	tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
> 
> +	if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
> +		mkdir -p /tmp/etc
> +		cd /tmp/
> +
> +		# Format: pkg-name<TAB>{rom,overlay,unkown}
> +		# rom is used for pkgs in /rom, even if updated later
> +		find /usr/lib/opkg/info -name "*.control" \( \
> +			\( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
> +			\( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
> +			\( -exec echo {} unknown \; \) \
> +			\) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES:1}
> +
> +		tar c${TAR_V}zf sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
> +		targz_append "$conf_tar" sysupgrade.installed.packages.tgz
> +		rm -f sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
> +	fi
> 	rm -f "$CONFFILES"
> }
> 
> --
> 2.16.3
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;" class="">Inline</span><br style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">On Apr 4, 2018, at 5:28 PM, Luiz Angelo Daros de Luca &lt;<a href="mailto:luizluca@gmail.com" class="">luizluca@gmail.com</a>&gt; wrote:<br class=""><br class="">When '-k' is used, sysupgrade inserts into backup a new file<br class="">/etc/sysupgrade.installed which contains pkgname and<br class="">origin (rom, overlay, unknown).<br class=""><br class="">It's maily used to reinstall all extra packages:<br class=""><br class=""># opkg update<br class=""># grep "\toverlay" etc/sysupgrade.installed | cut -f1 | xargs opkg install<br class=""># rm etc/sysupgrade.installed<br class=""><br class="">Signed-off-by: Luiz Angelo Daros de Luca &lt;<a href="mailto:luizluca@gmail.com" class="">luizluca@gmail.com</a>&gt;<br class="">---<br class="">package/base-files/files/sbin/sysupgrade | 30 ++++++++++++++++++++++++++++++<br class="">1 file changed, 30 insertions(+)<br class=""><br class="">diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade<br class="">index 01a942bac6..c5067a757b 100755<br class="">--- a/package/base-files/files/sbin/sysupgrade<br class="">+++ b/package/base-files/files/sbin/sysupgrade<br class="">@@ -11,6 +11,7 @@ export SAVE_CONFIG=1<br class="">export SAVE_OVERLAY=0<br class="">export SAVE_OVERLAY_PATH=<br class="">export SAVE_PARTITIONS=1<br class="">+export SAVE_INSTALLED_PKGS=0<br class="">export SKIP_UNCHANGED=0<br class="">export CONF_IMAGE=<br class="">export CONF_BACKUP_LIST=0<br class="">@@ -31,6 +32,7 @@ while [ -n "$1" ]; do<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>-p) export SAVE_PARTITIONS=0;;<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>-k) export SAVE_INSTALLED_PKGS=1;;<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>-u) export SKIP_UNCHANGED=1;;<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;<br class="">@@ -50,6 +52,7 @@ done<br class=""><br class="">export CONFFILES=/tmp/sysupgrade.conffiles<br class="">export CONF_TAR=/tmp/sysupgrade.tgz<br class="">+export INSTALLED_PACKAGES=/etc/sysupgrade.installed<br class=""><br class="">IMAGE="$1"<br class=""><br class="">@@ -67,6 +70,8 @@ upgrade-option:<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>-u &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;skip from backup files that are equals to those in /rom<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>-n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do not save configuration over reflash<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>-p &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do not attempt to restore the partition table after flash.<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span>-k &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include in backup a list of current installed packages at<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-converted-space">&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$INSTALLED_PACKAGES<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>-T | --test<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-converted-space">&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Verify image and config .tar.gz but do not actually flash.<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>-F | --force<br class="">@@ -203,6 +208,15 @@ fi<br class=""><br class="">include /lib/upgrade<br class=""><br class="">+targz_append() {<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span>local tar="$1"<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span>local append_tar="$2"<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span>(<span class="Apple-tab-span" style="white-space: pre;">	</span>gunzip -c "$tar" | head -c -1024;<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>gunzip -c $append_tar<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span>) | gzip &gt; $tar.new<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline !important; float: none;" class="">This seems a bit fragile… &nbsp;Isn’t there a better way to do this?</span><br style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Menlo-Regular; font-size: 11px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span>mv -f $tar.new $tar<br class="">+}<br class="">+<br class="">do_save_conffiles() {<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>local conf_tar="$1"<br class=""><br class="">@@ -219,6 +233,22 @@ do_save_conffiles() {<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>[ "$VERBOSE" -gt 1 ] &amp;&amp; TAR_V="v" || TAR_V=""<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2&gt;/dev/null<br class=""><br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span>if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>mkdir -p /tmp/etc<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>cd /tmp/<br class="">+<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span># Format: pkg-name&lt;TAB&gt;{rom,overlay,unkown}<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span># rom is used for pkgs in /rom, even if updated later<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>find /usr/lib/opkg/info -name "*.control" \( \<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>\( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>\( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>\( -exec echo {} unknown \; \) \<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>\) | sed -e 's,.*/,,;s/\.control /\t/' &gt; ${INSTALLED_PACKAGES:1}<br class="">+<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>tar c${TAR_V}zf sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>targz_append "$conf_tar" sysupgrade.installed.packages.tgz<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span><span class="Apple-tab-span" style="white-space: pre;">	</span>rm -f sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}<br class="">+<span class="Apple-tab-span" style="white-space: pre;">	</span>fi<br class=""><span class="Apple-tab-span" style="white-space: pre;">	</span>rm -f "$CONFFILES"<br class="">}<br class=""><br class="">--<br class="">2.16.3</blockquote></body></html>
Philip Prindeville April 21, 2018, 1:01 a.m. | #2
Inline

> On Apr 4, 2018, at 5:28 PM, Luiz Angelo Daros de Luca <luizluca@gmail.com> wrote:
> 
> When '-k' is used, sysupgrade inserts into backup a new file
> /etc/sysupgrade.installed which contains pkgname and
> origin (rom, overlay, unknown).
> 
> It's maily used to reinstall all extra packages:
> 
> # opkg update
> # grep "\toverlay" etc/sysupgrade.installed | cut -f1 | xargs opkg install
> # rm etc/sysupgrade.installed
> 
> Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
> ---
> package/base-files/files/sbin/sysupgrade | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
> 
> diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
> index 01a942bac6..c5067a757b 100755
> --- a/package/base-files/files/sbin/sysupgrade
> +++ b/package/base-files/files/sbin/sysupgrade
> @@ -11,6 +11,7 @@ export SAVE_CONFIG=1
> export SAVE_OVERLAY=0
> export SAVE_OVERLAY_PATH=
> export SAVE_PARTITIONS=1
> +export SAVE_INSTALLED_PKGS=0
> export SKIP_UNCHANGED=0
> export CONF_IMAGE=
> export CONF_BACKUP_LIST=0
> @@ -31,6 +32,7 @@ while [ -n "$1" ]; do
> 		-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
> 		-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
> 		-p) export SAVE_PARTITIONS=0;;
> +		-k) export SAVE_INSTALLED_PKGS=1;;
> 		-u) export SKIP_UNCHANGED=1;;
> 		-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
> 		-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
> @@ -50,6 +52,7 @@ done
> 
> export CONFFILES=/tmp/sysupgrade.conffiles
> export CONF_TAR=/tmp/sysupgrade.tgz
> +export INSTALLED_PACKAGES=/etc/sysupgrade.installed
> 
> IMAGE="$1"
> 
> @@ -67,6 +70,8 @@ upgrade-option:
> 	-u           skip from backup files that are equals to those in /rom
> 	-n           do not save configuration over reflash
> 	-p           do not attempt to restore the partition table after flash.
> +	-k           include in backup a list of current installed packages at
> +	             $INSTALLED_PACKAGES
> 	-T | --test
> 	             Verify image and config .tar.gz but do not actually flash.
> 	-F | --force
> @@ -203,6 +208,15 @@ fi
> 
> include /lib/upgrade
> 
> +targz_append() {
> +	local tar="$1"
> +	local append_tar="$2"
> +	(	gunzip -c "$tar" | head -c -1024;
> +		gunzip -c $append_tar
> +	) | gzip > $tar.new


This seems a bit fragile…  Isn’t there a better way to do this?


> +	mv -f $tar.new $tar
> +}
> +
> do_save_conffiles() {
> 	local conf_tar="$1"
> 
> @@ -219,6 +233,22 @@ do_save_conffiles() {
> 	[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
> 	tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
> 
> +	if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
> +		mkdir -p /tmp/etc
> +		cd /tmp/
> +
> +		# Format: pkg-name<TAB>{rom,overlay,unkown}
> +		# rom is used for pkgs in /rom, even if updated later
> +		find /usr/lib/opkg/info -name "*.control" \( \
> +			\( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
> +			\( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
> +			\( -exec echo {} unknown \; \) \
> +			\) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES:1}
> +
> +		tar c${TAR_V}zf sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
> +		targz_append "$conf_tar" sysupgrade.installed.packages.tgz
> +		rm -f sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
> +	fi
> 	rm -f "$CONFFILES"
> }
> 
> --
> 2.16.3

Patch

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 01a942bac6..c5067a757b 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -11,6 +11,7 @@  export SAVE_CONFIG=1
 export SAVE_OVERLAY=0
 export SAVE_OVERLAY_PATH=
 export SAVE_PARTITIONS=1
+export SAVE_INSTALLED_PKGS=0
 export SKIP_UNCHANGED=0
 export CONF_IMAGE=
 export CONF_BACKUP_LIST=0
@@ -31,6 +32,7 @@  while [ -n "$1" ]; do
 		-c) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/etc;;
 		-o) export SAVE_OVERLAY=1 SAVE_OVERLAY_PATH=/;;
 		-p) export SAVE_PARTITIONS=0;;
+		-k) export SAVE_INSTALLED_PKGS=1;;
 		-u) export SKIP_UNCHANGED=1;;
 		-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
 		-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
@@ -50,6 +52,7 @@  done
 
 export CONFFILES=/tmp/sysupgrade.conffiles
 export CONF_TAR=/tmp/sysupgrade.tgz
+export INSTALLED_PACKAGES=/etc/sysupgrade.installed
 
 IMAGE="$1"
 
@@ -67,6 +70,8 @@  upgrade-option:
 	-u           skip from backup files that are equals to those in /rom
 	-n           do not save configuration over reflash
 	-p           do not attempt to restore the partition table after flash.
+	-k           include in backup a list of current installed packages at
+	             $INSTALLED_PACKAGES
 	-T | --test
 	             Verify image and config .tar.gz but do not actually flash.
 	-F | --force
@@ -203,6 +208,15 @@  fi
 
 include /lib/upgrade
 
+targz_append() {
+	local tar="$1"
+	local append_tar="$2"
+	(	gunzip -c "$tar" | head -c -1024;
+		gunzip -c $append_tar
+	) | gzip > $tar.new
+	mv -f $tar.new $tar
+}
+
 do_save_conffiles() {
 	local conf_tar="$1"
 
@@ -219,6 +233,22 @@  do_save_conffiles() {
 	[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
 	tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null
 
+	if [ "$SAVE_INSTALLED_PKGS" -eq 1 ]; then
+		mkdir -p /tmp/etc
+		cd /tmp/
+
+		# Format: pkg-name<TAB>{rom,overlay,unkown}
+		# rom is used for pkgs in /rom, even if updated later
+		find /usr/lib/opkg/info -name "*.control" \( \
+			\( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
+			\( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
+			\( -exec echo {} unknown \; \) \
+			\) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES:1}
+
+		tar c${TAR_V}zf sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
+		targz_append "$conf_tar" sysupgrade.installed.packages.tgz
+		rm -f sysupgrade.installed.packages.tgz ${INSTALLED_PACKAGES:1}
+	fi
 	rm -f "$CONFFILES"
 }