Skip to content

Commit 84c4fb4

Browse files
authored
[WALLPAPERS] Simplify make-zip.sh logic (#11)
- Make make-zip.sh current directory free. - Use Bash array to handle filenames that contain spaces. - Simplify logic.
1 parent fc96018 commit 84c4fb4

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
output/
1+
wallpapers.zip

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ If any changes are made to the `wallpapers` repository, then the wallpaper manag
4141
1. Hold a poll or create a pull request before making any significant changes to the `wallpapers` repository.
4242
2. Update the `wallpapers` repository.
4343
3. Run `./make-zip.sh` on the latest `wallpapers` local repository.
44-
4. The file `output/wallpapers.zip` will be generated.
44+
4. The file `wallpapers.zip` will be generated.
4545
5. Release the new `wallpapers.zip` on the `reactos/wallpapers` `Releases` page ( https://github.com/reactos/wallpapers/releases ) with a new version tag (`v???`).
4646
6. Update the data file `roswallp.txt` on `reactos/rapps-db` by comparing it with this repository's [`roswallp-sample.txt`](roswallp-sample.txt) (See `TODO:` parts).

make-zip.sh

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,50 @@ then
77
exit 1
88
fi
99

10-
OLD_DIR=`pwd`
11-
NEW_DIR=$(dirname "$0")
12-
echo "make-zip.sh: NEW_DIR=$NEW_DIR"
13-
14-
cd "$NEW_DIR"
15-
16-
OUTPUT_DIR=$NEW_DIR/output
10+
WORK_DIR=$(dirname "$0")
11+
OUTPUT_DIR=$WORK_DIR
1712
ZIP_FILE=$OUTPUT_DIR/wallpapers.zip
13+
MAX_KB=800
14+
15+
echo "make-zip.sh: WORK_DIR=$WORK_DIR"
1816
echo "make-zip.sh: OUTPUT_DIR=$OUTPUT_DIR"
1917
echo "make-zip.sh: ZIP_FILE=$ZIP_FILE"
18+
echo "make-zip.sh: MAX_KB=$MAX_KB"
2019

2120
if [ ! -d "$OUTPUT_DIR" ]; then
22-
mkdir "$OUTPUT_DIR"
21+
mkdir -p "$OUTPUT_DIR"
2322
fi
2423

2524
if [ -f "$ZIP_FILE" ]; then
2625
rm "$ZIP_FILE"
2726
fi
2827

29-
WALLPAPERS_LIST=`ls **{,/**}/*.{jpg,png,tif,gif,bmp} 2> /dev/null`
28+
# Find wallpapers and store them in an array
29+
# NOTE: We use Bash array to handle filenames with spaces correctly.
30+
mapfile -t WALLPAPERS_LIST < <(find "$WORK_DIR" -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.tif" -o -iname "*.gif" -o -iname "*.bmp" \) -print)
3031

3132
# File size check
32-
for file in $WALLPAPERS_LIST; do
33-
file_size=`wc -c "$file" | cut -d' ' -f1`
34-
let KB="$file_size / 1024"
35-
if [ $KB -gt 800 ]; then
36-
let MB="$KB / 1024"
33+
for file in "${WALLPAPERS_LIST[@]}"; do
34+
file_size=$(wc -c < "$file")
35+
KB=$((file_size / 1024))
36+
MB=$((KB / 1024))
37+
if [ $KB -gt $MAX_KB ]; then
3738
if [ $MB -gt 1 ]; then
38-
echo "make-zip.sh: WARNING: $file : $MB MB"
39+
echo "make-zip.sh: WARNING: $file : $MB MB > $MAX_KB KB"
3940
else
40-
echo "make-zip.sh: WARNING: $file : $KB KB"
41+
echo "make-zip.sh: WARNING: $file : $KB KB > $MAX_KB KB"
4142
fi
4243
fi
4344
done
4445

45-
cp -f README.md /tmp/README.txt
46+
cp -f "$WORK_DIR/README.md" /tmp/README.txt
4647

47-
zip -j -q "$ZIP_FILE" $WALLPAPERS_LIST /tmp/README.txt LICENSE.txt
48+
zip -j -q "$ZIP_FILE" "${WALLPAPERS_LIST[@]}" /tmp/README.txt "$WORK_DIR/LICENSE.txt"
4849

4950
if [ "$?" -eq "0" ] && [ -f "$ZIP_FILE" ]; then
50-
file_size=`wc -c "$ZIP_FILE" | cut -d' ' -f1`
51-
let KB="$file_size / 1024"
52-
let MB="$KB / 1024"
51+
file_size=$(wc -c < "$ZIP_FILE")
52+
KB=$((file_size / 1024))
53+
MB=$((KB / 1024))
5354
if [ $MB -gt 1 ]; then
5455
echo "make-zip.sh: Generated $ZIP_FILE ($MB MB)"
5556
else
@@ -58,5 +59,3 @@ if [ "$?" -eq "0" ] && [ -f "$ZIP_FILE" ]; then
5859
fi
5960

6061
rm /tmp/README.txt
61-
62-
cd "$OLD_DIR"

0 commit comments

Comments
 (0)