Advertisement
s243a

trim_puppy.sh

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