-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate-scoop.sh
More file actions
43 lines (34 loc) · 869 Bytes
/
update-scoop.sh
File metadata and controls
43 lines (34 loc) · 869 Bytes
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
#!/bin/sh
set -eu
usage() {
echo "usage: $(basename $0) [-n] NEW_VERSION"
exit 1
}
SED_ARGS='-i'
BASE_URL='https://github.com/infrahq/infra/releases/download'
while getopts 'b:c:hn' OPTION; do
case $OPTION in
b) BASE_URL=$OPTARG ;;
n) SED_ARGS= ;;
*) usage ;;
esac
done
shift $(( $OPTIND - 1 ))
[ $# -eq 1 ] || usage
NEW_VERSION=$1
CHECKSUMS=$(mktemp)
cleanup() { rm $CHECKSUMS; }
trap cleanup 0
curl -o$CHECKSUMS -fsSL $BASE_URL/v$NEW_VERSION/infra-checksums.txt
PACKAGE=infra
PART=${NEW_VERSION##*-}
if [ "$PART" != "$NEW_VERSION" ]; then
PACKAGE=infra-$PART
fi
OLD_VERSION=$(jq -r .version <$PACKAGE.json)
EXPRS="s/$OLD_VERSION/$NEW_VERSION/g"
while read -r LINE; do
set -- $LINE
EXPRS="$EXPRS; /$2/{n;s/\"hash\": \".*\"/\"hash\": \"$1\"/;}"
done <$CHECKSUMS
echo $EXPRS | sed $SED_ARGS -f- $PACKAGE.json