Parallelize repacking

This commit is contained in:
BtbN 2022-01-15 02:17:12 +01:00
parent bf95872731
commit 30c0d7cae8

View file

@ -8,6 +8,7 @@ fi
RELEASE_DIR="$(realpath "$1")" RELEASE_DIR="$(realpath "$1")"
shift shift
mkdir -p "$RELEASE_DIR"
rm -rf repack_dir rm -rf repack_dir
mkdir repack_dir mkdir repack_dir
@ -17,41 +18,55 @@ while [[ $# -gt 0 ]]; do
INPUT="$1" INPUT="$1"
shift shift
rm -rf repack_dir/* (
set -e
REPACK_DIR="repack_dir/$BASHPID"
rm -rf "$REPACK_DIR"
mkdir "$REPACK_DIR"
if [[ $INPUT == *.zip ]]; then if [[ $INPUT == *.zip ]]; then
unzip "$INPUT" -d repack_dir unzip "$INPUT" -d "$REPACK_DIR"
elif [[ $INPUT == *.tar.xz ]]; then elif [[ $INPUT == *.tar.xz ]]; then
tar xvaf "$INPUT" -C repack_dir tar xvaf "$INPUT" -C "$REPACK_DIR"
else else
echo "Unknown input file type: $INPUT" echo "Unknown input file type: $INPUT"
exit 1 exit 1
fi fi
cd repack_dir cd "$REPACK_DIR"
INAME="$(echo ffmpeg-*)" INAME="$(echo ffmpeg-*)"
TAGNAME="$(cut -d- -f2 <<<"$INAME")" TAGNAME="$(cut -d- -f2 <<<"$INAME")"
if [[ $TAGNAME == N ]]; then if [[ $TAGNAME == N ]]; then
TAGNAME="master" TAGNAME="master"
elif [[ $TAGNAME == n* ]]; then elif [[ $TAGNAME == n* ]]; then
TAGNAME="$(sed -re 's/([0-9]+\.[0-9]+).*/\1/' <<<"$TAGNAME")" TAGNAME="$(sed -re 's/([0-9]+\.[0-9]+).*/\1/' <<<"$TAGNAME")"
fi fi
if [[ $INAME == *-*-*-*-*-* ]]; then if [[ "$INAME" =~ -[0-9]+-g ]]; then
ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f5- <<<"$INAME")" ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f5- <<<"$INAME")"
else else
ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f3- <<<"$INAME")" ONAME="ffmpeg-$TAGNAME-latest-$(cut -d- -f3- <<<"$INAME")"
fi fi
mv "$INAME" "$ONAME" mv "$INAME" "$ONAME"
if [[ $INPUT == *.zip ]]; then if [[ $INPUT == *.zip ]]; then
zip -9 -r "$RELEASE_DIR/$ONAME.zip" "$ONAME" zip -9 -r "$RELEASE_DIR/$ONAME.zip" "$ONAME"
elif [[ $INPUT == *.tar.xz ]]; then elif [[ $INPUT == *.tar.xz ]]; then
tar cvJf "$RELEASE_DIR/$ONAME.tar.xz" "$ONAME" tar cvJf "$RELEASE_DIR/$ONAME.tar.xz" "$ONAME"
fi fi
cd .. rm -rf "$REPACK_DIR"
) &
while [[ $(jobs | wc -l) -gt 3 ]]; do
wait %1
done
done done
while [[ $(jobs | wc -l) -gt 0 ]]; do
wait %1
done
rm -rf repack_dir