s243a

trim_puppy.sh (5)

Mar 27th, 2019
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.45 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. #Coppies a more recent version of remove_built_in
  89. #and also a list of icu related files (to be removed) which aren't associated
  90. #with any packages
  91. cp --remove-destination -arf $pre_remove_patch/* \
  92.                                  $s_rootfs/ 2>/dev/null
  93.  
  94. curdir=`pwd`
  95. rootfs="$s_rootfs"
  96. xinteractive=1
  97. prefix=""
  98. unmount_vfs(){
  99.  umount -l $curdir/$rootfs/dev 2>/dev/null
  100.  umount -l $curdir/$rootfs/sys 2>/dev/null
  101.  umount -l $curdir/$rootfs/proc 2>/dev/null
  102.  #umount /mnt/wktaz 2>/dev/null
  103.  #umount /mnt/wksfs 2>/dev/null
  104. }  
  105.  
  106. trap unmount_vfs EXIT
  107. trap unmount_vfs SIGKILL
  108. trap unmount_vfs SIGTERM
  109. xinteractive=1
  110. echo "PUPMODE='2'" > $curdir/$rootfs$prefix/etc/rc.d/PUPSTATE
  111. mkdir -p $curdir/$rootfs/proc;
  112. mkdir -p $curdir/$rootfs/sys
  113.  
  114. mount -o rbind /proc $curdir/$rootfs/proc
  115. mount -t sysfs none $curdir/$rootfs/sys
  116. if [ $xinteractive -eq 1 ]; then
  117.  echo "Removing block device files..."
  118.  #rm -rf $curdir/$rootfs/dev/*
  119.  #mount bind -t devtmpfs none $curdir/$rootfs/dev
  120.  mount -o rbind /dev $curdir/$rootfs/dev
  121.  cp -f /etc/resolv.conf $curdir/$rootfs/etc/resolv.conf
  122. fi
  123. copy_pet_specs(){
  124.   AWK_PRG="BEGIN{FS=\"|\"}
  125.  {
  126.    if (match(\$2,\"$app\")) {
  127.     print
  128.    }
  129.  }"
  130.   file_list=( "$rootfs_full/root/.packages/"*"-installed-packages" )
  131.   #cat "${file_list[@]}" | awk -F'|' "$AWK_PRG" #'{print $2;}'
  132.   cat "${file_list[@]}" | awk "$AWK_PRG"  >> "$inst_pkg_specs_target"
  133. }
  134. copy_built_in(){
  135.   set -x
  136.   app=$1
  137.   file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
  138.   if [ "${target:0:1}" = "/" ]; then
  139.     target_root="$target"      
  140.   else
  141.     target_root="$curdir/$target"    
  142.   fi  
  143.   target_file_list="$target_root/root/.packages/builtin_files/$app"  
  144.   echo "file_list=$file_list"
  145.   mkdir -p /tmp/trim_puppy
  146.   exec 10<> /tmp/trim_puppy/fd_10
  147.   subdir="/"
  148.   mkdir -p /tmp/trim_puppy/
  149.   rm "/tmp/trim_puppy/$app"
  150.   touch "/tmp/trim_puppy/$app"
  151.  
  152.   mkdir -p
  153.   inst_pkg_specs_target="$target_root/root/.packages/"$arr_name"-installed-packages"
  154.   mkdir -p `dirname "$inst_pkg_specs_target"`
  155.   copy_pet_specs
  156.  
  157.   while IFS=$'\n' read  -r -d $'\n' -u10 line ; do
  158.        line=`echo "$line" | tr -d '[:space:]'`
  159.        if [ ! "${line:0:1}" = "/" ]; then
  160.            line=$subdir$line
  161.        fi
  162.        echo $line>>"/tmp/trim_puppy/$app"
  163.        if [ "${target:0:1}" = "/" ]; then
  164.          target_prefixed="$target$line"
  165.          #target_root="$target" #Defined above      
  166.        else
  167.          #target_root="$curdir/$target" #Defined above
  168.          target_prefixed="$curdir/$target$line"      
  169.        fi  
  170.  
  171.        if [ "${s_rootfs:0:1}" = "/" ]; then
  172.          source_prefixed="$s_rootfs$line"
  173.          cd "$s_rootfs" #this is necessary for the cpio command below    
  174.        else
  175.          source_prefixed="$curdir/$s_rootfs$line"    
  176.          cd "$curdir/$s_rootfs"  #this is necessary for the cpio command below
  177.        fi  
  178.  
  179.     if [ -d "$source_prefixed" ]; then
  180.        subdir="$line"
  181.        echo ".$line" | cpio -pd "$target_root"
  182.        subdir=${subdir%/}/
  183.     else
  184.        target_dir=`dirname $target_prefixed`
  185.        if [ ! -d "$target_dir" ]; then
  186.         source_dir=`dirname $line`
  187.         echo ".$source_dir" | cpio -pd "$target_root"      
  188.        fi
  189.        if [ ! "$arr_action" = "mv" ]; then
  190.          cp -a -u "$source_prefixed" "$target_prefixed"
  191.        else
  192.          mv -uf "$file_list" "$source_prefixed" "$target_prefixed"
  193.          mv -uf $target_file_list
  194.        fi
  195.     fi
  196.    
  197.   done 10< <( cat "$file_list" )
  198.   exec 10>&-
  199.   set +x
  200.   if [ ! "$arr_action" = "mv" ]; then
  201.     cp -a -u "$file_list" "$target_file_list"
  202.   else
  203.     mv -uf "$file_list" "$target_file_list"
  204.   fi
  205. }
  206.  
  207.  
  208. for arr_name in "${ALL[@]}"; do
  209.   eval "arr=( \"\${"$arr_name"[@]}\" )"
  210.   arr_action=`$"$arr_name"_action`
  211.   #Move is faster but perhaps copy is safer
  212.   arr_action=${arr_action:-cp}
  213.   set -x
  214.   eval 'target="$'$arr_name'_target"'
  215.   target=${target:-"$curdir/$arr_name"}
  216.   set +x
  217.   if [ "${s_rootfs:0:1}" = "/" ]; then
  218.     s_rootfs_prefixed="$s_rootfs"    
  219.   else
  220.     s_rootfs_prefixed="$curdir/$s_rootfs"    
  221.   fi  
  222.   for app in "${arr[@]}"; do
  223.       echo "arr_action=$arr_action"
  224.       case "$arr_action" in
  225.       cp|mv)  
  226.           echo "app=$app"
  227.           copy_built_in "$app"        
  228.           ;;
  229.       #mv)
  230.       #    move_built_in()
  231.       #;;
  232.       #pet) #We might also want to convert to other package formats
  233.       #    mk_pet_fm_built_in()
  234.       #;;
  235.       esac
  236.       if [ -f "/tmp/trim_puppy/$app" ]; then
  237.         file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
  238.         rm "$file_list"
  239.         cp "/tmp/trim_puppy/$app" "$file_list"
  240.       fi
  241.       #chroot "$s_rootfs_prefixed" remove_builtin "$app"
  242.   done
  243. done
  244. chroot "$s_rootfs_prefixed" remove_builtin "${All[@]}"
  245.  
  246. if [ "$(mount | grep "$curdir/$rootfs/dev")" != "" ]; then
  247.  umount -l $curdir/$rootfs/dev
  248. fi 
  249.  
  250. if [ "$(mount | grep "$curdir/$rootfs/sys")" != "" ]; then
  251.  umount -l $curdir/$rootfs/sys
  252. fi 
  253. if [ "$(mount | grep "$curdir$rootfs/proc")" != "" ]; then
  254.  umount -l $curdir/$rootfs/proc
  255. fi
Advertisement
Add Comment
Please, Sign In to add comment