Skip to content

Commit 795cc04

Browse files
authored
fix: shell installation script (#98)
1 parent a89d3f1 commit 795cc04

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

scripts/install.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# SOURCE: https://github.com/Schniz/fnm/blob/master/.ci/install.sh
2-
31
#!/bin/bash
42

3+
# SOURCE: https://github.com/Schniz/fnm/blob/master/.ci/install.sh
4+
55
set -e
66

77
INSTALL_DIR="$HOME/.snm"
8-
RELEASE="latest"
98
OS="$(uname -s)"
109

1110
# Parse Flags
@@ -27,7 +26,7 @@ parse_args() {
2726
# echo "\`--force-install\`: I hope you know what you're doing." >&2
2827
# FORCE_INSTALL="true"
2928
# shift
30-
;;
29+
# ;;
3130
-r | --release)
3231
RELEASE="$2"
3332
shift # past release argument
@@ -41,24 +40,29 @@ parse_args() {
4140
done
4241
}
4342

43+
# Resources: https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
44+
get_latest_release() {
45+
RELEASE=$(curl --silent "https://api.github.com/repos/numToStr/snm/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' &)
46+
}
47+
4448
set_filename() {
4549
if [ "$OS" == "Linux" ]; then
4650
# Based on https://stackoverflow.com/a/45125525
4751
case "$(uname -m)" in
4852
arm | armv7*)
49-
FILENAME="snm-armv7-unknown-linux-gnueabihf"
53+
FILENAME="snm-$RELEASE-armv7-unknown-linux-gnueabihf"
5054
;;
5155
aarch* | armv8*)
52-
FILENAME="snm-aarch64-unknown-linux-gnu"
56+
FILENAME="snm-$RELEASE-aarch64-unknown-linux-gnu"
5357
;;
5458
*)
55-
FILENAME="snm-x86_64-unknown-linux-gnu"
59+
FILENAME="snm-$RELEASE-x86_64-unknown-linux-gnu"
5660
esac
5761
# elif [ "$OS" == "Darwin" ] && [ "$FORCE_INSTALL" == "true" ]; then
5862
elif [ "$OS" == "Darwin" ]; then
59-
FILENAME="snm-x86_64-apple-darwin"
63+
FILENAME="snm-$RELEASE-x86_64-apple-darwin"
6064
# USE_HOMEBREW="false"
61-
echo "Downloading the latest snm binary from GitHub..."
65+
echo "Downloading snm $VERSION binary from GitHub..."
6266
# echo " Pro tip: it's eaiser to use Homebrew for managing snm in MacOS."
6367
# echo " Remove the \`--force-no-brew\` so it will be easy to upgrade."
6468
# elif [ "$OS" == "Darwin" ]; then
@@ -75,12 +79,7 @@ download_snm() {
7579
# if [ "$USE_HOMEBREW" == "true" ]; then
7680
# brew install snm
7781
# else
78-
if [ "$RELEASE" == "latest" ]; then
79-
URL="https://github.com/numToStr/snm/releases/latest/download/$FILENAME.tar.gz"
80-
else
81-
URL="https://github.com/numToStr/snm/releases/download/$RELEASE/$FILENAME.tar.gz"
82-
fi
83-
82+
URL="https://github.com/numToStr/snm/releases/download/$RELEASE/$FILENAME.tar.gz"
8483
DOWNLOAD_DIR=$(mktemp -d)
8584

8685
echo "Downloading $URL..."
@@ -209,6 +208,7 @@ setup_shell() {
209208
}
210209

211210
parse_args "$@"
211+
get_latest_release
212212
set_filename
213213
check_dependencies
214214
download_snm

0 commit comments

Comments
 (0)