Guest User

mass-to-discs

a guest
Dec 4th, 2020
46
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. set -euo pipefail
  4. set -x
  5.  
  6. EXIT_FAILURE=1
  7. EXIT_SUCCESS=0
  8.  
  9. inputDir=mass
  10.  
  11. if [ ! -d "$inputDir" ]; then
  12.     echo "$inputDir/ not found"
  13.     exit $EXIT_FAILURE
  14. fi
  15.  
  16. array=()
  17. while IFS=  read -r -d $'\0'; do
  18.     array+=("$REPLY")
  19. done < <(find "$inputDir" -type f -print0 | sort -z)
  20. sz=${#array[@]}
  21. echo $sz
  22.  
  23. i=0
  24. discNo=1
  25. usedDiscSizeBytes=0
  26. discSizeBytes=24689770416
  27. discSizeBytes=4500000000
  28. for (( i=0; i<$sz; i++ )); do
  29.     originalPath="${array[$i]}"
  30.     filename=$(basename ${array[$i]})
  31.     fileSize=$(stat --printf="%s" "$originalPath")
  32.     echo $fileSize
  33.     usedDiscSizeBytes=$(expr $usedDiscSizeBytes + $fileSize)
  34.     echo $usedDiscSizeBytes
  35.     if [ $usedDiscSizeBytes -ge $discSizeBytes ]; then
  36.         usedDiscSizeBytes=0
  37.         discNo=$((discNo+1))
  38.     fi
  39.  
  40.     mkdir -p "disc$discNo"
  41.     cp -lv "$inputDir/$filename" "disc$discNo/$filename"
  42. done
  43.  
  44. exit $EXIT_SUCCESS
RAW Paste Data