-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.sh
42 lines (36 loc) · 810 Bytes
/
util.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
#!/bin/bash
HERE=$(cd $(dirname $0) && pwd)
cd "$HERE"
function checksum() {
sha256sum -c "$1"
}
function download() {
builtin local url="$1" sumfile="$2" file="$3"
if ! checksum "$sumfile" &>/dev/null; then
wget "$url" -O "$file"
fi
if ! checksum "$sumfile"; then
echo "Fail to download $file!"
exit 1
fi
}
function download_ex() {
builtin local action="$1" sumfile="$2"
if ! checksum "$sumfile" &>/dev/null; then
builtin eval "$action"
fi
if ! checksum "$sumfile"; then
echo "Fail to satisfy $sumfile!"
exit 1
fi
}
function dryrunable() {
if [ -z $DRYRUN ]; then
builtin eval "$@"
fi
}
function available() {
builtin local TRASH
TRASH=$(builtin command -v "$1")
builtin return $?
}