Advertisement
s243a

trim_puppy.sh (2)

Mar 24th, 2019
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.34 KB | None | 0 0
  1. curdir=`pwd`
  2. s_rootfs="rootfs"
  3. prefix=""
  4. action="move"
  5.  
  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. #Let's remove this desktop related stuff and move it into a different sfs
  11. B=( "desk_icon_theme_blue_moon_Slacko" "desk_icon_theme_stardust" \
  12. "desk_icon_theme_zabuton" "desktop-file-utils" "gnome-menus" )
  13.  
  14.  
  15. #!/bin/sh
  16. curdir=`pwd`
  17. rootfs="$s_rootfs"
  18. xinteractive=1
  19. prefix=""
  20. unmount_vfs(){
  21.  umount -l $curdir/$rootfs/dev 2>/dev/null
  22.  umount -l $curdir/$rootfs/sys 2>/dev/null
  23.  umount -l $curdir/$rootfs/proc 2>/dev/null
  24.  #umount /mnt/wktaz 2>/dev/null
  25.  #umount /mnt/wksfs 2>/dev/null
  26. }  
  27.  
  28. trap unmount_vfs EXIT
  29. trap unmount_vfs SIGKILL
  30. trap unmount_vfs SIGTERM
  31. xinteractive=1
  32. echo "PUPMODE='2'" > $curdir/$rootfs$prefix/etc/rc.d/PUPSTATE
  33. mkdir -p $curdir/$rootfs/proc;
  34. mkdir -p $curdir/$rootfs/sys
  35.  
  36. mount -o rbind /proc $curdir/$rootfs/proc
  37. mount -t sysfs none $curdir/$rootfs/sys
  38. if [ $xinteractive -eq 1 ]; then
  39.  echo "Removing block device files..."
  40.  #rm -rf $curdir/$rootfs/dev/*
  41.  #mount bind -t devtmpfs none $curdir/$rootfs/dev
  42.  mount -o rbind /dev $curdir/$rootfs/dev
  43.  cp -f /etc/resolv.conf $curdir/$rootfs/etc/resolv.conf
  44. fi
  45.  
  46. copy_built_in(){
  47.   set -x
  48.   app=$1
  49.   file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
  50.   echo "file_list=$file_list"
  51.   mkdir -p /tmp/trim_puppy
  52.   exec 10<> /tmp/trim_puppy/fd_9
  53.   subdir="/"
  54.   mkdir -p /tmp/trim_puppy/
  55.   rm "/tmp/trim_puppy/$app"
  56.   touch "/tmp/trim_puppy/$app"
  57.   while IFS=$'\n' read  -r -d $'\n' -u10 line ; do
  58.        line=`echo "$line" | tr -d '[:space:]'`
  59.        if [ ! "${line:0:1}" = "/" ]; then
  60.            line=$subdir$line
  61.        fi
  62.        echo $line>>"/tmp/trim_puppy/$app"
  63.        if [ "${target:0:1}" = "/" ]; then
  64.          target_prefixed="$target$line"
  65.          target_root="$target"      
  66.        else
  67.          target_root="$curdir/$target"
  68.          target_prefixed="$curdir/$target$line"      
  69.        fi  
  70.        if [ "${s_rootfs:0:1}" = "/" ]; then
  71.          source_prefixed="$s_rootfs$line"
  72.          cd "$s_rootfs" #this is necessary for the cpio command below    
  73.        else
  74.          source_prefixed="$curdir/$s_rootfs$line"    
  75.          cd "$curdir/$s_rootfs"  #this is necessary for the cpio command below
  76.        fi  
  77.        
  78.     if [ -d "$source_prefixed" ]; then
  79.        subdir="$line"
  80.        echo ".$line" | cpio -pd "$target_root"
  81.        subdir=${subdir%/}/
  82.     else
  83.        target_dir=`dirname $target_prefixed`
  84.        if [ ! -d "$target_dir" ]; then
  85.         source_dir=`dirname $line`
  86.         echo ".$source_dir" | cpio -pd "$target_root"      
  87.        fi
  88.        if [ "$arr_action" = "mv" ]; then
  89.          cp -a -u "$source_prefixed" "$target_prefixed"
  90.        else
  91.          cp -uf "$source_prefixed" "$target_prefixed"
  92.        fi
  93.     fi
  94.   done 10< <( cat "$file_list" )
  95.   exec 10>&-
  96.   set +x
  97. }
  98.  
  99.  
  100. for arr_name in A B; do
  101.   eval "arr=( \"\${"$arr_name"[@]}\" )"
  102.   arr_action=`$"$arr_name"_action`
  103.   #Move is faster but perhaps copy is safer
  104.   arr_action=${arr_action:-cp}
  105.   set -x
  106.   eval 'target="$'$arr_name'_target"'
  107.   target=${target:-"$curdir/$arr_name"}
  108.   set +x
  109.   if [ "${s_rootfs:0:1}" = "/" ]; then
  110.     s_rootfs_prefixed="$s_rootfs"    
  111.   else
  112.     s_rootfs_prefixed="$curdir/$s_rootfs"    
  113.   fi  
  114.   for app in "${arr[@]}"; do
  115.       echo "arr_action=$arr_action"
  116.       case "$arr_action" in
  117.       cp|mv)  
  118.           echo "app=$app"
  119.           copy_built_in "$app"        
  120.           ;;
  121.       #mv)
  122.       #    move_built_in()
  123.       #;;
  124.       #pet) #We might also want to convert to other package formats
  125.       #    mk_pet_fm_built_in()
  126.       #;;
  127.       esac
  128.       if [ -f "/tmp/trim_puppy/$app" ]; then
  129.         file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
  130.         rm "$file_list"
  131.         cp "/tmp/trim_puppy/$app" "$file_list"
  132.       fi
  133.       chroot "$s_rootfs_prefixed" remove_builtin "$app"
  134.   done
  135. done
  136.  
  137.  
  138. if [ "$(mount | grep "$curdir/$rootfs/dev")" != "" ]; then
  139.  umount -l $curdir/$rootfs/dev
  140. fi 
  141.  
  142. if [ "$(mount | grep "$curdir/$rootfs/sys")" != "" ]; then
  143.  umount -l $curdir/$rootfs/sys
  144. fi 
  145. if [ "$(mount | grep "$curdir$rootfs/proc")" != "" ]; then
  146.  umount -l $curdir/$rootfs/proc
  147. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement