Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CONF_DIR="/etc/$APP_NAME"
ENV_FILE="$CONF_DIR/env"
SERVICE_NAME="$APP_NAME"

VERSION=""; UNATTENDED=0; DRY_RUN=0; UNINSTALL=0; PURGE=0
KEYNEST_VERSION=""; UNATTENDED=0; DRY_RUN=0; UNINSTALL=0; PURGE=0

# ---------------------------------------------------------------- logging ---
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
Expand Down Expand Up @@ -72,7 +72,7 @@ EOF

for arg in "$@"; do
case "$arg" in
--version=*) VERSION="${arg#*=}" ;;
--version=*) KEYNEST_VERSION="${arg#*=}" ;;
--unattended) UNATTENDED=1 ;;
--dry-run) DRY_RUN=1 ;;
--uninstall) UNINSTALL=1 ;;
Expand Down Expand Up @@ -213,17 +213,21 @@ if [ ! -f "$ENV_FILE" ]; then
fi

# --------------------------------------------------------- resolve version --
if [ -z "$VERSION" ]; then
if [ -z "$KEYNEST_VERSION" ]; then
info "resolving latest stable version"
VERSION=$($FETCH "https://api.github.com/repos/$GH_REPO/releases/latest" \
KEYNEST_VERSION=$($FETCH "https://api.github.com/repos/$GH_REPO/releases/latest" \
| grep '"tag_name"' | head -1 | cut -d'"' -f4) \
|| fatal 31 "could not resolve the latest version (GitHub rate-limit?). Use --version=X.Y.Z"
[ -n "$VERSION" ] || fatal 31 "no stable release found yet. Use --version=X.Y.Z"
[ -n "$KEYNEST_VERSION" ] || fatal 31 "no stable release found yet. Use --version=X.Y.Z"
fi
VERSION_NORM=$(echo "$VERSION" | sed 's/^v//')
VERSION_NORM=$(echo "$KEYNEST_VERSION" | sed 's/^v//')
case "$KEYNEST_VERSION" in
v*) KEYNEST_TAG="$KEYNEST_VERSION" ;;
*) KEYNEST_TAG="v$KEYNEST_VERSION" ;;
esac
ASSET="${APP_NAME}_${VERSION_NORM}_linux_${REL_ARCH}.tar.gz"
BASE_URL="https://github.com/$GH_REPO/releases/download/$VERSION"
info "version: $VERSION"
BASE_URL="https://github.com/$GH_REPO/releases/download/$KEYNEST_TAG"
info "version: $KEYNEST_VERSION"

# connectivity pre-flight BEFORE touching the system
$FETCH "https://github.com/$GH_REPO" >/dev/null \
Expand All @@ -239,7 +243,7 @@ trap cleanup EXIT INT TERM

info "downloading $ASSET"
fetch_to "$BASE_URL/$ASSET" "$TMP/$ASSET" || fatal 32 "download failed: $BASE_URL/$ASSET"
fetch_to "$BASE_URL/checksums.txt" "$TMP/checksums.txt" || fatal 32 "checksums.txt not found in release $VERSION"
fetch_to "$BASE_URL/checksums.txt" "$TMP/checksums.txt" || fatal 32 "checksums.txt not found in release $KEYNEST_VERSION"
[ -s "$TMP/$ASSET" ] || fatal 32 "downloaded asset is empty"

SUM_FILE=$(sha256sum "$TMP/$ASSET" | awk '{print $1}')
Expand Down Expand Up @@ -378,7 +382,7 @@ fi

# ------------------------------------------------------------------ summary --
printf '\n%s================ %s installed ================%s\n' "$C_G" "$APP_NAME" "$C_0"
printf 'Version: %s%s\n' "$VERSION" "$( [ "$UPGRADING" -eq 1 ] && echo ' (upgrade)' || true)"
printf 'Version: %s%s\n' "$KEYNEST_VERSION" "$( [ "$UPGRADING" -eq 1 ] && echo ' (upgrade)' || true)"
printf 'App: %s -> %s\n' "$OPT_DIR/current" "$RELEASE_DIR"
printf 'Node: %s\n' "$NODE_BIN"
printf 'Data: %s\n' "$STATE_DIR"
Expand Down
Loading