Advertisement
darsinqauros

Contribution to Tazusb clean

Oct 13th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.28 KB | None | 0 0
  1. #...............................................................................
  2. # Begin code alterations - 13.10.2014 - Rodrigo Boechat                        .
  3. # Reason:                                                                      .
  4. # A new clean_usb implementation was necessary to follow the alterations made  .
  5. # on writefs.                                                                  .
  6. #...............................................................................
  7. #...............................................................................
  8. # Maintained the original code without alterations.                            .
  9. # Thus, the original was renamed "clean_usb_orig".                             .
  10. #...............................................................................
  11.  
  12. # Clean out old backups to save disk space
  13. clean_usb_orig()
  14. {
  15.     echo ""
  16.     echo -en "\033[1m`gettext \"Clean\"`\033[0m
  17. ================================================================================"
  18. gettext "Remove old rootfs.gz.unixtimestamp backup filesystems to free up disk space."; echo -e "\n\n"
  19.     # Locate and interactively remove old filesystems from /home directory
  20.     for file in `find /home/boot/rootfs.gz.[0-9]*`
  21.     do
  22.         gettext "Do you wish to remove: `basename $file` (Yes/no/exit) ? "
  23.         read answer
  24.         case $answer in
  25.             e|E|"exit"|Exit)
  26.                 exit 0 ;;
  27.             y|Y|yes|Yes)
  28.                 rm -f $file ;;
  29.             *)
  30.             gettext "No filesystems selected, exiting..." ; echo "" ;;
  31.         esac
  32.     done
  33. }
  34.  
  35. #...............................................................................
  36. # 13.10.2014 - Rodrigo Boechat                                                 .
  37. # Now is also necessary that the "clean_usb" knows how to handle entries       .
  38. # in boot menu.                                                            .
  39. #...............................................................................
  40. clean_usb()
  41.     {
  42.     echo ""
  43.     echo -en "\033[1m`gettext \"Clean\"` Usb\033[0m
  44. ================================================================================"
  45.     gettext "Remove old unixtimestamp.rootfs.gz backup filesystems to free up disk space."; echo -e "\n\n"
  46.     gettext "What do you wish to do?"
  47.     echo -en "
  48. \033[1mStandard\033[0m Cleaning - Deletes all backups except the latest.
  49. Complete Cleaning - Deletes all backups.
  50.    
  51.    \033[1mST\033[0m for Standard
  52.    CO for Complete
  53.    Exit
  54.    
  55.    (St/co/exit):: "
  56.    
  57.     read vAnswer
  58.    
  59.     echo -e "\n"
  60.    
  61.     case $vAnswer in
  62.        ST|St|sT|st)
  63.            #..................................................................
  64.            # Remove all but the latest backup.                               .
  65.            # As the latest backup should be in boot menu entry, no change in .
  66.            # extlinux.conf & isolinux.cfg is necessary.                      .
  67.            #..................................................................
  68.            for file in $(find /home/boot/[0-9]*.rootfs.gz | sort -r | sed '1{/.*/d}')
  69.            do
  70.               echo "Removing $file..."
  71.               rm -f "$file"
  72.            done
  73.            echo "Everything done."
  74.            ;;
  75.        CO|Co|cO|co)
  76.            #..................................................................
  77.            # Remove all backup.                                              .
  78.            #..................................................................
  79.            echo "Erasing all backup. Wait a minute or two..."
  80.            find /home/boot/[0-9]*.rootfs.gz -exec rm -f '{}' \;
  81.            
  82.            #..................................................................
  83.            # Retrieve the home UUID from extlinux.conf.                      .
  84.            #..................................................................
  85.            vHome=$(cat /home/boot/extlinux/extlinux.conf | grep "home" | tail -n 1 | awk -F ' ' '{print $8}')
  86.            
  87.            #..................................................................
  88.            # Clear the Restore menu entry, from extlinux.conf & isolinux.cfg .
  89.            # and switch back to "# Space Reserved for Recovery #" instead.   .
  90.            #..................................................................
  91.            echo "Clearing extlinux & isolinux..."
  92.            sed -i ':a;N;$!ba;s/LABEL tazUsbRecovery\n\tMENU LABEL SliTaz Usb Recovery\n\tCOM32 c32box.c32\n\tappend linux \/boot\/bzImage initrd=\/boot\/[0-9]*.rootfs.gz rw root=\/dev\/null autologin '$vHome'/# Space Reserved for Recovery #/' /home/boot/extlinux/extlinux.conf
  93.            sed -i ':a;N;$!ba;s/LABEL tazUsbRecovery\n\tMENU LABEL SliTaz Usb Recovery\n\tCOM32 c32box.c32\n\tappend linux \/boot\/bzImage initrd=\/boot\/[0-9]*.rootfs.gz rw root=\/dev\/null autologin '$vHome'/# Space Reserved for Recovery #/' /home/boot/extlinux/isolinux.cfg
  94.            
  95.            echo "Everything done."
  96.            ;;
  97.        e|E|"exit"|Exit)
  98.            echo "Exiting..."
  99.            exit 0
  100.            ;;
  101.        *)
  102.            echo "Instruction not recognized. Exiting..."
  103.            exit 0
  104.            ;;
  105.     esac
  106. }
  107. #...............................................................................
  108. # End code alterations - 13.10.2014 - Rodrigo Boechat                          .
  109. #...............................................................................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement