repack_latest.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. set -e
  3. if [[ $# -lt 2 ]]; then
  4. echo "Missing arguments"
  5. exit -1
  6. fi
  7. RELEASE_DIR="$(realpath "$1")"
  8. shift
  9. mkdir -p "$RELEASE_DIR"
  10. rm -rf repack_dir
  11. mkdir repack_dir
  12. trap "rm -rf repack_dir" EXIT
  13. while [[ $# -gt 0 ]]; do
  14. INPUT="$1"
  15. shift
  16. (
  17. set -e
  18. REPACK_DIR="repack_dir/$BASHPID"
  19. rm -rf "$REPACK_DIR"
  20. mkdir "$REPACK_DIR"
  21. if [[ $INPUT == *.zip ]]; then
  22. unzip "$INPUT" -d "$REPACK_DIR"
  23. elif [[ $INPUT == *.tar.xz ]]; then
  24. tar xvaf "$INPUT" -C "$REPACK_DIR"
  25. else
  26. echo "Unknown input file type: $INPUT"
  27. exit 1
  28. fi
  29. cd "$REPACK_DIR"
  30. INAME="$(echo ffmpeg-*)"
  31. TAGNAME="$(cut -d- -f2 <<<"$INAME")"
  32. if [[ $TAGNAME == N ]]; then
  33. TAGNAME="master"
  34. elif [[ $TAGNAME == n* ]]; then
  35. TAGNAME="$(sed -re 's/([0-9]+\.[0-9]+).*/\1/' <<<"$TAGNAME")"
  36. fi
  37. if [[ "$INAME" =~ -[0-9]+-g ]]; then
  38. ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f5- <<<"$INAME")"
  39. else
  40. ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f3- <<<"$INAME")"
  41. fi
  42. mv "$INAME" "$ONAME"
  43. if [[ $INPUT == *.zip ]]; then
  44. zip -9 -r "$RELEASE_DIR/$ONAME.zip" "$ONAME"
  45. elif [[ $INPUT == *.tar.xz ]]; then
  46. tar cvJf "$RELEASE_DIR/$ONAME.tar.xz" "$ONAME"
  47. fi
  48. rm -rf "$REPACK_DIR"
  49. ) &
  50. while [[ $(jobs | wc -l) -gt 3 ]]; do
  51. wait %1
  52. done
  53. done
  54. while [[ $(jobs | wc -l) -gt 0 ]]; do
  55. wait %1
  56. done
  57. rm -rf repack_dir