Advertisement
s243a

trim_puppy.sh (3)

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