Advertisement
s243a

trim_puppy_retry.sh

Mar 28th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.64 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. prefix=""
  5. action="mv"
  6. retry=1 #Default action for an array
  7. chroot_remove_builtin=0
  8. #Applications
  9. #Let's remove these applications and maybe put them into an sfs
  10. ALL=()
  11. ALL_ArrNames=( "A_DesktopApplicaitons" )
  12. A_DesktopApplicaitons=( "leafpad" "solitaire-minesweeper-1.3-i486" \
  13. "gtkhash-0.6.0-i686-up" "leafpad" "MPlayer" "clipit" "geany" "get_java" \
  14.   "getflash" "get_libreoffice" "gnome-mplayer" "pfind" \
  15.  "pupmd5sum" "screener" "bulldog-finder-4.1.1" "galculator" \
  16.  "file-roller" "gparted" "gtkhash-thunar-plugin" "gnome-bluetooth-2.32.0" \
  17. "gpicview" "isomaster" "libical" "libvisual-0.4.0" "pburn-xslacko" \
  18. "pfilesearch" "pfilesearch" "pschedule" "thunar" "thunar-archive-plugin" \
  19. "thunar-volman" "mtpaint" )
  20. ALL+=( "${A_DesktopApplicaitons[@]}" )
  21. ALL_ArrNames+=( "A_DesktopApplicaitons" )
  22.  
  23. #Let's remove this desktop related stuff and move it into a different sfs
  24. #Core PUppy
  25. A_CorePuppyDtAps=( "pfontview" "Pup-Kview" "Pup-SysInfo" )
  26. ALL+=( "${A_CorePuppyDtAps[@]}" )
  27. ALL_ArrNames+=( "A_CorePuppyDtAps" )
  28.  
  29. #Dektop related stuff
  30. A_DesktopCore=( "desk_icon_theme_blue_moon_Slacko" "desk_icon_theme_stardust" \
  31. "desk_icon_theme_zabuton" "desktop-file-utils" "gnome-menus" \
  32.  "libgnomecanvas" "libxfce4ui" "libxfce4util" "libxfcegui4-4.10.0" \
  33. "puppy_icon_theme" "pup-volume-monitor" "redshiftGUI-0.2.1" "retrovol" \
  34. "pupx" "shared-mime-info" "soothe-theme" "xfce4-cpugraph-plugin-1.0.5" \
  35. "xfce4-mixer-4.11.0" "xfce4-notifyd" "xfce4-panel" "xfce4-screenshooter-1.8.1" \
  36. "xfce4-session" "xfce4-settings" "xfce4-terminal" "xfce4-whiskermenu-plugin" \
  37. "xfconf" "xfdesktop" "xfwm4" \
  38.  "garcon" "hicolor-icon-theme" "libexo_lib-0.3.2" "libgtkhtml" "lxtask" \
  39. "netmon_wce" "mkwallpaper"  )
  40. ALL+=( "${A_DesktopCore[@]}" )
  41. ALL_ArrNames+=( "A_DesktopCore" )
  42.  
  43. #Programming related stuff
  44. A_DevCore=( "libglade2" "libgladeui1_11" "puppybasic-2.5b" "subversion" "automake" \
  45.  "bacon" "flex" "gcc_dev" "git" "gcc_dev" "jimtcl" "make" "pkgconfig" \
  46. "tcl" )
  47. ALL+=( "${A_DevCore[@]}" )
  48. ALL_ArrNames+=( "A_DevCore" )
  49.  
  50. #Browser related stuff
  51. A_BrowserCore=( "libwebkitgtk-1.10.2" "libwebp-0.3.1" "gst-ffmpeg-0.10.13" \
  52. "gst-plugins-base-0.10.36" "gst-plugins-good-0.10.31" "gstreamer-0.10.36" \
  53.  "midori-0.5.9" "ffconvert" "ffmpeg" "libcroco" "libsoup-2.42.2" "lynx2-8-7-i486" \
  54. "tazweb-1.6.2" )
  55. ALL+=( "${A_BrowserCore[@]}" )
  56. ALL_ArrNames+=( "A_BrowserCore" )
  57.  
  58. #Video Related stuff
  59. A_VideoCore=( "libtheora" "libvpx" "schroedinger" )
  60. ALL+=( "${A_VideoCore[@]}" )
  61. ALL_ArrNames+=( "A_VideoCore" )
  62.  
  63. #Internet/networking reled stuff
  64. A_NetworkingCore=( "pgprs" "ppp" "rp-pppoe" "samba" "Simple-File-Sharing_Samba4" \
  65. "firewall_ng" "firewallstatus" "frisbee" \
  66.  "wvdial" "putty-0.60-2010-09-10-i486" "arp" "arp-scan" "axel-1.0a-1" "lcms" "neon" \
  67. "transmission" )
  68. ALL+=( "${A_NetworkingCore[@]}" )
  69. ALL_ArrNames+=( "A_NetworkingCore" )
  70.  
  71. #F=( "alsaequal" "alsa-lib" "alsa-utils" )
  72. #Sound Related stuff
  73. A_SoundCore=( "asunder-2.1-i486" "audiofile" "flac" "esound" "lame" "libao" \
  74. "libid3tag" "libmad" "libogg" "libvorbis" "lvm2" "mplayer_codecs_basic" )
  75. ALL+=( "${A_SoundCore[@]}" )
  76. ALL_ArrNames+=( "A_SoundCore" )
  77.  
  78. #Other Hardware and sound realted stuff
  79. A_HW_Misc=( "pTape-2.0" "bluez-4.99" "bluez-firmware-1.2" )
  80. ALL+=( "${A_HW_Misc[@]}" )
  81. ALL_ArrNames+=( "A_HW_Misc" )
  82.  
  83. #Digital Camera related stuff
  84. A_CameraCore=( "libdc1394" "libdv" "gphotofs"  )
  85. ALL+=( "${A_CameraCore[@]}" )
  86. ALL_ArrNames+=( "A_CameraCore" )
  87.  
  88. #Printing, scaners and pdfs related stuff
  89. A_PrintScanPDF+=( "libgsf" "cups" "cups_pdf" "foomatic-filters" "ghostscript" \
  90. "gtklp" "libspectre" "libtiff" "sane-backends" )
  91. ALL+=( "${A_PrintScanPDF[@]}" )
  92. ALL_ArrNames+=( "A_PrintScanPDF" )
  93.  
  94. #I'm not sure what this stuff is fore
  95. A_Unknown=( "bbc_provided" )
  96.  
  97. #Misc. Command line tools
  98. #K=()
  99. #Core stuff to remove
  100. A_SystemCore=( "icu_unknown" "bash" "jasper" "parted" )
  101. ALL+=( "${A_SystemCore[@]}" )
  102. ALL_ArrNames+=( "A_SystemCore" )
  103.  
  104. #Coppies a more recent version of remove_built_in
  105. #and also a list of icu related files (to be removed) which aren't associated
  106. #with any packages
  107. pre_remove_patch="pre_remove_patch"
  108. cp --remove-destination -arf $pre_remove_patch/* \
  109.                                  $s_rootfs/ 2>/dev/null
  110.  
  111. curdir=`pwd`
  112. rootfs="$s_rootfs"
  113. xinteractive=1S
  114. prefix=""
  115. unmount_vfs(){
  116.  umount -l $curdir/$rootfs/dev 2>/dev/null
  117.  umount -l $curdir/$rootfs/sys 2>/dev/null
  118.  umount -l $curdir/$rootfs/proc 2>/dev/null
  119.  #umount /mnt/wktaz 2>/dev/null
  120.  #umount /mnt/wksfs 2>/dev/null
  121. }  
  122.  
  123. trap unmount_vfs EXIT
  124. trap unmount_vfs SIGKILL
  125. trap unmount_vfs SIGTERM
  126. xinteractive=1
  127. echo "PUPMODE='2'" > $curdir/$rootfs$prefix/etc/rc.d/PUPSTATE
  128. mkdir -p $curdir/$rootfs/proc;
  129. mkdir -p $curdir/$rootfs/sys
  130.  
  131. mount -o rbind /proc $curdir/$rootfs/proc
  132. mount -t sysfs none $curdir/$rootfs/sys
  133. if [ $xinteractive -eq 1 ]; then
  134.  echo "Removing block device files..."
  135.  #rm -rf $curdir/$rootfs/dev/*
  136.  #mount bind -t devtmpfs none $curdir/$rootfs/dev
  137.  mount -o rbind /dev $curdir/$rootfs/dev
  138.  cp -f /etc/resolv.conf $curdir/$rootfs/etc/resolv.conf
  139. fi
  140. copy_pet_specs(){
  141.   AWK_PRG="BEGIN{FS=\"|\"}
  142.  {
  143.    if ( \$2 == \"$app\" ) {
  144.     print
  145.    }
  146.  }"
  147.   file_spec_list=( "$rootfs_full/root/.packages/"*"-installed-packages" )
  148.   #cat "${file_spec_list[@]}" | awk -F'|' "$AWK_PRG" #'{print $2;}'
  149.   spec=$( cat "${file_spec_list[@]}" | awk "$AWK_PRG"  >> "$inst_pkg_specs_target" )
  150.   match_cnt=$( grep -cF "$spec" "$inst_pkg_specs_target" )
  151.   if [ $match_cnt -eq 0 ]; then
  152.     spec >> "$inst_pkg_specs_target"
  153.   fi
  154. }
  155. copy_built_in(){
  156.   set -x
  157.   app=$1
  158.   if [ $retry -eq 1 ]; then
  159.     file_list="$alt_s_rootfs/root/.packages/builtin_files/$app"
  160.   else
  161.     file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
  162.   fi
  163.   if [ "${target:0:1}" = "/" ]; then
  164.     target_root="$target"      
  165.   else
  166.     target_root="$curdir/$target"    
  167.   fi  
  168.   target_file_list="$target_root/root/.packages/builtin_files/$app"  
  169.   echo "file_list=$file_list"
  170.   mkdir -p /tmp/trim_puppy
  171.   exec 10<> /tmp/trim_puppy/fd_10
  172.   subdir="/"
  173.   mkdir -p /tmp/trim_puppy/
  174.   rm "/tmp/trim_puppy/$app"
  175.   touch "/tmp/trim_puppy/$app"
  176.  
  177.   #mkdir -p
  178.   inst_pkg_specs_target="$target_root/root/.packages/"$arr_name"-installed-packages"
  179.   mkdir -p `dirname "$inst_pkg_specs_target"`
  180.   copy_pet_specs
  181.  
  182.   while IFS=$'\n' read  -r -d $'\n' -u10 line ; do
  183.        line=`echo "$line" | tr -d '[:space:]'`
  184.        if [ ! "${line:0:1}" = "/" ]; then
  185.            line=$subdir$line
  186.        fi
  187.        echo $line>>"/tmp/trim_puppy/$app"
  188.        if [ "${target:0:1}" = "/" ]; then
  189.          target_prefixed="$target$line"
  190.          #target_root="$target" #Defined above      
  191.        else
  192.          #target_root="$curdir/$target" #Defined above
  193.          target_prefixed="$curdir/$target$line"      
  194.        fi  
  195.  
  196.        if [ "${s_rootfs:0:1}" = "/" ]; then
  197.          source_prefixed="$s_rootfs$line"
  198.          cd "$s_rootfs" #this is necessary for the cpio command below    
  199.        else
  200.          source_prefixed="$curdir/$s_rootfs$line"    
  201.          cd "$curdir/$s_rootfs"  #this is necessary for the cpio command below
  202.        fi  
  203.  
  204.     if [ -d "$source_prefixed" ]; then
  205.        subdir="$line"
  206.        echo ".$line" | cpio -pd "$target_root"
  207.        subdir=${subdir%/}/
  208.     else
  209.        target_dir=`dirname $target_prefixed`
  210.        if [ ! -d "$target_dir" ]; then
  211.         source_dir=`dirname $line`
  212.         echo ".$source_dir" | cpio -pd "$target_root"      
  213.        fi
  214.        if [ ! -f "$source_prefixed" ] && [ $retry -eq 1 ]; then
  215.            source_prefixed="$alt_s_rootfs$line"
  216.            cp -a -u "$source_prefixed" "$target_prefixed"
  217.        elif [ ! "$arr_action" = "mv" ]; then
  218.          cp -a -u "$source_prefixed" "$target_prefixed"
  219.        else
  220.          mv -uf "$source_prefixed" "$target_prefixed"
  221.          mv -uf $target_file_list
  222.        fi
  223.     fi
  224.    
  225.   done 10< <( cat "$file_list" )
  226.   exec 10>&-
  227.   set +x
  228.   if [ ! "$arr_action" = "mv" ]; then
  229.     mkdir -p `dirname "$target_file_list"`
  230.     cp -a -u "$file_list" "$target_file_list"
  231.   else
  232.     mv -uf "$file_list" "$target_file_list"
  233.   fi
  234. }
  235.  
  236.  
  237. for arr_name in "${ALL_ArrNames[@]}"; do
  238.   eval "arr=( \"\${"$arr_name"[@]}\" )"
  239.   arr_action=`$"$arr_name"_action`
  240.   arr_action=${arr_action:-"$action"}
  241.   #Move is faster but perhaps copy is safer
  242.   arr_action=${arr_action:-cp}
  243.   set -x
  244.   eval 'target="$'$arr_name'_target"'
  245.   target=${target:-"$curdir/$arr_name"}
  246.   set +x
  247.   if [ "${s_rootfs:0:1}" = "/" ]; then
  248.     s_rootfs_prefixed="$s_rootfs"    
  249.   else
  250.     s_rootfs_prefixed="$curdir/$s_rootfs"    
  251.   fi  
  252.   for app in "${arr[@]}"; do
  253.       echo "arr_action=$arr_action"
  254.       case "$arr_action" in
  255.       cp|mv|retry)  
  256.           echo "app=$app"
  257.           copy_built_in "$app"        
  258.           ;;
  259.       #mv)
  260.       #    move_built_in()
  261.       #;;
  262.       #pet) #We might also want to convert to other package formats
  263.       #    mk_pet_fm_built_in()
  264.       #;;
  265.       esac
  266.       if [ -f "/tmp/trim_puppy/$app" ]; then
  267.         file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
  268.         rm "$file_list"
  269.         cp "/tmp/trim_puppy/$app" "$file_list"
  270.       fi
  271.       #chroot "$s_rootfs_prefixed" remove_builtin "$app"
  272.   done
  273. done
  274. if [ chroot_remove_builtin = 1 ];then
  275.   chroot "$s_rootfs_prefixed" remove_builtin "${ALL[@]}"
  276. fi
  277. if [ "$(mount | grep "$curdir/$rootfs/dev")" != "" ]; then
  278.  umount -l $curdir/$rootfs/dev
  279. fi 
  280.  
  281. if [ "$(mount | grep "$curdir/$rootfs/sys")" != "" ]; then
  282.  umount -l $curdir/$rootfs/sys
  283. fi 
  284. if [ "$(mount | grep "$curdir$rootfs/proc")" != "" ]; then
  285.  umount -l $curdir/$rootfs/proc
  286. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement