Skip to content

Commit 9adf13e

Browse files
authored
Merge pull request #5 from Hashnode/scriptonist/gimme.sh
Write bash script to get latest release
2 parents fa83997 + 9b0b014 commit 9adf13e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.goreleaser.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ builds:
1414
- amd64
1515
archive:
1616
name_template: "hashnode-{{ .Os }}-{{ .Arch }}"
17+
format_overrides:
18+
- goos: windows
19+
format: zip
20+
files:
21+
- none*
1722
checksum:
1823
name_template: 'checksums.txt'
1924
snapshot:

get.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# set -x
3+
set -eo pipefail
4+
#!/bin/bash
5+
6+
GREEN='\033[0;32m'
7+
NC='\033[0m'
8+
RED='\033[0;31m'
9+
10+
if [[ $EUID -ne 0 ]]; then
11+
echo -e "${RED}This script must be run as root, please try again with sudo${NC}"
12+
exit 1
13+
fi
14+
15+
if ! [ -x "$(command -v tar)" ]; then
16+
echo 'Error: curl is not installed.' >&2
17+
exit 1
18+
fi
19+
20+
BINARY_NAME="hashnode"
21+
HOST_OS=${HOST_OS:-$(uname | tr '[:upper:]' '[:lower:]')}
22+
23+
if [[ $(uname -m) == "x86_64" ]]; then
24+
HOST_ARCH="amd64"
25+
else
26+
HOST_ARCH=${HOST_ARCH:-$(uname -m)}
27+
fi
28+
29+
ARTIFACT_NAME=${BINARY_NAME}-${HOST_OS}-${HOST_ARCH}.tar.gz
30+
31+
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/hashnode/hashnode-cli/releases/latest)
32+
LATEST_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
33+
ARTIFACT_URL="https://github.com/hashnode/hashnode-cli/releases/download/$LATEST_VERSION/$ARTIFACT_NAME"
34+
35+
curl -L $ARTIFACT_URL | tar xvz
36+
mv hashnode /usr/local/bin/hashnode
37+
38+
39+
echo -e "${GREEN}Installed Successfully${NC}"
40+

0 commit comments

Comments
 (0)