-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·168 lines (146 loc) · 4.55 KB
/
install.sh
File metadata and controls
executable file
·168 lines (146 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/sh
# Nullify CLI installer
# Usage: curl -sSfL https://raw.githubusercontent.com/Nullify-Platform/cli/main/install.sh | sh
set -e
REPO="Nullify-Platform/cli"
BINARY_NAME="nullify"
# Detect OS
detect_os() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$os" in
linux) echo "linux" ;;
darwin) echo "darwin" ;;
mingw*|msys*|cygwin*) echo "windows" ;;
*) echo "Unsupported OS: $os" >&2; exit 1 ;;
esac
}
# Detect architecture
detect_arch() {
arch=$(uname -m)
case "$arch" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
esac
}
# Get latest release version from GitHub API
get_latest_version() {
version=$(curl -sSfL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')
if [ -z "$version" ]; then
echo "Failed to determine latest version" >&2
exit 1
fi
echo "$version"
}
main() {
# Parse arguments
NULLIFY_HOST=""
while [ $# -gt 0 ]; do
case "$1" in
--host)
NULLIFY_HOST="$2"
shift 2
;;
--host=*)
NULLIFY_HOST="${1#*=}"
shift
;;
*)
shift
;;
esac
done
os=$(detect_os)
arch=$(detect_arch)
version=$(get_latest_version)
version_number="${version#v}"
echo "Installing Nullify CLI ${version} for ${os}/${arch}..."
# Determine archive extension
if [ "$os" = "windows" ]; then
ext="zip"
else
ext="tar.gz"
fi
archive_name="nullify_${os}_${arch}.${ext}"
download_url="https://github.com/${REPO}/releases/download/${version}/${archive_name}"
checksums_url="https://github.com/${REPO}/releases/download/${version}/checksums.txt"
# Create temp directory
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
# Download archive and checksums
echo "Downloading ${download_url}..."
curl -sSfL -o "${tmp_dir}/${archive_name}" "$download_url"
curl -sSfL -o "${tmp_dir}/checksums.txt" "$checksums_url"
# Verify checksum
echo "Verifying checksum..."
expected_checksum=$(grep "${archive_name}" "${tmp_dir}/checksums.txt" | awk '{print $1}')
if [ -z "$expected_checksum" ]; then
echo "Warning: could not find checksum for ${archive_name}, skipping verification" >&2
else
if command -v sha256sum > /dev/null 2>&1; then
actual_checksum=$(sha256sum "${tmp_dir}/${archive_name}" | awk '{print $1}')
elif command -v shasum > /dev/null 2>&1; then
actual_checksum=$(shasum -a 256 "${tmp_dir}/${archive_name}" | awk '{print $1}')
else
echo "Error: no sha256sum or shasum found, cannot verify binary integrity" >&2
exit 1
fi
if [ "$actual_checksum" != "$expected_checksum" ]; then
echo "Checksum verification failed!" >&2
echo "Expected: ${expected_checksum}" >&2
echo "Actual: ${actual_checksum}" >&2
exit 1
fi
echo "Checksum verified."
fi
# Extract
echo "Extracting..."
if [ "$ext" = "zip" ]; then
unzip -q "${tmp_dir}/${archive_name}" -d "${tmp_dir}/extracted"
else
mkdir -p "${tmp_dir}/extracted"
tar -xzf "${tmp_dir}/${archive_name}" -C "${tmp_dir}/extracted"
fi
# Determine install directory
if [ -w "/usr/local/bin" ]; then
install_dir="/usr/local/bin"
elif [ -d "${HOME}/.local/bin" ]; then
install_dir="${HOME}/.local/bin"
else
mkdir -p "${HOME}/.local/bin"
install_dir="${HOME}/.local/bin"
fi
# Install binary
cp "${tmp_dir}/extracted/${BINARY_NAME}" "${install_dir}/${BINARY_NAME}"
chmod +x "${install_dir}/${BINARY_NAME}"
echo ""
echo "Nullify CLI ${version} installed to ${install_dir}/${BINARY_NAME}"
# Check if install dir is in PATH
case ":${PATH}:" in
*":${install_dir}:"*) ;;
*)
echo ""
echo "NOTE: ${install_dir} is not in your PATH."
echo "Add it by running:"
echo " export PATH=\"${install_dir}:\$PATH\""
;;
esac
# Configure host if provided
if [ -n "$NULLIFY_HOST" ]; then
config_dir="${HOME}/.nullify"
mkdir -m 0700 -p "$config_dir"
# Sanitize host: strip characters that could break JSON
sanitized_host=$(printf '%s' "$NULLIFY_HOST" | tr -d '"\\')
printf '{"host":"%s"}\n' "$sanitized_host" > "${config_dir}/config.json"
chmod 0600 "${config_dir}/config.json"
echo "Configured host: ${NULLIFY_HOST}"
fi
echo ""
echo "Run 'nullify --version' to verify the installation."
if [ -n "$NULLIFY_HOST" ]; then
echo "Run 'nullify auth login' to authenticate."
else
echo "Run 'nullify auth login --host <your-instance>.nullify.ai' to get started."
fi
}
main "$@"