|
1 | 1 | #!/usr/bin/env sh |
2 | 2 | set -e |
3 | 3 |
|
4 | | -# Detect OS |
| 4 | +# detect OS |
5 | 5 | detect_os() { |
6 | 6 | case "$(uname -s)" in |
7 | 7 | Linux*) echo "linux";; |
8 | 8 | Darwin*) echo "darwin";; |
9 | 9 | FreeBSD*) echo "freebsd";; |
10 | 10 | MINGW*|MSYS*|CYGWIN*) echo "windows";; |
11 | 11 | *) |
12 | | - echo "Error: Unsupported OS $(uname -s)" >&2 |
| 12 | + echo "error: unsupported OS $(uname -s)" >&2 |
13 | 13 | exit 1 |
14 | 14 | ;; |
15 | 15 | esac |
16 | 16 | } |
17 | 17 |
|
18 | | -# Detect architecture |
| 18 | +# detect architecture |
19 | 19 | detect_arch() { |
20 | 20 | case "$(uname -m)" in |
21 | 21 | x86_64|amd64) echo "amd64";; |
22 | 22 | aarch64|arm64) echo "arm64";; |
23 | 23 | riscv64) echo "riscv64";; |
24 | 24 | *) |
25 | | - echo "Error: Unsupported architecture $(uname -m)" >&2 |
| 25 | + echo "error: unsupported architecture $(uname -m)" >&2 |
26 | 26 | exit 1 |
27 | 27 | ;; |
28 | 28 | esac |
29 | 29 | } |
30 | 30 |
|
31 | | -# Set install directory |
| 31 | +# set install directory |
32 | 32 | INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}" |
33 | 33 |
|
34 | | -# Detect platform |
| 34 | +# detect platform |
35 | 35 | OS=$(detect_os) |
36 | 36 | ARCH=$(detect_arch) |
37 | 37 |
|
38 | | -echo "Installing nak ($OS-$ARCH) to $INSTALL_DIR..." |
| 38 | +echo "installing nak ($OS-$ARCH) to $INSTALL_DIR..." |
39 | 39 |
|
40 | | -# Check if curl is available |
41 | | -command -v curl >/dev/null 2>&1 || { echo "Error: curl is required" >&2; exit 1; } |
| 40 | +# check if curl is available |
| 41 | +command -v curl >/dev/null 2>&1 || { echo "error: curl is required" >&2; exit 1; } |
42 | 42 |
|
43 | | -# Get latest release tag |
| 43 | +# get latest release tag |
44 | 44 | RELEASE_INFO=$(curl -s https://api.github.com/repos/fiatjaf/nak/releases/latest) |
45 | 45 | TAG="${RELEASE_INFO#*\"tag_name\"}" |
46 | 46 | TAG="${TAG#*\"}" |
47 | 47 | TAG="${TAG%%\"*}" |
48 | 48 |
|
49 | | -[ -z "$TAG" ] && { echo "Error: Failed to fetch release info" >&2; exit 1; } |
| 49 | +[ -z "$TAG" ] && { echo "error: failed to fetch release info" >&2; exit 1; } |
50 | 50 |
|
51 | | -# Construct download URL |
| 51 | +# construct download URL |
52 | 52 | BINARY_NAME="nak-${TAG}-${OS}-${ARCH}" |
53 | 53 | [ "$OS" = "windows" ] && BINARY_NAME="${BINARY_NAME}.exe" |
54 | 54 | DOWNLOAD_URL="https://github.com/fiatjaf/nak/releases/download/${TAG}/${BINARY_NAME}" |
55 | 55 |
|
56 | | -# Create install directory and download |
| 56 | +# create install directory and download |
57 | 57 | mkdir -p "$INSTALL_DIR" |
58 | 58 | TARGET_PATH="$INSTALL_DIR/nak" |
59 | 59 | [ "$OS" = "windows" ] && TARGET_PATH="${TARGET_PATH}.exe" |
60 | 60 |
|
61 | 61 | if curl -sS -L -f -o "$TARGET_PATH" "$DOWNLOAD_URL"; then |
62 | 62 | chmod +x "$TARGET_PATH" |
63 | | - echo "Installed nak $TAG to $TARGET_PATH" |
64 | | - |
65 | | - # Check if install dir is in PATH |
| 63 | + echo "installed nak $TAG to $TARGET_PATH" |
| 64 | + |
| 65 | + # check if install dir is in PATH |
66 | 66 | case ":$PATH:" in |
67 | 67 | *":$INSTALL_DIR:"*) ;; |
68 | | - *) echo "Note: Add $INSTALL_DIR to your PATH" ;; |
| 68 | + *) echo "note: add $INSTALL_DIR to your PATH" ;; |
69 | 69 | esac |
70 | 70 | else |
71 | | - echo "Error: Download failed from $DOWNLOAD_URL" >&2 |
| 71 | + echo "error: download failed from $DOWNLOAD_URL" >&2 |
72 | 72 | exit 1 |
73 | 73 | fi |
0 commit comments