-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
114 lines (98 loc) · 3.25 KB
/
install.sh
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
#!/bin/bash
set -e
# Check for required dependencies
check_dependency() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Error: Required dependency '$1' is not installed"
case "$1" in
jq)
echo "Please install jq using one of the following commands:"
echo " - For Debian/Ubuntu: sudo apt-get install jq"
echo " - For RedHat/CentOS: sudo yum install jq"
echo " - For macOS: brew install jq"
;;
*)
echo "Please install $1 before continuing"
;;
esac
exit 1
fi
}
# Check for sudo privileges upfront
if ! [ -w "/usr/local/bin" ]; then
echo "Error: Installation requires sudo privileges"
exit 1
fi
# Check for required dependencies
check_dependency "jq"
check_dependency "curl"
# Determine operating system and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
# Get the latest version tag if VERSION is not set
if [ -z "$VERSION" ]; then
if ! VERSION=$(curl -sSfL https://api.github.com/repos/Arch-Network/arch-node/releases/latest | jq -r .tag_name); then
echo "Error: Failed to fetch latest version information"
exit 1
fi
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
echo "Error: Invalid version information received from GitHub API"
exit 1
fi
fi
# Create temporary directory with cleanup
TMP_DIR=$(mktemp -d)
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
# Download URL based on OS and architecture
BINARY_NAME="arch-cli"
DOWNLOAD_BINARY_NAME="cli"
# Map uname architecture to our release architecture names
case "$ARCH" in
x86_64)
RELEASE_ARCH="x86_64-unknown-linux-gnu"
;;
aarch64|arm64)
if [ "$OS" = "darwin" ]; then
RELEASE_ARCH="aarch64-apple-darwin"
else
RELEASE_ARCH="aarch64-unknown-linux-gnu"
fi
;;
*)
echo "Error: Unsupported architecture: $ARCH"
exit 1
;;
esac
# Construct and validate download URL
DOWNLOAD_URL="https://github.com/Arch-Network/arch-node/releases/download/${VERSION}/${DOWNLOAD_BINARY_NAME}-${RELEASE_ARCH}"
echo "Downloading ${BINARY_NAME} version ${VERSION}..."
# Attempt download with better error handling
if ! curl -sSfL "$DOWNLOAD_URL" -o "$TMP_DIR/${BINARY_NAME}"; then
echo "Error: Failed to download binary from ${DOWNLOAD_URL}"
echo "Please check your internet connection and verify the version exists"
exit 1
fi
# Verify download
if [ ! -s "$TMP_DIR/${BINARY_NAME}" ]; then
echo "Error: Downloaded file is empty"
echo "Please verify the version and architecture are correct:"
echo "Version: ${VERSION}"
echo "Architecture: ${RELEASE_ARCH}"
exit 1
fi
# Install into /usr/local/bin with improved error messages
INSTALL_DIR="/usr/local/bin"
if ! sudo mv "$TMP_DIR/${BINARY_NAME}" "$INSTALL_DIR/"; then
echo "Error: Failed to move binary to ${INSTALL_DIR}"
echo "Please check your permissions and disk space"
exit 1
fi
if ! sudo chmod +x "$INSTALL_DIR/${BINARY_NAME}"; then
echo "Error: Failed to make binary executable"
echo "Please check your permissions"
exit 1
fi
echo "${BINARY_NAME} ${VERSION} installed successfully to ${INSTALL_DIR}"