Skip to content

Commit 3d18025

Browse files
committed
feat: update jnv version to 1.0.1 and adjust installation script for latest version handling
1 parent 3d048b1 commit 3d18025

4 files changed

Lines changed: 100 additions & 71 deletions

File tree

src/jnv/devcontainer-feature.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "jnv",
33
"id": "jnv",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"description": "jnv is designed for navigating JSON, offering an interactive JSON viewer and jq filter editor.",
6+
"documentationURL": "https://github.com/ynqa/jnv",
67
"options": {
78
"version": {
89
"type": "string",

src/jnv/install.sh

Lines changed: 96 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,130 @@
11
#!/usr/bin/env bash
22

3+
# Variables
4+
REPO_OWNER="ynqa"
5+
REPO_NAME="jnv"
36
JNV_VERSION="${VERSION:-"latest"}"
4-
JNV_API_URL="https://api.github.com/repos/ynqa/jnv/releases"
5-
JNV_RELEASES_URL="https://github.com/ynqa/jnv/releases"
7+
GITHUB_API_REPO_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases"
68

7-
set -e -x
9+
set -e
810

911
if [ "$(id -u)" -ne 0 ]; then
10-
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
11-
exit 1
12+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
13+
exit 1
1214
fi
1315

1416
# Clean up
1517
rm -rf /var/lib/apt/lists/*
1618

17-
architecture="$(uname -m)"
18-
case ${architecture} in
19-
x86_64) architecture="x86_64" ;;
20-
*)
21-
echo "(!) Architecture ${architecture} unsupported"
22-
exit 1
23-
;;
19+
# Determine the OS and architecture
20+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
21+
ARCH=$(uname -m)
22+
23+
case "$ARCH" in
24+
x86_64)
25+
ARCH="x86_64"
26+
;;
27+
aarch64)
28+
ARCH="aarch64"
29+
;;
30+
armv7l)
31+
ARCH="armv7"
32+
;;
33+
*)
34+
echo "Unsupported architecture: $ARCH"
35+
exit 1
36+
;;
2437
esac
2538

26-
# check if linux/windows/macOS
27-
OS="$(uname -s)"
28-
case ${OS} in
29-
Linux) OS="unknown-linux-gnu" ;;
30-
Darwin) OS="apple-darwin" ;;
31-
*)
32-
echo "(!) Platform ${OS} unsupported"
33-
exit 1
34-
;;
39+
case "$OS" in
40+
linux)
41+
OS="unknown-linux-gnu"
42+
;;
43+
*)
44+
echo "Unsupported OS: $OS (devcontainer features only support Linux)"
45+
exit 1
46+
;;
3547
esac
3648

3749
# Checks if packages are installed and installs them if not
3850
check_packages() {
39-
if ! dpkg -s "$@" >/dev/null 2>&1; then
40-
if [ "$(find /var/lib/apt/lists/* -print0 | wc -l)" = "0" ]; then
41-
echo "Running apt-get update..."
42-
apt-get update -y
43-
fi
44-
apt-get -y install --no-install-recommends "$@"
45-
fi
51+
if ! dpkg -s "$@" >/dev/null 2>&1; then
52+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
53+
echo "Running apt-get update..."
54+
apt-get update -y
55+
fi
56+
apt-get -y install --no-install-recommends "$@"
57+
fi
4658
}
4759

48-
# Figure out correct version of a three part version number is not passed
49-
validate_version_exists() {
50-
local variable_name=$1
51-
local requested_version=$2
52-
if [ "${requested_version}" = "latest" ]; then requested_version=$(curl -sL ${JNV_API_URL}/latest | jq -r ".tag_name"); fi
53-
local version_list
54-
version_list=$(curl -sL ${JNV_API_URL} | jq -r ".[].tag_name")
55-
if [ -z "${variable_name}" ] || ! echo "${version_list}" | grep "${requested_version}" >/dev/null 2>&1; then
56-
echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
57-
exit 1
58-
fi
59-
echo "${variable_name}=${requested_version}"
60+
# Function to get the latest version from GitHub API
61+
get_latest_version() {
62+
curl -s "${GITHUB_API_REPO_URL}/latest" | jq -r ".tag_name"
6063
}
6164

62-
# make sure we have curl
65+
# Make sure we have required packages
6366
check_packages curl tar jq ca-certificates xz-utils
6467

65-
# make sure version is available
66-
if [ "${JNV_VERSION}" = "latest" ]; then JNV_VERSION=$(curl -sL ${JNV_API_URL}/latest | jq -r ".tag_name"); fi
67-
validate_version_exists JNV_VERSION "${JNV_VERSION}"
68+
# Check if a version is passed as an argument
69+
if [ -z "$JNV_VERSION" ] || [ "$JNV_VERSION" == "latest" ]; then
70+
# No version provided, get the latest version
71+
JNV_VERSION=$(get_latest_version)
72+
echo "No version provided or 'latest' specified, installing the latest version: $JNV_VERSION"
73+
else
74+
echo "Installing version from environment variable: $JNV_VERSION"
75+
fi
6876

69-
# download and install binary
70-
JNV_FILENAME="jnv-${architecture}-${OS}.tar.xz"
77+
# Construct the download URL
78+
DOWNLOAD_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${JNV_VERSION}/jnv-${ARCH}-${OS}.tar.xz"
7179

72-
url="${JNV_RELEASES_URL}/download/${JNV_VERSION}/${JNV_FILENAME}"
73-
echo "Downloading ${url}..."
74-
curl -sSL "$url" -o "${JNV_FILENAME}"
75-
if [ $? -ne 0 ]; then
76-
echo "Failed to download ${url}"
77-
exit 1
78-
fi
80+
# Create a temporary directory for the download
81+
TMP_DIR=$(mktemp -d)
82+
cd "$TMP_DIR" || exit
83+
84+
echo "Downloading jnv from $DOWNLOAD_URL"
85+
curl -sSL "$DOWNLOAD_URL" -o "jnv.tar.xz" || {
86+
echo "Failed to download $DOWNLOAD_URL"
87+
exit 1
88+
}
7989

80-
# Custom steps for jnv
81-
# unxz jnv-x86_64-unknown-linux-gnu.tar.xz
82-
# tar xf jnv-x86_64-unknown-linux-gnu.tar
83-
# mv jnv-x86_64-unknown-linux-gnu/jnv /usr/local/bin/jnv
84-
# rm -rf jnv-x86_64-unknown-linux-gnu
85-
# rm jnv-x86_64-unknown-linux-gnu.tar
90+
# Extract the archive
91+
echo "Extracting jnv..."
92+
unxz "jnv.tar.xz" || {
93+
echo "Failed to decompress jnv.tar.xz"
94+
exit 1
95+
}
8696

87-
unxz "${JNV_FILENAME}"
88-
tar xf "${JNV_FILENAME%.xz}"
89-
install -m 555 "${JNV_FILENAME%.tar.xz}/jnv" /usr/local/bin/jnv
97+
tar -xf "jnv.tar" || {
98+
echo "Failed to extract jnv.tar"
99+
exit 1
100+
}
90101

91-
if [ $? -ne 0 ]; then
92-
echo "Failed to extract ${JNV_FILENAME}"
93-
exit 1
102+
# Find the extracted directory (it should match the archive name pattern)
103+
EXTRACTED_DIR=$(find . -name "jnv-${ARCH}-${OS}" -type d | head -1)
104+
if [ -z "$EXTRACTED_DIR" ]; then
105+
echo "ERROR: Could not find extracted jnv directory"
106+
exit 1
94107
fi
95108

96-
rm -rf "${JNV_FILENAME%.tar.xz}"
97-
rm "${JNV_FILENAME%.xz}"
109+
# Move the binary to /usr/local/bin
110+
echo "Installing jnv..."
111+
install -m 755 "${EXTRACTED_DIR}/jnv" /usr/local/bin/jnv || {
112+
echo "Failed to install jnv binary"
113+
exit 1
114+
}
115+
116+
# Cleanup
117+
cd - || exit
118+
rm -rf "$TMP_DIR"
98119

99120
# Clean up
100-
# rm -rf /var/lib/apt/lists/*
121+
rm -rf /var/lib/apt/lists/*
122+
123+
# Verify installation
124+
echo "Verifying installation..."
125+
jnv --version || {
126+
echo "Installation verification failed"
127+
exit 1
128+
}
101129

102130
echo "Done!"

test/_global/jnv-specific-version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -e
44
source dev-container-features-test-lib
5-
check "jnv with specific version" /bin/bash -c "jnv -V | grep '0.1.2'"
5+
check "jnv with specific version" /bin/bash -c "jnv -V | grep '0.6.1'"
66

77
reportResults

test/_global/scenarios.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
9999
"features": {
100100
"jnv": {
101-
"version": "v0.1.2"
101+
"version": "v0.6.1"
102102
}
103103
}
104104
},

0 commit comments

Comments
 (0)