-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·64 lines (53 loc) · 1.58 KB
/
update.sh
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
62
63
#!/bin/sh
alias p='printf %s\\n'
fail() { p "$0: $1" >&2; exit 1; }
debug() { [ -n "$DEBUG" ] && p "debug: $1" >&2; }
# Dependencies:
# - curl
# - unzip
# TODO: better documentation
main() (
mkdir tmp && cd tmp ||
fail 'mkdir or cd tmp failed'
while IFS= read -r ln; do
# shellcheck disable=SC2086
update_ck $ln || exit
done < ../dependencies.txt
rmdir ../tmp
)
# update_ck <repo_name> <repo_url> <files...>
# downloads $repo_name as ZIP of master branch from $repo_url
# and compares downloaded $files with those in lib/$repo_name,
# listing all changed files.
update_ck() (
readonly repo_name="$1" repo_url="$2"; shift 2
readonly file_zip='repo.zip'
readonly zip_root="$repo_name-master"
debug "downloading from repo $repo_name from <$repo_url>"
curl -sSLo "$file_zip" -- "$repo_url" ||
fail 'failed to download repo'
debug 'unzipping downloaded archive'
# shellcheck disable=SC2046
# WARNING: `unzip` does not support `--`
unzip -oq "$file_zip" $(prepend "$zip_root/" "$@") ||
fail 'failed to extract files from downloaded repo'
debug 'comparing unzipped files with lib/, applying changes, and printing changed files'
for f do
cmp -s -- "../lib/$repo_name/$f" "$zip_root/$f" 2> /dev/null &&
continue
mkdir -p "$(dirname "../lib/$repo_name/$f")" &&
mv -f -- "$zip_root/$f" "../lib/$repo_name/$f" ||
fail 'mkdir or mv failed; idk why'
p "$repo_name/$f"
done
rm -r -- "$file_zip" "$zip_root"
)
# prepend <substr> <args...>
# prepends $substr to each argument in $args.
prepend() (
readonly substr="$1"; shift
for arg do
p "$substr$arg"
done
)
main || exit