-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path8mb
executable file
·41 lines (36 loc) · 822 Bytes
/
8mb
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
#!/bin/bash
set -eo pipefail
size=10
tolerance=5
usage() {
echo "Usage: $0 -f <file> [-s <size>] [-t <tolerance>]"
echo " -f <file> File to compress"
echo " -s <size> Target size in MB (default: 10)"
echo " -t <tolerance> Tolerance in % (default: 5)"
echo " -h Display this help message"
}
# parse args
while getopts h:f:s:t: flag
do
case "${flag}" in
f) file=${OPTARG};;
s) size=${OPTARG};;
t) tolerance=${OPTARG};;
h) usage
exit 0;;
*) usage
exit 1;;
esac
done
if [ -z "$file" ]; then
usage
exit 1
fi
docker run \
--rm \
--user "$(id -u):$(id -g)" \
-v "$(dirname "$file"):/data" \
matthewbaggett/8mb \
-f "/data/$(basename "$file")" \
--size "$size" \
--tolerance "$tolerance"