From 30c0d7cae8853e28dcf9b4c5aac053d56dfc39d5 Mon Sep 17 00:00:00 2001 From: BtbN Date: Sat, 15 Jan 2022 02:17:12 +0100 Subject: [PATCH] Parallelize repacking --- util/repack_latest.sh | 73 ++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/util/repack_latest.sh b/util/repack_latest.sh index cb0e686..df3c587 100755 --- a/util/repack_latest.sh +++ b/util/repack_latest.sh @@ -8,6 +8,7 @@ fi RELEASE_DIR="$(realpath "$1")" shift +mkdir -p "$RELEASE_DIR" rm -rf repack_dir mkdir repack_dir @@ -17,41 +18,55 @@ while [[ $# -gt 0 ]]; do INPUT="$1" shift - rm -rf repack_dir/* + ( + set -e + REPACK_DIR="repack_dir/$BASHPID" + rm -rf "$REPACK_DIR" + mkdir "$REPACK_DIR" - if [[ $INPUT == *.zip ]]; then - unzip "$INPUT" -d repack_dir - elif [[ $INPUT == *.tar.xz ]]; then - tar xvaf "$INPUT" -C repack_dir - else - echo "Unknown input file type: $INPUT" - exit 1 - fi + if [[ $INPUT == *.zip ]]; then + unzip "$INPUT" -d "$REPACK_DIR" + elif [[ $INPUT == *.tar.xz ]]; then + tar xvaf "$INPUT" -C "$REPACK_DIR" + else + echo "Unknown input file type: $INPUT" + exit 1 + fi - cd repack_dir + cd "$REPACK_DIR" - INAME="$(echo ffmpeg-*)" - TAGNAME="$(cut -d- -f2 <<<"$INAME")" + INAME="$(echo ffmpeg-*)" + TAGNAME="$(cut -d- -f2 <<<"$INAME")" - if [[ $TAGNAME == N ]]; then - TAGNAME="master" - elif [[ $TAGNAME == n* ]]; then - TAGNAME="$(sed -re 's/([0-9]+\.[0-9]+).*/\1/' <<<"$TAGNAME")" - fi + if [[ $TAGNAME == N ]]; then + TAGNAME="master" + elif [[ $TAGNAME == n* ]]; then + TAGNAME="$(sed -re 's/([0-9]+\.[0-9]+).*/\1/' <<<"$TAGNAME")" + fi - if [[ $INAME == *-*-*-*-*-* ]]; then - ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f5- <<<"$INAME")" - else - ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f3- <<<"$INAME")" - fi + if [[ "$INAME" =~ -[0-9]+-g ]]; then + ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f5- <<<"$INAME")" + else + ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f3- <<<"$INAME")" + fi - mv "$INAME" "$ONAME" + mv "$INAME" "$ONAME" - if [[ $INPUT == *.zip ]]; then - zip -9 -r "$RELEASE_DIR/$ONAME.zip" "$ONAME" - elif [[ $INPUT == *.tar.xz ]]; then - tar cvJf "$RELEASE_DIR/$ONAME.tar.xz" "$ONAME" - fi + if [[ $INPUT == *.zip ]]; then + zip -9 -r "$RELEASE_DIR/$ONAME.zip" "$ONAME" + elif [[ $INPUT == *.tar.xz ]]; then + tar cvJf "$RELEASE_DIR/$ONAME.tar.xz" "$ONAME" + fi - cd .. + rm -rf "$REPACK_DIR" + ) & + + while [[ $(jobs | wc -l) -gt 3 ]]; do + wait %1 + done done + +while [[ $(jobs | wc -l) -gt 0 ]]; do + wait %1 +done +rm -rf repack_dir