forked from BtbN/FFmpeg-Builds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepack_latest.sh
executable file
·72 lines (57 loc) · 1.55 KB
/
repack_latest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -e
if [[ $# -lt 2 ]]; then
echo "Missing arguments"
exit -1
fi
RELEASE_DIR="$(realpath "$1")"
shift
mkdir -p "$RELEASE_DIR"
rm -rf repack_dir
mkdir repack_dir
trap "rm -rf repack_dir" EXIT
while [[ $# -gt 0 ]]; do
INPUT="$1"
shift
(
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
cd "$REPACK_DIR"
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 [[ "$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"
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
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