Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curdir=`pwd`
- s_rootfs="rootfs"
- alt_s_rootfs="/mnt/+mnt++root+Downloads+xslacko-slim-4.4r25.iso+puppy_xslacko_4.4.sfs"
- prefix=""
- action="mv"
- retry=1 #Default action for an array
- chroot_remove_builtin=0
- #After we remove packages we might install some replacement versions
- #When distro not specified in path look for pkg dirs in dir containing distro name in this order
- post_rm_pkg_dirs=( "pupngo" ) #Replaceing bash with pupngo's version can save a fair bit of space
- #When arch not specified in path look for pkg arch dir containing distro name in this order
- arches=( "i386" "no-arch" "i486" "i586" "i686" )
- #Applications
- #Let's remove these applications and maybe put them into an sfs
- ALL=()
- ALL_ArrNames=()
- #Printing, scaners and pdfs related stuff
- A_PrintScanPDF+=( "libgs9" )
- ALL+=( "${A_PrintScanPDF[@]}" )
- ALL_ArrNames+=( "A_PrintScanPDF" )
- #I'm not sure what this stuff is fore
- A_Unknown=( "bbc_provided" )
- ALL+=( "${A_A_Unknown[@]}" )
- ALL_ArrNames+=( "A_A_Unknown" )
- #Misc. Command line tools
- A_Commandline=( "testdisk" )
- ALL+=( "${A_Commandline[@]}" )
- ALL_ArrNames+=( "A_Commandline" )
- Post_Remove_Install_Fm_Dir=( \
- "i386/pupngo/bash-4.2" \
- )
- #source pkgs_arry
- #Coppies a more recent version of remove_built_in
- #and also a list of icu related files (to be removed) which aren't associated
- #with any packages
- pre_remove_patch="pre_remove_patch"
- cp --remove-destination -arf $pre_remove_patch/* \
- $s_rootfs/ 2>/dev/null
- delete_petspec_fm_file(){
- local field_val=$1
- local pkg_rootfs=${2:-"$s_rootfs"}
- local spec_list_name=${3:-"woof-installed-packages"}
- local field=${4:-1} #The first field is the default
- #TODO if prk_rootfs="/" or "" give warning
- AWK_PRG="BEGIN{FS=\"|\"}
- {
- if ( \$$field != \"$field_val\" ) {
- print
- }
- }"
- #TODO we probably need logic to expand wildards
- local file_spec_list=( "$pkg_rootfs/root/.packages/$spec_list_name" )
- for spec_list in "${file_spec_list[@]}"; do
- cat "$spec_list" | awk "$AWK_PRG" >> "/tmp/$spec_list"
- rm "$spec_list"
- mv "/tmp/$spec_list" "$spec_list"
- done
- }
- inst_builtin_fm_dir(){
- local source_dir=$1
- local dest_root=${2:-s_rootfs}
- local pkg_name=${3:-`basename $1`} #TODO add logic for different location of files.list
- source_file_list_prefixed="$source_dir/root/.packages/builtin_files/$pkg_name"
- dest_file_list_prefixed="$dest_root/root/.packages/builtin_files/$pkg_name"
- local spec_list_name=${4:-"woof-installed-packages"}
- local file_spec_list_path="$dest_root/root/.packages/$spec_list_name"
- cp --remove-destination -arf $source_dir/* \
- $dest_root/ 2>/dev/null
- if [ ! -f "$source_file_list_prefixed" ]; then
- cd source_dir
- find . -mindepth 1 -name '*' > "$dest_file_list_prefixed"
- fi
- if [ ! -f "$source_dir/pet.specs" ]; then
- cd "source_dir"
- dir2pet "$pkg_name"
- fi
- #match_cnt=$( grep -cF "$spec" "$inst_pkg_specs_target" )
- #if [ $match_cnt -eq 0 ]; then
- # spec >> "$inst_pkg_specs_target"
- #fi
- if [ -f "source_dir/pet.specs" ]; then
- #All args here except the first are default
- delete_petspec_fm_file "$pkg_name" "$dest_root" "$spec_list_name" "1"
- cat "$source_dir/pet.specs" >> "$file_spec_list_path"
- fi
- }
- curdir=`pwd`
- rootfs="$s_rootfs"
- xinteractive=1S
- prefix=""
- unmount_vfs(){
- umount -l $curdir/$rootfs/dev 2>/dev/null
- umount -l $curdir/$rootfs/sys 2>/dev/null
- umount -l $curdir/$rootfs/proc 2>/dev/null
- #umount /mnt/wktaz 2>/dev/null
- #umount /mnt/wksfs 2>/dev/null
- }
- trap unmount_vfs EXIT
- trap unmount_vfs SIGKILL
- trap unmount_vfs SIGTERM
- xinteractive=1
- echo "PUPMODE='2'" > $curdir/$rootfs$prefix/etc/rc.d/PUPSTATE
- mkdir -p $curdir/$rootfs/proc;
- mkdir -p $curdir/$rootfs/sys
- mount -o rbind /proc $curdir/$rootfs/proc
- mount -t sysfs none $curdir/$rootfs/sys
- if [ $xinteractive -eq 1 ]; then
- echo "Removing block device files..."
- #rm -rf $curdir/$rootfs/dev/*
- #mount bind -t devtmpfs none $curdir/$rootfs/dev
- mount -o rbind /dev $curdir/$rootfs/dev
- cp -f /etc/resolv.conf $curdir/$rootfs/etc/resolv.conf
- fi
- copy_pet_specs(){
- AWK_PRG="BEGIN{FS=\"|\"}
- {
- if ( \$2 == \"$app\" ) {
- print
- }
- }"
- file_spec_list=( "$rootfs_full/root/.packages/"*"-installed-packages" )
- #cat "${file_spec_list[@]}" | awk -F'|' "$AWK_PRG" #'{print $2;}'
- spec=$( cat "${file_spec_list[@]}" | awk "$AWK_PRG" >> "$inst_pkg_specs_target" )
- match_cnt=$( grep -cF "$spec" "$inst_pkg_specs_target" )
- if [ $match_cnt -eq 0 ]; then
- spec >> "$inst_pkg_specs_target"
- fi
- }
- copy_built_in(){
- set -x
- app=$1
- file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
- if [ ! -f "$file_list" ] && [ $retry -eq 1 ]; then
- file_list="$alt_s_rootfs/root/.packages/builtin_files/$app"
- using_alt_list=1
- else
- using_alt_list=1=0
- fi
- if [ "${target:0:1}" = "/" ]; then
- target_root="$target"
- else
- target_root="$curdir/$target"
- fi
- target_file_list="$target_root/root/.packages/builtin_files/$app"
- echo "file_list=$file_list"
- mkdir -p /tmp/trim_puppy
- exec 10<> /tmp/trim_puppy/fd_10
- subdir="/"
- mkdir -p /tmp/trim_puppy/
- rm "/tmp/trim_puppy/$app"
- touch "/tmp/trim_puppy/$app"
- #mkdir -p
- inst_pkg_specs_target="$target_root/root/.packages/"$arr_name"-installed-packages"
- mkdir -p `dirname "$inst_pkg_specs_target"`
- copy_pet_specs
- while IFS=$'\n' read -r -d $'\n' -u10 line ; do
- line=`echo "$line" | tr -d '[:space:]'`
- if [ ! "${line:0:1}" = "/" ]; then
- line=$subdir$line
- fi
- echo $line>>"/tmp/trim_puppy/$app"
- if [ "${target:0:1}" = "/" ]; then
- target_prefixed="$target$line"
- #target_root="$target" #Defined above
- else
- #target_root="$curdir/$target" #Defined above
- target_prefixed="$curdir/$target$line"
- fi
- if [ "${s_rootfs:0:1}" = "/" ]; then
- source_prefixed="$s_rootfs$line"
- cd "$s_rootfs" #this is necessary for the cpio command below
- else
- source_prefixed="$curdir/$s_rootfs$line"
- cd "$curdir/$s_rootfs" #this is necessary for the cpio command below
- fi
- if [ -d "$source_prefixed" ]; then
- subdir="$line"
- echo ".$line" | cpio -pd "$target_root"
- subdir=${subdir%/}/
- else
- target_dir=`dirname $target_prefixed`
- if [ ! -d "$target_dir" ]; then
- source_dir=`dirname $line`
- echo ".$source_dir" | cpio -pd "$target_root"
- fi
- if [ ! -f "$source_prefixed" ] && [ $retry -eq 1 ]; then
- source_prefixed="$alt_s_rootfs$line"
- cp -a -u "$source_prefixed" "$target_prefixed"
- elif [ ! "$arr_action" = "mv" ]; then
- cp -a -u "$source_prefixed" "$target_prefixed"
- else
- mv -uf "$source_prefixed" "$target_prefixed"
- if [ -f "$source_prefixed" ]; then
- rm "$source_prefixed"
- fi
- fi
- fi
- done 10< <( cat "$file_list" )
- exec 10>&-
- set +x
- if [ ! "$arr_action" = "mv" ]; then
- mkdir -p `dirname "$target_file_list"`
- cp -a -u "$file_list" "$target_file_list"
- else
- mv -uf "$file_list" "$target_file_list"
- sed -i "\%|${app}|%d" "$curdir/$s_rootfs/root/.packages/"*"-installed-packages"
- if [ -f "$file_list" ]; then
- rm "$file_list"
- fi
- fi
- }
- for arr_name in "${ALL_ArrNames[@]}"; do
- eval "arr=( \"\${"$arr_name"[@]}\" )"
- arr_action=`$"$arr_name"_action`
- arr_action=${arr_action:-"$action"}
- #Move is faster but perhaps copy is safer
- arr_action=${arr_action:-cp}
- set -x
- eval 'target="$'$arr_name'_target"'
- target=${target:-"$curdir/$arr_name"}
- set +x
- if [ "${s_rootfs:0:1}" = "/" ]; then
- s_rootfs_prefixed="$s_rootfs"
- else
- s_rootfs_prefixed="$curdir/$s_rootfs"
- fi
- for app in "${arr[@]}"; do
- echo "arr_action=$arr_action"
- case "$arr_action" in
- cp|mv|retry)
- echo "app=$app"
- copy_built_in "$app"
- ;;
- #mv)
- # move_built_in()
- #;;
- #pet) #We might also want to convert to other package formats
- # mk_pet_fm_built_in()
- #;;
- esac
- if [ -f "/tmp/trim_puppy/$app" ] && [ $chroot_remove_builtin -eq 1 ]; then
- file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
- rm "$file_list"
- cp "/tmp/trim_puppy/$app" "$file_list"
- fi
- #chroot "$s_rootfs_prefixed" remove_builtin "$app"
- done
- done
- for pkg_dir in "${Post_Remove_Install_Fm_Dir[@]}"; do
- if [ "${pkg_dir:0:1}" = "." ]; then
- pkg_dir="$curdir/${pkg_dir:1:}"
- elif [ ! "${pkg_dir:0:1}" = "/" ]; then
- rel_path=${pkg_dir%/*}
- pkg_name=`basename pkg_dir`
- if [ -z "$rel_path" ]; then
- for pkg_arch in "${arches[@]}" "."; do
- for pkg_distro in "${post_rm_pkg_dirs[@]}" "."
- rel_path="$pkg_arch/$distro"
- a_pkg_dir="$curdir/post_patch/$pkg_arch/$pkg_distro/$pkg_name"
- if [ -d "a_pkg_dir" ] || [ -d `readlink "$a_pkg_dir"` ]; then
- pkg_dir="$a_pkg_dir"
- break 2;
- fi
- done
- done
- else
- pkg_dir="$curdir/post_patch/$arch/pupngo/$pkg_dir/$pkg_dir"
- fi
- fi
- inst_builtin_fm_dir "$pkg_dir"
- done
- if [ chroot_remove_builtin = 1 ];then
- chroot "$s_rootfs_prefixed" remove_builtin "${ALL[@]}"
- fi
- if [ "$(mount | grep "$curdir/$rootfs/dev")" != "" ]; then
- umount -l $curdir/$rootfs/dev
- fi
- if [ "$(mount | grep "$curdir/$rootfs/sys")" != "" ]; then
- umount -l $curdir/$rootfs/sys
- fi
- if [ "$(mount | grep "$curdir$rootfs/proc")" != "" ]; then
- umount -l $curdir/$rootfs/proc
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement