Advertisement
s243a

trim_puppy.sh (4)

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