-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathutils.sh
36 lines (32 loc) · 927 Bytes
/
utils.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
#! /bin/bash
## vim: noet:sw=0:sts=0:ts=4
# downloads a file and validates its checksum
SourcemodHelper::downloadFile () {
[[ $2 ]] || return
local cachefile="$SM_FILECACHE_DIR/$2"
[[ -r $cachefile ]] || {
local tmp=$(mktemp)
wget -O "$tmp" "$1" || return
local sha="$(sha256sum "$tmp")"
sha=${sha%% *}
[[ $sha == $2 ]] || {
error <<< "Mismatched checksum for file $1 (expected $2, got $sha)"
return 1
}
mv "$tmp" "$cachefile"
}
echo "$cachefile"
}
SourcemodHelper::unpackZip () {
local zipfile="$(SourcemodHelper::downloadFile "$@")"
[[ -r $zipfile ]] && unzip -q "$zipfile"
}
SourcemodHelper::unpackTar () {
local tarfile="$(SourcemodHelper::downloadFile "$@")"
[[ -r $tarfile ]] && tar xzf "$tarfile"
}
SourcemodHelper::downloadSmx () {
local smxname="${3-${1##*/}}"
local smxfile="$(SourcemodHelper::downloadFile "$@")"
[[ -r $smxfile ]] && cp "$smxfile" "$SM_TMP_PLUGIN_DIR/$smxname"
}