-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip_pdx
executable file
·54 lines (49 loc) · 960 Bytes
/
zip_pdx
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
#!/bin/bash
function show_help() {
echo "Usage: zip_pdx <dir> [-s]"
echo "Zips every pdx in a directory"
echo "Options:"
echo " -s Single fire at target dir"
echo " -h Display this help message"
}
function singlefire() {
local item="$1"
if [ -d "$item" ] && [ -f "$item/pdxinfo" ]; then #
zipname="${item}.zip"
if [ ! -f "$zipname" ]; then
zip -r "$zipname" "$item" >&2 #
else
echo "$zipname already exists" >&2
exit 1
fi
else
echo "$item: pdxinfo not found" >&2
exit 1
fi
}
function zip_dir() {
local dir_to_loop="$1"
for item in "$dir_to_loop"/*; do
if [ -d "$item" ] && [ -f "$item/pdxinfo" ]; then
zipname="${item}.zip"
if [ ! -f "$zipname" ]; then
zip -r "$zipname" "$item"
fi
fi
done
}
if [ "$#" -lt 1 ]; then
show_help
exit 1
fi
case "$2" in
-s)
singlefire "$1"
;;
-h)
show_help
;;
*)
zip_dir "$1"
;;
esac