-
Notifications
You must be signed in to change notification settings - Fork 1
/
downstream-helpers
executable file
·47 lines (38 loc) · 1.21 KB
/
downstream-helpers
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
#!/usr/bin/env bash
# shell-helpers downstreamer version v1
# https://github.com/briceburg/shell-helpers
# Copyright 2016-present Brice Burgess, Licensed under the Apache License 2.0
# * requires curl
#
# place in the directory containing shell-helpers library files and execute to
# fetch the latest release of all shell-helpers files.
#
# alternatively pass the path of directory containing shell-helpers files, e.g.
# ./downstream-helpers /path/to/shell-helper-files/
#
# an example at bottom demonstrates hardcoding the helpers path
#
main(){
readonly workdir="$1"
readonly CWD="$( cd $(dirname $0) ; pwd -P )"
local pattern="# @shell-helpers_UPDATE_URL="
local file
local match
local url
set -eo pipefail
exec >&2
cd "${workdir:-$CWD}"
for file in *; do
echo "tyring $workdir/$file"
match=$(grep -m1 "^$pattern" "$file" 2>/dev/null) || \
continue
url=${match//$pattern/}
echo " replacing $file with $url ..."
curl --silent -Lf $url > $file || \
echo " ! failed to download $url"
done
}
# :: example hardcoding of workdir [uncomment below lines]
# readonly SCRIPT_CWD=$( cd $(dirname "${BASH_SOURCE[0]}") ; pwd -P )
# main "$SCRIPT_CWD/common/lib.d/helpers"
main "$@"