Reinstalling user package(s) after firmware upgrade


#1

If you want to save and reinstall user installed package(s) after firmware upgrade, this is the script that I use :wink:

Script name: overlaypkgs.sh

#!/bin/sh
#set -x
#by Faruk Tezcan

do_backup() {
  echo
  echo "Checking. Please wait"
  [ -f $filename ] && rm $filename>/dev/null
  echo > $filename; ret="$?"
  [ $ret -ne 0 ] && { echo "Invalid file name: $filename"; exit 1; }
  rm $filename>/dev/null
  [ $(ls -1 /overlay$UP/usr/lib/opkg/info/*.control | wc -l) = 0 ] && {
    echo "No user packages found"; exit 1; }
  echo
  echo "Saved package(s):"
  for EACH in /overlay$UP/usr/lib/opkg/info/*.control
  do
    NAME="$(egrep "^Package: " $EACH | cut -f 2 -d ' ')"
    opkg whatdepends $NAME>/tmp/opkg.whatdepends
    found=0;
    while read line
    do
      if [ $found -eq 0 ]; then {
        [ "$line" == "What depends on root set" ] && found=1 
      } else found=$((found+1))
      fi
    done</tmp/opkg.whatdepends
    [ $found -eq 1 ] && { echo "$NAME"; echo $NAME>>$filename; }
  done
  rm /tmp/opkg.whatdepends>/dev/null
  echo         
  echo "$filename created"                                        
  echo                                                                                   
  echo "You should save this file now and continue your firmware upgrade"                
  echo "After the upgrade restore $filename and enter '$(basename "$0") restore' command"
} # do_backup

do_restore() {
  [ -f $filename ] || { echo "$filename could not found"; exit 1; }
  opkg update
  echo "Reinstalling user packages"
  echo "Installed packages:">$filename.log

  for EACH in `cat $filename`
  do
    [ -f /overlay$UP/usr/lib/opkg/info/$EACH.control ] || { echo $EACH; opkg install $EACH >> $filename.log; }
  done

  echo "All the package(s) in $filename reinstalled"
  echo
  echo "Please check '$filename.log'"
} # do_restore

usage() {
cat <<EOF

Usage: $(basename "$0") [OPTION(S)]...[backup|restore]
where: -f <xxx> file name to save package names
                default='/etc/config/overlaypkgs.lst'
       -d       debug option
       -h       show this help text

Backup user installed packages before firmware upgrade and restore after that


EOF

exit 1
} # usage

[ $# -eq 0 ] && usage

filename="/etc/config/overlaypkgs.lst"

while getopts ':df:h' flag
do
  case "${flag}" in
    d    ) set -x ;;
    f    ) filename=$OPTARG ;;
    \?   ) echo "Invalid option: -$OPTARG"; usage ;;
    :    ) echo "Invalid option: -$OPTARG requires an argument"; usage ;;
    h\?* ) usage ;;
  esac
done

shift "$((OPTIND-1))"   # Discard the options and sentinel --
[ $# -ne 1 ] && usage

UP=""; [ -d /overlay/upper ] && UP="/upper"
cmd=$1

case $cmd in
  backup  ) do_backup ;;
  restore ) do_restore ;;
  *       ) echo "Invalid option: -$cmd"; usage; exit 1 ;;
esac

exit 0

Usage :
overlaypkgs.sh backup
This command simply creates a list from /overlay drive for user installed package(s) in /etc/config. If you keep your settings during the firmware upgrade process you will have this file after the upgrade or you can save /etc/config/overlaypkgs.lst file somewhere else.

overlaypkgs.sh restore
Make sure that your created user package(s) list file is ready. Enter this command after the firmware upgrade and enjoy your new system without missing anyhting.


#2

With luck, capturing the user-installed packages will be part of v19 -- it is already part of master with slightly different logic