Advertisement
s243a

mk-min-taz-functions.sh

Apr 1st, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.99 KB | None | 0 0
  1. unmount_vfs(){
  2.  umount -l $curdir/$rootfs/dev 2>/dev/null
  3.  umount -l $curdir/$rootfs/sys 2>/dev/null
  4.  umount -l $curdir/$rootfs/proc 2>/dev/null
  5.  #umount /mnt/wktaz 2>/dev/null
  6.  #umount /mnt/wksfs 2>/dev/null
  7.  close_file_descriptors
  8.  
  9. }  
  10. close_file_descriptors(){
  11.   exec 10>&-
  12. }
  13. delete_petspec_fm_file(){
  14.  
  15.   local field_val=$1
  16.   local pkg_rootfs=${2:-"$s_rootfs"}
  17.   local spec_list_name=${3:-"woof-installed-packages"}
  18.   local field=${4:-1} #The first field is the default  
  19.   #TODO if prk_rootfs="/" or "" give warning
  20.   AWK_PRG="BEGIN{FS=\"|\"}
  21.  {
  22.    if ( \$$field != \"$field_val\" ) {
  23.     print
  24.    }
  25.  }"
  26.   #TODO we probably need logic to expand wildards
  27.   local file_spec_list=( "$pkg_rootfs/root/.packages/$spec_list_name" )
  28.  
  29.   for spec_list in "${file_spec_list[@]}"; do
  30.     spec_name=`basename "$spec_list"`
  31.     cat "$spec_list" | awk "$AWK_PRG"  >> "/tmp/trim_puppy/$spec_name"
  32.     echo "about to"
  33.     echo "rm \"$spec_list\"
  34.    mv  \"/tmp/trim_puppy/$spec_name\" \"$spec_list\"
  35.    "
  36.     read -p "Press enter to continue"
  37.     set -x    
  38.     rm "$spec_list"
  39.     mv  "/tmp/trim_puppy/$spec_name" "$spec_list"
  40.     set +x    
  41.     read -p "Press enter to continue"
  42.   done
  43.  
  44. }
  45.  
  46. inst_builtin_fm_dir(){
  47.   local source_dir=$1
  48.   local dest_root=${2:-"$curdir/$s_rootfs"} #TODO make the default more robust with regards to slashes
  49.   if [ "$dest_root" = "/" ]; then
  50.      echo "warning about to install package into system rootfs"
  51.      read -p "Press enter to continue"
  52.   fi
  53.  
  54.   local pkg_name=${3:-`basename $1`} #TODO add logic for different location of files.list
  55.  
  56.   source_file_list_prefixed="$source_dir/root/.packages/builtin_files/$pkg_name"
  57.   dest_file_list_prefixed="$dest_root/root/.packages/builtin_files/$pkg_name"
  58.   local spec_list_name=${4:-"woof-installed-packages"}
  59.   local file_spec_list_path="$dest_root/root/.packages/$spec_list_name"
  60.   echo "about to:"
  61.   echo "  cp --remove-destination -arf $source_dir/*
  62.                                 $dest_root/ 2>/dev/null"
  63.   read -p "Press enter to continue"
  64.   cp --remove-destination -arf $source_dir/* \
  65.                                  $dest_root/ 2>/dev/null
  66.   if [ ! -f "$source_file_list_prefixed" ]; then
  67.      cd "$source_dir"
  68.      mkdir -p `dirname "$dest_file_list_prefixed"`
  69.      find . -mindepth 1 -name '*' > "$dest_file_list_prefixed"
  70.   fi
  71.  
  72. }
  73. update_pkg_specs(){
  74.   if [ ! -z "$1" ]; then
  75.     spec_types_arry_name=$1
  76.   else
  77.     spec_types_arry=( "pet" "tazpkg" )
  78.     spec_types_arry_name="spec_types_arry"
  79.   fi
  80.   for spec_type in $(eval 'echo "${'$spec_types_arry_name'[@]}"'); do
  81.       case "$spec_type" in
  82.       pet|.pet)
  83.         pet_specs_fm_dir
  84.         ;;
  85.       tazpkg)
  86.         tazpkg_specs_fm_dir
  87.         ;;
  88.       esac
  89.   done
  90. }
  91. pet_specs_fm_dir(){
  92.  
  93.   if [ ! -f "$source_dir/pet.specs" ]; then
  94.      cd "source_dir"
  95.      
  96.      
  97.      dir2pet "$pkg_name"
  98.   fi  
  99.  
  100.   #match_cnt=$( grep -cF "$spec" "$inst_pkg_specs_target" )
  101.   #if [ $match_cnt -eq 0 ]; then
  102.   #  spec >> "$inst_pkg_specs_target"
  103.   #fi
  104.   if [ -f "$source_dir/pet.specs" ]; then
  105.     #All args here except the first are default
  106.     echo "about to:"
  107.     echo "  delete_petspec_fm_file \"$pkg_name\" \"$dest_root\" \"$spec_list_name\" \"1\""
  108.     read -p "Press enter to continue"
  109.     delete_petspec_fm_file "$pkg_name" "$dest_root" "$spec_list_name" "1"
  110.     cat "$source_dir/pet.specs" >> "$file_spec_list_path"
  111.   fi
  112. }
  113. copy_pet_specs(){
  114.   AWK_PRG="BEGIN{FS=\"|\"}
  115.  {
  116.    if ( \$2 == \"$app\" ) {
  117.     print
  118.    }
  119.  }"
  120.   file_spec_list=( "$rootfs_full/root/.packages/"*"-installed-packages" )
  121.   #cat "${file_spec_list[@]}" | awk -F'|' "$AWK_PRG" #'{print $2;}'
  122.   spec=$( cat "${file_spec_list[@]}" | awk "$AWK_PRG"  >> "$inst_pkg_specs_target" )
  123.   match_cnt=$( grep -cF "$spec" "$inst_pkg_specs_target" )
  124.   if [ $match_cnt -eq 0 ]; then
  125.     spec >> "$inst_pkg_specs_target"
  126.   fi
  127. }
  128. copy_built_in(){
  129.   set -x
  130.   app=$1
  131.   file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
  132.   if [ ! -f "$file_list" ] && [ $retry -eq 1 ]; then
  133.     file_list="$alt_s_rootfs/root/.packages/builtin_files/$app"
  134.     using_alt_list=1
  135.   else
  136.     using_alt_list=1=0
  137.   fi
  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 [ ! -f "$source_prefixed" ] && [ $retry -eq 1 ]; then
  190.            source_prefixed="$alt_s_rootfs$line"
  191.            cp -a -u "$source_prefixed" "$target_prefixed"
  192.        elif [ ! "$arr_action" = "mv" ]; then
  193.          cp -a -u "$source_prefixed" "$target_prefixed"
  194.        else
  195.          mv -uf "$source_prefixed" "$target_prefixed"
  196.          if [ -f "$source_prefixed" ]; then
  197.            rm "$source_prefixed"
  198.          fi
  199.        fi
  200.     fi
  201.    
  202.   done 10< <( cat "$file_list" )
  203.   exec 10>&-
  204.   set +x
  205.   if [ ! "$arr_action" = "mv" ]; then
  206.     mkdir -p `dirname "$target_file_list"`
  207.     cp -a -u "$file_list" "$target_file_list"
  208.   else
  209.     mv -uf "$file_list" "$target_file_list"
  210.     sed -i "\%|${app}|%d" "$curdir/$s_rootfs/root/.packages/"*"-installed-packages"
  211.     if [ -f "$file_list" ]; then
  212.       rm "$file_list"
  213.     fi
  214.   fi
  215. }
  216. dissect_rootfs(){
  217.   #arr_names=${1:-ALL_ArrNames}
  218.   arry_names_name=${1:-ALL_ArrNames}
  219.   for arr_name in $(eval 'echo "${'$arry_names_name'[@]}"'); do
  220.     eval "arr=( \"\${"$arr_name"[@]}\" )"
  221.     eval "arr_action=\$"$arr_name"_action"
  222.     arr_action=${arr_action:-"$action"}
  223.     #Move is faster but perhaps copy is safer
  224.     arr_action=${arr_action:-cp}
  225.     set -x
  226.     eval 'target="$'$arr_name'_target"'
  227.     target=${target:-"$curdir/$arr_name"}
  228.     set +x
  229.     if [ "${s_rootfs:0:1}" = "/" ]; then
  230.       s_rootfs_prefixed="$s_rootfs"    
  231.     else
  232.       s_rootfs_prefixed="$curdir/$s_rootfs"    
  233.     fi  
  234.     for app in "${arr[@]}"; do
  235.       echo "arr_action=$arr_action"
  236.       case "$arr_action" in
  237.       cp|mv|retry)  
  238.           echo "app=$app"
  239.           copy_built_in "$app"        
  240.           ;;
  241.       #mv)
  242.       #    move_built_in()
  243.       #;;
  244.       #pet) #We might also want to convert to other package formats
  245.       #    mk_pet_fm_built_in()
  246.       #;;
  247.       esac
  248.       if [ -f "/tmp/trim_puppy/$app" ] && [ $chroot_remove_builtin -eq 1 ]; then
  249.         file_list="$curdir/$s_rootfs/root/.packages/builtin_files/$app"
  250.         rm "$file_list"
  251.         cp "/tmp/trim_puppy/$app" "$file_list"
  252.       fi
  253.       #chroot "$s_rootfs_prefixed" remove_builtin "$app"
  254.     done
  255.   done
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement