Advertisement
s243a

mk_tarball.sh

Mar 16th, 2020
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.38 KB | None | 0 0
  1. #!/bin/bash
  2. IN_FILE="$(realpath ./woof-CE-out-replace.lst)"
  3. out_type=file
  4. case "$out_type" in
  5. directory)
  6.   OUT_FILE=arch32_tarball4woof_ce-20200314
  7.   mkdir -p "$OUT_FILE"
  8.   ;;
  9. *)
  10.   OUT_FILE=arch32_tarball4woof_ce-20200314.tar.gz
  11.   ;;
  12. esac
  13. CWD=$(realpath .)
  14. delete_old=yes
  15. OUT_FILE_PATH="$(realpath $OUT_FILE || echo "$OUT_FILE")"
  16. if [ "$delete_old" = yes ]; then
  17.   [ -f "$OUT_FILE_PATH" ] && rm "$OUT_FILE_PATH"
  18. else
  19.   [ -f "$OUT_FILE_PATH" ] && mv "$OUT_FILE_PATH" "$OUT_FILE_PATH_back$$"
  20. fi  
  21. case "$OUT_FILE_PATH" in
  22. *.gz)
  23.   PRE_OUT_FILE_PATH="${OUT_FILE_PATH%.gz}"
  24.   ;;
  25. esac
  26. if [ ! -z "PRE_OUT_FILE_PATH" ]; then
  27.     if [ "$delete_old" = yes ]; then
  28.       [ -f "$PRE_OUT_FILE_PATH" ] && rm "$PRE_OUT_FILE_PATH"
  29.     else
  30.       [ -f "$PRE_OUT_FILE_PATH" ] && mv "$PRE_OUT_FILE_PATH" "$PRE_OUT_FILE_PATH_back$$"
  31.     fi  
  32. fi
  33. function process_output(){
  34.   local exit_fn2=$1
  35.   #if [ "$exit_fn2" = no ]; then
  36.       while read -r a_file a_root rest; do
  37.         #read -r a_file a_root rest
  38.         cd "$CWD"
  39.         a_file="$(echo "$a_file" | sed -e 's%\(^['"'"']\|^["]\)%%' -e 's%\(['"'"']\|["]\)%%')"
  40.         [ -z "$a_root" ] && a_root=$CWD
  41.         a_root="$(echo "$a_root" | sed -e 's%\(^['"'"']\|^["]\)%%' -e 's%\(['"'"']\|["]\)%%')"
  42.         [ -z "$a_root" ] && a_root=$CWD    
  43.         #a_root="${aroot%/}/"
  44.         #[ "$a_file" = EOF ] && break
  45.         #[ -z "$a_file" ] && break
  46.         a_file2="${a_file%/*}"
  47.         a_file2="${a_file2%/}"     
  48.         [ ! -e "$a_file2" ] && cd "$CWD" && continue
  49.         if [ -e "$a_root/$a_file2" ] && [ ! -z "$a_file2" ]; then
  50.             cd $a_root
  51.             if [ -d "$OUT_FILE_PATH" ]; then
  52.               cd $a_root
  53.               find . -wholename "./$a_file2" | cpio -pdu "$OUT_FILE_PATH"
  54.             else
  55.               #a_file="${a_file%/*}"
  56.               #a_file="${a_file%/}"
  57.               a_root="${a_root%/}"
  58.               case "OUT_FILE_PATH" in
  59.               *)
  60.                  if [ -f "$PRE_OUT_FILE_PATH" ]; then            
  61.                    tar -r -f "$PRE_OUT_FILE_PATH" $a_file2
  62.                  else
  63.                    tar -cf "$PRE_OUT_FILE_PATH" $a_file2
  64.                  fi
  65.                  #find . -name "$a_file" | tar -czvf "$OUT_FILE_PATH"
  66.                 ;;
  67.               esac
  68.             fi
  69.         fi
  70.        
  71.       done 
  72.     #fi
  73.     #exit 0
  74. }
  75.  
  76. while read -r line; do
  77.   echo "$line '' '' ''"
  78. done <$IN_FILE | process_output "$exit_fn"
  79. case "$OUT_FILE_PATH" in
  80. *.gz)
  81.   #set +x
  82.   gzip -c "$PRE_OUT_FILE_PATH" > "$OUT_FILE_PATH" && rm "$PRE_OUT_FILE_PATH"
  83.   ;;
  84. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement