Advertisement
darsinqauros

Contribution to Tazusb Writefs

Oct 12th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.88 KB | None | 0 0
  1. case $COMMAND in
  2.     writefs)
  3.         # Writefs to rootfs.gz
  4.         check_root
  5.         if [ -z $2 ]; then
  6.             COMPRESSION=none
  7.         else
  8.             COMPRESSION=$2
  9.         fi
  10.         # Start info
  11.         newline
  12.         boldify "$(gettext 'Write filesystem')"
  13.         separator
  14.         cat << EOT
  15. $(gettext "The command writefs will write all the current filesystem into a suitable
  16. cpio archive (rootfs.gz) usable on a bootable LiveUSB media.")
  17.  
  18. $(boldify "Archive compression:") $(colorize 36 "$COMPRESSION")
  19.  
  20. EOT
  21.         # Clear out tazpkg cache
  22.         rm /var/cache/tazpkg/* -r -f
  23.  
  24.         # Optionally remove sound card selection and screen resolution.
  25.         gettext "Do you wish to remove the sound card and screen configs ? "; echo
  26.         gettext "Press ENTER to keep or answer (No|yes|exit): "
  27.         read anser
  28.         case $anser in
  29.             e|E|"exit"|Exit)
  30.                 exit 0 ;;
  31.             y|Y|yes|Yes)
  32.                 gettext "Removing current sound card and screen configurations..."
  33.                 rm -f /var/lib/sound-card-driver
  34.                 rm -f /var/lib/alsa/asound.state
  35.                 rm -f /etc/X11/xorg.conf ;;
  36.             *)
  37.                 gettext "Keeping current sound card and screen configurations..." ;;
  38.         esac
  39.         status && newline
  40.        
  41.         # Optionally remove i18n settings
  42.         gettext "Do you wish to remove local/keymap settings ? "; echo
  43.         gettext "Press ENTER to keep or answer (No|yes|exit): "
  44.         read anser
  45.         case $anser in
  46.             e|E|"exit"|Exit)
  47.                 exit 0 ;;
  48.             y|Y|yes|Yes)
  49.                 gettext "Removing current locale/keymap settings..."
  50.                 echo "" > /etc/locale.conf
  51.                 echo "" > /etc/keymap.conf ;;
  52.             *)
  53.                 gettext "Keeping current locale/keymap settings..."
  54.                 grep -qs '^INCLUDE i18n.cfg' /home/boot/*linux/*linux.c* &&
  55.                 sed -i 's/^INCLUDE i18n.cfg/# &/' /home/boot/*linux/*linux.c* ;;
  56.         esac
  57.         status
  58.        
  59.         # Clean-up files by default
  60.         echo "" > /etc/udev/rules.d/70-persistent-net.rules
  61.         echo "" > /etc/udev/rules.d/70-persistant-cd.rules
  62.        
  63.         # Create list of files
  64.         # find / -xdev | sed '/^\/home\//d;/^\/tmp\//d' >/tmp/list
  65.         # for dev in console null tty tty1
  66.         # do
  67.         #   echo /dev/$dev >>/tmp/list
  68.         # done
  69.  
  70.         find /bin /etc /init /sbin /var /dev /lib /root /usr >/tmp/list
  71.  
  72.         for dir in /home /proc /run /sys /tmp /mnt /media /media/cdrom /media/flash /media/usbdisk
  73.         do
  74.             echo $dir >>/tmp/list
  75.         done
  76.         sed -i '/^\/var\/run\/.*pid$/d' /tmp/list
  77.  
  78.         # Generate initramfs with specified compression
  79.         if [ "$COMPRESSION" = "lzma" ]; then
  80.             gettext "Creating rootfs.gz with lzma compression... "
  81.             cpio -o -H newc | lzma e -si -so > /rootfs.gz
  82.  
  83.         elif [ "$COMPRESSION" = "gzip" ]; then
  84.             gettext "Creating rootfs.gz with gzip compression... "
  85.             cpio -o -H newc | gzip -9 > /rootfs.gz
  86.  
  87.         else
  88.             gettext "Creating rootfs.gz without compression... "
  89.             cpio -o -H newc > /rootfs.gz
  90.         fi < /tmp/list
  91.  
  92.         # Get initramfs size
  93.         size=`du -sh /rootfs.gz | cut -f 1`
  94.  
  95.         # If the bootable medium is where it should be, copy across
  96.         if (test -e /home/boot/bzImage); then
  97.             gettext "Moving rootfs.gz to media. Remember to unmount for delayed writes!"; echo ""
  98.  
  99.                         #..................................................................
  100.                         # Begin code alterations - 13.10.2014 - Rodrigo Boechat           .
  101.                         # Reasons:                                                        .
  102.                         # 1) Recreated an error that involves the physical removal of the .
  103.                         # flash drive before the end of full copy of rootfs.gz. This      .
  104.                         # causes the system to be broken for the next start.              .
  105.                         # =============================================================== .
  106.                         # 2) Currently, writefs tazusb creates a single rootfs.gz file.   .
  107.                         # And there is no entry for this new single file in boot menu.    .
  108.                         # Because the slitaz boot scheme works with four files.           .
  109.                         #..................................................................
  110.                         #..................................................................
  111.                         # 13.10.2014 - Rodrigo Boechat                                    .
  112.                         # To minimize the error occurrence described in item 1. Also      .
  113.                         # realized that previous.gz is not really necessary. Got rid of.  .
  114.                         #..................................................................
  115.  
  116.                         ## Move the old filesystem with the unix timestamp for reference
  117.                         #if (test -e /home/boot/previous.gz); then
  118.                         #       mv /home/boot/previous.gz /home/boot/rootfs.gz.$(date +%s)
  119.                         #fi
  120.                         #mv /home/boot/rootfs.gz /home/boot/previous.gz
  121.                         #mv /rootfs.gz /home/boot/.
  122.  
  123.                         mv /rootfs.gz /home/boot/newrootfs.gz
  124.                         vDate=$(date +%s)
  125.                         [ -f /home/boot/rootfs.gz ] && mv /home/boot/rootfs.gz /home/boot/$vDate.rootfs.gz
  126.                         mv /home/boot/newrootfs.gz /home/boot/rootfs.gz
  127.  
  128.                         #..................................................................
  129.                         # 13.10.2014 - Rodrigo Boechat                                    .
  130.                         # To remedy the lack of entry in the boot menu, writefs has to    .
  131.                         # insert the menu entry for itself.                               .
  132.                         # The insert was made ​​based on lines 28 and 29 found in the file: .
  133.                         # /home/boot/extlinux/extlinux.conf.                              .
  134.                         # 28- # Labels                                                    .
  135.                         # 29- LABEL slitaz                                                .
  136.                         #..................................................................
  137.                         #..................................................................
  138.                         # Retrieve the home UUID from extlinux.conf.                      .
  139.                         #..................................................................
  140.                         vHome=$(cat /home/boot/extlinux/extlinux.conf | grep "home" | tail -n 1 | awk -F ' ' '{print $8}')
  141.  
  142.                         sed -i ':a;N;$!ba;s/\(^\|\n\)\(# Labels\)\n\(LABEL slitaz\)\(\n\|$\)/\1\2\n# Begin of WriteFs Edition #\nLABEL SlitazUSB\n\tMENU LABEL Slitaz Usb\n\tCOM32 c32box.c32\n\tappend linux \/boot\/bzImage initrd=\/boot\/rootfs.gz rw root=\/dev\/null autologin '$vHome'\n# Space Reserved for Recovery #\n# End of WriteFs Edition #\n\3\4/' /home/boot/extlinux/extlinux.conf
  143.                         sed -i ':a;N;$!ba;s/\(^\|\n\)\(# Labels\)\n\(LABEL slitaz\)\(\n\|$\)/\1\2\n# Begin of WriteFs Edition #\nLABEL SlitazUSB\n\tMENU LABEL Slitaz Usb\n\tCOM32 c32box.c32\n\tappend linux \/boot\/bzImage initrd=\/boot\/rootfs.gz rw root=\/dev\/null autologin '$vHome'\n# Space Reserved for Recovery #\n# End of WriteFs Edition #\n\3\4/' /home/boot/extlinux/isolinux.cfg
  144.  
  145.                         #..................................................................
  146.                         # 13.10.2014 - Rodrigo Boechat                                    .
  147.                         # Also a menu entry for recovery.                                 .
  148.                         #..................................................................
  149.                         if [ -f /home/boot/$vDate.rootfs.gz ]; then
  150.                        
  151.                            vQuantity=$(ls /home/boot/*.rootfs.gz | wc -l)
  152.                            
  153.                            #..................................................................
  154.                            # Regex for the recovery menu entry.                              .
  155.                            #..................................................................
  156.                            sed -i 's/^# Space Reserved for Recovery #$/LABEL tazUsbRecovery\n\tMENU LABEL SliTaz Usb Recovery\n\tCOM32 c32box.c32\n\tappend linux \/boot\/bzImage initrd=\/boot\/'$vDate'.rootfs.gz rw root=\/dev\/null autologin '$vHome'/' /home/boot/extlinux/extlinux.conf
  157.                            sed -i 's/^# Space Reserved for Recovery #$/LABEL tazUsbRecovery\n\tMENU LABEL SliTaz Usb Recovery\n\tCOM32 c32box.c32\n\tappend linux \/boot\/bzImage initrd=\/boot\/'$vDate'.rootfs.gz rw root=\/dev\/null autologin '$vHome'/' /home/boot/extlinux/isolinux.cfg
  158.                            
  159.                            if [ $vQuantity -gt 1 ]; then
  160.                            
  161.                               #..................................................................
  162.                               # Update the recovery boot menu entry when a new backup is created.
  163.                               #..................................................................
  164.                               sed -i 's/^\tappend linux \/boot\/bzImage initrd=\/boot\/[0-9]*\.rootfs\.gz/\tappend linux \/boot\/bzImage initrd=\/boot\/'$vDate'.rootfs.gz/' /home/boot/extlinux/extlinux.conf
  165.                               sed -i 's/^\tappend linux \/boot\/bzImage initrd=\/boot\/[0-9]*\.rootfs\.gz/\tappend linux \/boot\/bzImage initrd=\/boot\/'$vDate'.rootfs.gz/' /home/boot/extlinux/isolinux.cfg
  166.                              
  167.                            fi
  168.  
  169.                         fi
  170.                            
  171.                         #..................................................................
  172.                         # End code alterations - 13.10.2014 - Rodrigo Boechat             .
  173.                         #..................................................................
  174.                        
  175.         else
  176.             gettext "rootfs.gz is located in /"; echo ""
  177.         fi
  178.  
  179.         separator
  180.         gettext "Root filesystem size: $size"; echo ""
  181.         echo ""
  182.         echo "----"
  183.         gettext "ENTER to continue..."; read i
  184.         ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement