-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi-smusher.sh
executable file
·64 lines (56 loc) · 1.58 KB
/
openapi-smusher.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
64
#!/usr/bin/env bash
set -e
while [ $# -gt 0 ]; do
case "$1" in
--spec*|-s*)
if [[ "$1" != *=* ]]; then shift; fi
SPEC="${1#*=}"
;;
--output*|-o*)
if [[ "$1" != *=* ]]; then shift; fi
OUTPUT="${1#*=}"
;;
*)
>&2 printf "Error: Invalid argument\n"
exit 1
;;
esac
shift
done
if ! command -v jq &> /dev/null
then
echo -e "\033[31m'jq' could not be found. It is a requirement."
exit 1
fi
jq --arg spec "$SPEC" --arg output "$OUTPUT" '."input-file"= $spec | ."output-file"= $output' \
smusher-config.json > tmp-smusher-config.json && mv tmp-smusher-config.json smusher-config.json
RELEASE_BINARY_SUFFIX="_darwin_arm64.tar.gz"
ARCH="$(uname -m)"
if [[ "$OSTYPE" == "linux-gnu"* ]]
then
if [[ "$ARCH" == "arm64" ]]
then
RELEASE_BINARY_SUFFIX="_linux_arm64.tar.gz"
else
RELEASE_BINARY_SUFFIX="_linux_amd64.tar.gz"
fi
elif [[ "$OSTYPE" == "darwin"* ]]
then
if [[ "$ARCH" == "x86_64" ]]
then
RELEASE_BINARY_SUFFIX="_darwin_amd64.tar.gz"
fi
fi
if [[ -z "${GH_TOKEN}" ]]
then
read -s -p "GitHub.com PAT: " token
echo -en "\r\033[K"
else
token="${GH_TOKEN}"
fi
BINARY_URL=$(curl --fail https://$token:@api.github.com/repos/Woosmap/openapi-smusher/releases/latest | jq -r ".assets[] | select(.name | contains (\"${RELEASE_BINARY_SUFFIX}\")) | .url")
BINARY="openapi-smusher${RELEASE_BINARY_SUFFIX}"
echo "$BINARY_URL"
curl --fail --location --output $BINARY --header 'Accept: application/octet-stream' --user $username:$token "$BINARY_URL"
tar -xf "$BINARY"
./openapi-smusher