s243a

trim_puppy.sh (6)

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