1 |
9015
|
aaronmk
|
#!/bin/bash -e
|
2 |
|
|
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
|
3 |
|
|
|
4 |
|
|
if self_not_included; then
|
5 |
|
|
|
6 |
|
|
### zip
|
7 |
|
|
|
8 |
9074
|
aaronmk
|
zip()
|
9 |
9015
|
aaronmk
|
{
|
10 |
9215
|
aaronmk
|
echo_func
|
11 |
9537
|
aaronmk
|
cmd_log_fd=1 try self "$@" || ignore 12 #"zip has nothing to do" (`man zip`)
|
12 |
9015
|
aaronmk
|
}
|
13 |
|
|
|
14 |
12986
|
aaronmk
|
unzip()
|
15 |
|
|
{
|
16 |
|
|
echo_func
|
17 |
|
|
local piping="$(test "$1" = -p; exit2bool)"
|
18 |
|
|
|
19 |
|
|
cmd_log_fd="$(if test ! "$piping"; then echo 1; fi)" try self "$@"
|
20 |
|
|
# cmd_log_fd: don't filter stdout if piping extracted data to it
|
21 |
|
|
if test "$piping"; then ignore_e 1; fi # unzip exits 1 on SIGPIPE
|
22 |
|
|
end_try
|
23 |
|
|
}
|
24 |
9015
|
aaronmk
|
|
25 |
9249
|
aaronmk
|
zip_newer() { echo_func; set_inv force; zip ${no_force:+-u }"$@"; }
|
26 |
|
|
unzip_newer() { echo_func; set_inv force; unzip ${no_force:+-u }-o "$@"; }
|
27 |
9015
|
aaronmk
|
# -o is safe because -u only extracts newer files
|
28 |
|
|
|
29 |
14533
|
aaronmk
|
|
30 |
|
|
### compression of individual files
|
31 |
|
|
|
32 |
|
|
compress()
|
33 |
|
|
{
|
34 |
|
|
begin_target; : "${full_file:?}"; local zip_file="$full_file.zip"
|
35 |
|
|
stdout="$zip_file" to_file compress__zip_and_test
|
36 |
|
|
}
|
37 |
|
|
compress__zip_and_test()
|
38 |
|
|
{
|
39 |
|
|
zip -9 <"$full_file"
|
40 |
|
|
unzip -t "$zip_file" # only if newly created
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
expand()
|
44 |
|
|
{
|
45 |
|
|
begin_target; : "${full_file:?}"; local zip_file="$full_file.zip"
|
46 |
|
|
stdout="$full_file" to_file unzip <"$zip_file"
|
47 |
|
|
}
|
48 |
|
|
|
49 |
9015
|
aaronmk
|
fi
|