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 close_file_descriptors } close_file_descriptors(){ exec 10>&- } process_pet_specs(){ local specs_txt=`cat "$1" | head --lines=1` #https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash #http://www.linuxquestions.org/questions/programming-9/bash-shell-script-split-array-383848/#post3270796 specs=(${specs_txt//|/ }) process_pet_specs_FULL_NAME=specs[0] process_pet_specs_PKG_NAME=[1] process_pet_specs_VERSION=specs[2] process_pet_CATEGORY=specs[4] process_pet_SIZE=specs[5] process_pet_BRANCH=specs[6] #Repository Folder process_pet_FILE_NAME=specs[7] #File Namer process_pet_FILE_DEPENDS=specs[8] process_pet_FILE_SHORT_DESC=specs[9] process_pet_FILE_COMPILED WITHIN=specs[10] process_pet_FILE_COMPAT_DISTRO_VER=specs[11] process_pet_REPO_NAME=specs[12] } mk_tazpkg_receipt(){ parse_pkg_dirname "$1" local pkg_path="$path__ppd" local pkg_name="$pkg_name__ppd" local pkg_short_name="$pkg_short_ppd" local pkg_version="$pkg_version__ppd" if [ -f "$pkg_path/receipt" ]; then process_pet_specs echo 'PACKAGE="$process_pet_specs_PKG_NAME" VERSION="$process_pet_specs_VERSION" CATEGORY="$process_pet_CATEGORY" SHORT_DESC="$process_pet_SHORT_DESC" WEB_SITE="$web_site" MAINTAINER="$maintainer" DEPENDS="$process_pet_FILE_DEPENDS" ' > $pkg_path/receipt #TODO add che for pkgmanager type and suport for toher package managers fi } delete_petspec_fm_file(){ local field_val=$1 local pkg_rootfs=${2:-"$s_rootfs"} local spec_list_name=${3:-'*-packages'} if [ -z "$4" ]; then if [[ $field_val == *"-"* ]]; then local field=1 else local field=2 fi else local field="$4" fi #TODO if prk_rootfs="/" or "" give warning #TODO Give the option to compare more than one field. #https://www.gnu.org/software/gawk/manual/html_node/Boolean-Ops.html #TODO consider how to deal with miskes like dashes when there should be AWK_PRG="BEGIN{FS=\"|\"} { if ( \$$field != \"$field_val\" ) { print } }" #TODO we probably need logic to expand wildards local file_spec_lists=( `ls -1 "$pkg_rootfs/root/.packages/$spec_list_name"` ) 2>/dev/null mkdir -p /tmp/trim_puppy/ for spec_list in "${file_spec_lists[@]}"; do spec_name=`basename "$spec_list"` cat "$spec_list" | awk "$AWK_PRG" >> "/tmp/trim_puppy/$spec_name" echo "about to" echo "rm \"$spec_list\" mv \"/tmp/trim_puppy/$spec_name\" \"$spec_list\" " #read -p "Press enter to continue" set -x rm "$spec_list" mv "/tmp/trim_puppy/$spec_name" "$spec_list" set +x #read -p "Press enter to continue" done } parse_pkg_dirname(){ path__ppd=$1 pkg_name__ppd=${pkg_name%.extracted} pkg_name__ppd=${pkg_name%.tazpkg} pkg_name__ppd=${pkg_name%.pet} pkg_name__ppd=${pkg_name%.txz} pkg_short_name__ppd=${pkg_name%%-*} pkg_version__ppd=${pkg_name#*-} } inst_pkg_fm_anywhere(){ set -x parse_pkg_dirname $1 local source_dir="$path__ppd" local pkg_name="$pkg_name__ppd" local pkg_short_name="$pkg_short_name__ppd" local dest_root=${2:-"$curdir/$s_rootfs"} #TODO make the default more robust with regards to slashes if [ "$dest_root" = "/" ]; then echo "warning about to install package into system rootfs" #read -p "Press enter to continue" fi local pkg_name=${3:-`basename $1`} #TODO add logic for different location of files.list pkg_name=${pkg_name%%.*} if [ -d "$source_dir/fs" ]; then source_dir_fs="$source_dir/fs" else source_dir_fs="$source_dir" fi system_root_check_and_warn \ $source_dir_fs -m="source_dir_fs=$source_dir_fs" \ $dest_root -m="dest_root=$dest_root" set +x echo " cp --remove-destination -arf $source_dir_fs/* $dest_root/ 2>/dev/null" #read -p "Press enter to continue" cp --remove-destination -arf $source_dir_fs/* \ $dest_root/ 2>/dev/null cd "$source_dir" find . -mindepth 1 -name '*' > "$source_dir/$pkg_name" #"$dest_file_list_prefixed" update_pkg_specs "$source_dir" "$dest_root" } update_pkg_specs(){ parse_pkg_dirname "$1" local source_dir="$path__ppd" local pkg_name="$pkg_name__ppd" local pkg_short_name="$pkg_short_name__ppd" local pkg_version="$pkg_version__ppd" local dest_root=${2:-"$curdir/$s_rootfs"} #TODO make the default more robust with regards to slashes if [ ! -z "$3" ]; then spec_types_arry_name=$3 else spec_types_arry=( "pet" "tazpkg" ) spec_types_arry_name="spec_types_arry" fi mkdir -p "$dest_root/root/.packages/builtin_files" mkdir -p "$dest_root/var/lib/tazpkg/installed/$pkg_short_name" for spec_type in $(eval 'echo "${'$spec_types_arry_name'[@]}"'); do case "$spec_type" in pet|.pet) pet_specs_fm_dir "$source_dir" "$dest_root"/ cp "$source_dir/pet.specs" \ "$dest_root/root/.packages/builtin_files/$pkg_short_name" ;; tazpkg) tazpkg_specs_fm_dir "$source_dir" cp "$source_dir/$pkg_name" "$dest_root/var/lib/tazpkg/installed/$pkg_short_name/files.list" ;; esac done } system_root_check_and_warn(){ args=() #let count=0 let arg_count=0 for arg in "$@"; do if [[ "$arg" = "-m="* ]]; then message=${arg#-m=} args[-1]="$message" else args+=( "$arg" "arg$arg_count=$arg" ) fi #let count++ let arg_count++ done while read a b; do if [ "$a" = "/" ]; then echo "Warning! Action may involve system root:" echo "$b" read -p "Press enter to continue" fi done < <( "${args[@]}" ) } tazpkg_specs_fm_dir(){ parse_pkg_dirname "$1" local pkg_path="$path__ppd" local pkg_name="$pkg_name__ppd" local pkg_short_name="$pkg_short_name__ppd" local pkg_version="$pkg_version__ppd" local receipt_target_root=${2:-"$curdir/$s_rootfs"} if [ ! "$pkg_path/receipt" ]; then mk_tazpkg_receipt $pkg_path fi #https://unix.stackexchange.com/questions/266627/bash-source-without-polluting-own-namespace-get-variables-from-other-scripts/477443 set +x eval $(source "$pkg_path/recepit" &> /dev/null; echo pkg_short_name=${PACKAGE:-"$pkg_short_name"}; echo pkg_version=${VERSION:-"$pkg_version"};) set -x local pkg_name2="$pkg_short_name" if [ ! -z "$receipt_target_root" ]; then if [ "$receipt_target_root" = "/" ]; then echo "Warning: installing package receipt to system rootfs" #read -p "Press enter to continue" fi receipt_target=$receipt_target_root/var/lib/tazpkg/installed/$pkg_name2/receipt mkdir -p `dirname "$receipt_target"` system_root_check_and_warn \ $pkg_path -m="pkg_path/receipt=$pkg_path/receipt" \ $receipt_target_root -m="receipt_target=$receipt_target" cp -f "$pkg_path/receipt" "$receipt_target" fi set +x } pet_specs_fm_dir(){ set -x parse_pkg_dirname "$1" local source_dir="$path__ppd" local pkg_name="$pkg_name__ppd" local pkg_short_name="$pkg_short_name__ppd" local pkg_version="$pkg_version__ppd" local receipt_target_root=${2:-"$curdir/$s_rootfs"} #if [ -z "$3" ]; then # local target_pet_spec_path="$file_spec_list_path" #else # local installer=${3:-woof} # local target_pet_spec_path="$receipt_target_root/root/.packages/$installer"'-installed-packages' #fi local installer=${3:-woof} local target_pet_spec_path="$receipt_target_root/root/.packages/$installer"'-installed-packages' if [ ! -f "$source_dir/pet.specs" ]; then cd "$source_dir/.." old_name=`basename "$source_dir"` if [ -f "$source_dir/receipt" ]; then eval $(source "$source_dir/receipt" &> /dev/null; echo pkg_short_name=${PACKAGE:-"$pkg_short_name"}; echo pkg_version=${VERSION:-"$pkg_version"}; echo pkg_category=$CATEGORY; echo pkg_depends=$DEPENDS;) mv "$old_name" "$pkg_short_name"-"$pkg_version" dir2pet -g -s -p="$pkg_name" -c="$pkg_category" #-d="$pkg_depends" TODO Need to fix the format of depends option mv "$pkg_short_name"-"$pkg_version" "$old_name" else mv "$old_name" "$pkg_name" dir2pet -g -s -p="$pkg_name" mv "$pkg_name" "$old_name" fi fi set +x if [ -f "$source_dir/pet.specs" ]; then #&& [ -d "$receipt_target_root/var" ]; then if [ -f "$target_pet_spec_path" ]; then echo "TODO: maybe we need a forced option if the package exists" #TODO maybe remove old package before deleting. delete_petspec_fm_file "$pkg_name" "$dest_root" "$spec_list_name" #"1" We don't need to specify the field else mkdir -p "$receipt_target_root/root/.packages" touch "$target_pet_spec_path" fi cat "$source_dir/pet.specs" >> "$target_pet_spec_path" fi } copy_pet_specs(){ local spec_target=$1 if [ -z "$spec_target" ]; then spec_target="$inst_pkg_specs_target" fi 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" >> "$spec_target" ) match_cnt=$( grep -cF "$spec" "$spec_target" ) if [ $match_cnt -eq 0 ]; then echo "$spec" >> "$spec_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=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 } dissect_rootfs(){ #arr_names=${1:-ALL_ArrNames} arry_names_name=${1:-ALL_ArrNames} for arr_name in $(eval 'echo "${'$arry_names_name'[@]}"'); do eval "arr=( \"\${"$arr_name"[@]}\" )" eval "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 }