-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·159 lines (132 loc) · 4.4 KB
/
install.sh
File metadata and controls
executable file
·159 lines (132 loc) · 4.4 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
#!/bin/bash
# AxKeyStore Installation Script
# This script downloads the latest or a specific version of AxKeyStore and installs it locally.
set -e
REPO="basilgregory/axkeystore"
BINARY_NAME="axkeystore"
INSTALL_BASE_DIR="$HOME/.axkeystore"
INSTALL_DIR="$INSTALL_BASE_DIR/bin"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}Starting AxKeyStore installation...${NC}"
# 1. Detect OS and Architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
darwin)
PLATFORM="macos"
;;
linux)
PLATFORM="linux"
;;
*)
echo -e "${RED}Unsupported operating system: $OS${NC}"
exit 1
;;
esac
case "$ARCH" in
x86_64|amd64)
ARCH="x86_64"
;;
arm64|aarch64)
ARCH="aarch64"
;;
*)
echo -e "${RED}Unsupported architecture: $ARCH${NC}"
exit 1
;;
esac
# 2. Check for dependencies
if ! command -v curl >/dev/null 2>&1; then
echo -e "${RED}curl is required but not installed. Please install curl and try again.${NC}"
exit 1
fi
# 3. Determine Version
VERSION=$1
if [ -z "$VERSION" ] || [ "$VERSION" = "latest" ]; then
echo -e "${BLUE}Fetching latest version information...${NC}"
VERSION=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo -e "${RED}Failed to fetch latest version. Please specify a version tag (e.g., v0.1.6).${NC}"
exit 1
fi
else
# Ensure version starts with 'v'
if [[ ! "$VERSION" =~ ^v ]]; then
VERSION="v$VERSION"
fi
fi
echo -e "${BLUE}Target Version: $VERSION${NC}"
echo -e "${BLUE}Platform: $PLATFORM-$ARCH${NC}"
# 3. Construct Asset Name
ASSET_NAME="${BINARY_NAME}-${PLATFORM}-${ARCH}"
if [ "$PLATFORM" = "windows" ]; then
ASSET_NAME="${ASSET_NAME}.exe"
fi
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/$ASSET_NAME"
# 4. Download Binary
TMP_DIR=$(mktemp -d)
TMP_BINARY="$TMP_DIR/$ASSET_NAME"
echo -e "${BLUE}Downloading $ASSET_NAME...${NC}"
if ! curl -L --fail -o "$TMP_BINARY" "$DOWNLOAD_URL"; then
echo -e "${RED}Failed to download binary from $DOWNLOAD_URL${NC}"
echo -e "${RED} Please check if the version and platform are correct.${NC}"
exit 1
fi
chmod +x "$TMP_BINARY"
# 5. Install Binary
FINAL_BINARY_PATH="$INSTALL_DIR/${BINARY_NAME}-${VERSION}"
SYMLINK_PATH="$INSTALL_DIR/${BINARY_NAME}"
echo -e "${BLUE}Installing to $INSTALL_DIR...${NC}"
# Create directories if they don't exist
mkdir -p "$INSTALL_DIR"
# Move binary and create symlink
mv "$TMP_BINARY" "$FINAL_BINARY_PATH"
ln -sf "$FINAL_BINARY_PATH" "$SYMLINK_PATH"
# 6. Cleanup
rm -rf "$TMP_DIR"
echo -e "${GREEN}AxKeyStore $VERSION installed successfully!${NC}"
echo -e "${GREEN}Installation path: ${NC}${BLUE}$SYMLINK_PATH${NC}"
# 7. Update PATH in shell profile
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
SHELL_TYPE=$(basename "$SHELL")
PROFILE=""
case "$SHELL_TYPE" in
zsh)
PROFILE="$HOME/.zshrc"
[ ! -f "$PROFILE" ] && [ -f "$HOME/.zprofile" ] && PROFILE="$HOME/.zprofile"
;;
bash)
PROFILE="$HOME/.bashrc"
[ ! -f "$PROFILE" ] && [ -f "$HOME/.bash_profile" ] && PROFILE="$HOME/.bash_profile"
;;
*)
PROFILE="$HOME/.profile"
;;
esac
if [ -n "$PROFILE" ]; then
if [ ! -f "$PROFILE" ]; then
touch "$PROFILE"
fi
if ! grep -q "$INSTALL_DIR" "$PROFILE"; then
echo -e "${BLUE}Adding $INSTALL_DIR to PATH in $PROFILE...${NC}"
echo "" >> "$PROFILE"
echo "# AxKeyStore PATH" >> "$PROFILE"
echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >> "$PROFILE"
echo -e "${GREEN}PATH updated in $PROFILE${NC}"
else
echo -e "${BLUE} $INSTALL_DIR is already mentioned in $PROFILE.${NC}"
fi
echo -e "${BLUE} Please run 'source $PROFILE' or restart your terminal to use '${NC}${BLUE}${BINARY_NAME}${NC}${BLUE}' from anywhere.${NC}"
fi
else
echo -e "${GREEN}AxKeyStore is ready! You can run it using the command: ${NC}${BLUE}${BINARY_NAME}${NC}"
fi
# Verify installation
if [ -f "$SYMLINK_PATH" ]; then
INSTALLED_VER=$("$SYMLINK_PATH" --version 2>/dev/null || echo "$VERSION")
echo -e "${GREEN}Installed version: $INSTALLED_VER${NC}"
fi