Advertisement
s243a

trim_puppy.sh (v2-1)

Mar 29th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.65 KB | None | 0 0
  1. curdir=`pwd`
  2. s_rootfs="rootfs"
  3. alt_s_rootfs="/mnt/+mnt++root+Downloads+xslacko-slim-4.4r25.iso+puppy_xslacko_4.4.sfs"
  4. if [ -d "$alt_s_rootfs=" ]; then
  5.   retry=1 #Default action for an array
  6. fi
  7. prefix=""
  8. action="mv"
  9.  
  10. chroot_remove_builtin=0
  11. no_mount_rootfs=1
  12.  
  13. #After we remove packages we might install some replacement versions
  14. #When distro not specified in path look for pkg dirs in dir containing distro name in this order
  15. post_rm_pkg_dirs=( "pupngo" ) #Replaceing bash with pupngo's version can save a fair bit of space
  16. #When arch not specified in path look for pkg arch dir containing distro name in this order
  17. arches=( "i386" "no-arch" "i486" "i586" "i686" )
  18.  
  19.  
  20. #Applications
  21. #Let's remove these applications and maybe put them into an sfs
  22. ALL=()
  23. ALL_ArrNames=()
  24.  
  25. A_SystemCore=( "bash")
  26. ALL+=( "${A_SystemCore[@]}" )
  27. ALL_ArrNames+=( "A_SystemCore" )
  28.  
  29. curdir=`pwd`
  30. rootfs="$s_rootfs"
  31. prefix=""
  32. xinteractive=1
  33.  
  34. Post_Remove_Install_Fm_Dir=( \
  35. "i386/pupngo/bash-4.2" \
  36. )
  37.  
  38. #source pkgs_arry
  39.  
  40. #Coppies a more recent version of remove_built_in
  41. #and also a list of icu related files (to be removed) which aren't associated
  42. #with any packages
  43. pre_remove_patch="pre_remove_patch"
  44. cp --remove-destination -arf $pre_remove_patch/* \
  45.                                  $s_rootfs/ 2>/dev/null
  46. source trim_puppy_functions.sh
  47.  
  48.  
  49.  
  50.  
  51. if [ no_mount_rootfs -eq 0 ]; then
  52.   trap unmount_vfs EXIT
  53.   trap unmount_vfs SIGKILL
  54.   trap unmount_vfs SIGTERM
  55.  
  56.  
  57.   echo "PUPMODE='2'" > $curdir/$rootfs$prefix/etc/rc.d/PUPSTATE
  58.   mkdir -p $curdir/$rootfs/proc;
  59.   mkdir -p $curdir/$rootfs/sys
  60.  
  61.   mount -o rbind /proc $curdir/$rootfs/proc
  62.   mount -t sysfs none $curdir/$rootfs/sys
  63.   if [ $xinteractive -eq 1 ]; then
  64.     echo "Removing block device files..."
  65.     #rm -rf $curdir/$rootfs/dev/*
  66.     #mount bind -t devtmpfs none $curdir/$rootfs/dev
  67.     mount -o rbind /dev $curdir/$rootfs/dev
  68.     cp -f /etc/resolv.conf $curdir/$rootfs/etc/resolv.conf
  69.   fi
  70.  
  71. else
  72.   trap close_file_descriptors EXIT
  73.   trap close_file_descriptors SIGKILL
  74.   trap close_file_descriptors SIGTERM
  75. fi
  76.  
  77.  
  78.  
  79. dissect_rootfs
  80.  
  81.  
  82.  
  83.  
  84. for pkg_dir in "${Post_Remove_Install_Fm_Dir[@]}"; do
  85.   if [ "${pkg_dir:0:1}" = "." ]; then
  86.     pkg_dir="$curdir/${pkg_dir:1:}"
  87.   elif [ ! "${pkg_dir:0:1}" = "/" ]; then
  88.         rel_path=${pkg_dir%/*}
  89.         pkg_name=`basename "$pkg_dir"`
  90.         #pkg_dir="$curdir/post_patch/$arch/pupngo/$pkg_dir/$pkg_dir"
  91.         if [ -z "$rel_path" ]; then
  92.           for pkg_arch in "${arches[@]}" "."; do
  93.             for pkg_distro in "${post_rm_pkg_dirs[@]}" "."; do
  94.               rel_path="$pkg_arch/$distro"
  95.               a_pkg_dir="$curdir/post_patch/$pkg_arch/$pkg_distro/$pkg_name"
  96.               if [ -d "a_pkg_dir" ] || [ -d `readlink "$a_pkg_dir"` ]; then
  97.                  pkg_dir="$a_pkg_dir"
  98.                  break 2;
  99.               fi
  100.                  
  101.             done
  102.           done
  103.         else
  104.           echo "nothing to do"
  105.           for test_rel_path in "$rel_path" "post_patch/$rel_path"; do
  106.             pkg_dir="$curdir/$test_rel_path/$pkg_name"
  107.             if [ -d "$pkg_dir" ]; then
  108.               break
  109.             fi
  110.           done
  111.         fi
  112.   fi
  113.   inst_builtin_fm_dir "$pkg_dir"
  114. done
  115.  
  116. if [ "$no_mount_rootfs" -eq 0 ]; then
  117.   if [ chroot_remove_builtin = 1 ];then
  118.     chroot "$s_rootfs_prefixed" remove_builtin "${ALL[@]}"
  119.   fi
  120.   if [ "$(mount | grep "$curdir/$rootfs/dev")" != "" ]; then
  121.    umount -l $curdir/$rootfs/dev
  122.   fi   
  123.  
  124.   if [ "$(mount | grep "$curdir/$rootfs/sys")" != "" ]; then
  125.    umount -l $curdir/$rootfs/sys
  126.   fi   
  127.   if [ "$(mount | grep "$curdir$rootfs/proc")" != "" ]; then
  128.    umount -l $curdir/$rootfs/proc
  129.   fi
  130. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement