Advertisement
ryzhov_al

[Keenetic] Entware migration between partitions

Apr 8th, 2019 (edited)
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.71 KB | None | 0 0
  1. #!/bin/sh
  2. # The last version of this script is available at https://pastebin.com/Wm0yDd6x
  3. # Create two ext partitions with OPT1, OPT2 labels first, fix URL below if necessary
  4. #URL=http://bin.entware.net/mipselsf-k3.4/installer/mipsel-installer.tar.gz
  5. URL=http://bin.entware.net/aarch64-k3.10/installer/aarch64-installer.tar.gz
  6.  
  7. echo -n  '[1/5] Checking for OPT1 and OPT2 partitions... '
  8. OPT1=$(readlink /tmp/mnt/OPT1) && OPT2=$(readlink /tmp/mnt/OPT2)
  9. if [ $? -ne 0 ] ; then
  10.     echo "I presume I've got two partitions labeled as OPT1 and OPT2."
  11.     echo 'See you next time!'
  12.     exit 1
  13. else
  14.     echo 'done.'
  15. fi
  16.  
  17. echo -n '[2/5] Detecting current /opt partition... '
  18. OPT_MPOINT=$(mount | grep ' /opt type ' | cut -d' ' -f1)
  19. OPT=$(mount | grep $OPT_MPOINT | grep ' on /tmp/mnt/' | cut -d' ' -f 3 | cut -d'/' -f 4)
  20. if [ -z "$OPT_MPOINT" ] || [ -z "$OPT" ]; then
  21.     echo "Can't detect current /opt mountpoint. I'm too stupid for that, sorry."
  22.     exit 1
  23. fi
  24. if [ "$OPT" = "$OPT1" ]; then
  25.     echo 'done. Migrating from OPT1 to OPT2'
  26.     SRC=$OPT1
  27.     DST=$OPT2
  28. else
  29.     echo 'done. Migrating from OPT2 to OPT1'
  30.     SRC=$OPT2
  31.     DST=$OPT1
  32. fi
  33.  
  34. echo '[3/5] Cleaning up target partition... '
  35. rm -fr /tmp/mnt/$DST/*
  36. mkdir /tmp/mnt/$DST/root
  37. if [ $? -ne 0 ] ; then
  38.     echo "Can't create destination folder, exiting."
  39.     exit 1
  40. fi
  41.  
  42. echo '[4/5] Saving installed packages list...'
  43. #tar cf /tmp/mnt/$DST/root/opt.tar /opt
  44. opkg list_installed | cut -d ' ' -f 1 > /tmp/mnt/$DST/root/installed_packages.txt
  45. cp $0 /tmp/mnt/$DST/root
  46.  
  47. echo '[5/5] Downloading installation archive...'
  48. mkdir /tmp/mnt/$DST/install
  49. wget -qO /tmp/mnt/$DST/install/installer.tgz $URL
  50.  
  51. echo 'Done! You may switch OPKG partition from WebUI.'
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement