-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmake-zip.sh
More file actions
61 lines (50 loc) · 1.58 KB
/
make-zip.sh
File metadata and controls
61 lines (50 loc) · 1.58 KB
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
#!/usr/bin/env bash
# Create a zip file from wallpapers
if ! command -v zip &> /dev/null
then
echo "make-zip.sh: No zip program found."
exit 1
fi
WORK_DIR=$(dirname "$0")
OUTPUT_DIR=$WORK_DIR
ZIP_FILE=$OUTPUT_DIR/wallpapers.zip
MAX_KB=650
echo "make-zip.sh: WORK_DIR=$WORK_DIR"
echo "make-zip.sh: OUTPUT_DIR=$OUTPUT_DIR"
echo "make-zip.sh: ZIP_FILE=$ZIP_FILE"
echo "make-zip.sh: MAX_KB=$MAX_KB"
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p "$OUTPUT_DIR"
fi
if [ -f "$ZIP_FILE" ]; then
rm "$ZIP_FILE"
fi
# Find wallpapers and store them in an array
# NOTE: We use Bash array to handle filenames with spaces correctly.
mapfile -t WALLPAPERS_LIST < <(find "$WORK_DIR" -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.tif" -o -iname "*.gif" -o -iname "*.bmp" \) -print)
# File size check
for file in "${WALLPAPERS_LIST[@]}"; do
file_size=$(wc -c < "$file")
KB=$((file_size / 1024))
MB=$((KB / 1024))
if [ $KB -gt $MAX_KB ]; then
if [ $MB -gt 1 ]; then
echo "make-zip.sh: WARNING: $file : $MB MB > $MAX_KB KB"
else
echo "make-zip.sh: WARNING: $file : $KB KB > $MAX_KB KB"
fi
fi
done
cp -f "$WORK_DIR/README.md" /tmp/README.txt
zip -j -q "$ZIP_FILE" "${WALLPAPERS_LIST[@]}" /tmp/README.txt "$WORK_DIR/LICENSE.txt"
if [ "$?" -eq "0" ] && [ -f "$ZIP_FILE" ]; then
file_size=$(wc -c < "$ZIP_FILE")
KB=$((file_size / 1024))
MB=$((KB / 1024))
if [ $MB -gt 1 ]; then
echo "make-zip.sh: Generated $ZIP_FILE ($MB MB)"
else
echo "make-zip.sh: Generated $ZIP_FILE ($KB KB)"
fi
fi
rm /tmp/README.txt