-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
172 lines (147 loc) · 4.83 KB
/
install.sh
File metadata and controls
172 lines (147 loc) · 4.83 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
169
170
171
172
#!/bin/bash
set -e
REPO="dvaji/infera"
BINARY_NAME="infs"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
get_latest_version() {
local response
response=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" 2>/dev/null) || {
error "Failed to fetch latest version from GitHub API. Please check your internet connection."
}
local version
version=$(echo "$response" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$version" ]; then
error "Could not parse version from GitHub API response. Response was: ${response:0:200}..."
fi
echo "$version"
}
get_platform() {
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux)
if [ "$ARCH" = "x86_64" ]; then
echo "linux-x86_64"
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
echo "linux-aarch64"
else
error "Unsupported architecture: $ARCH"
fi
;;
Darwin)
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
echo "macos-aarch64"
else
error "Unsupported macOS architecture: $ARCH. Only Apple Silicon (aarch64/arm64) is supported."
fi
;;
*)
error "Unsupported OS: $OS"
;;
esac
}
check_dependencies() {
if ! command -v curl &> /dev/null; then
error "curl is required but not installed. Please install curl first."
fi
}
detect_shell_profile() {
SHELL_PROFILE=""
case "${SHELL##*/}" in
zsh)
if [ -f "$HOME/.zshrc" ]; then
SHELL_PROFILE="$HOME/.zshrc"
fi
;;
bash)
if [ -f "$HOME/.bashrc" ]; then
SHELL_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
SHELL_PROFILE="$HOME/.bash_profile"
fi
;;
fish)
if [ -f "$HOME/.config/fish/config.fish" ]; then
SHELL_PROFILE="$HOME/.config/fish/config.fish"
fi
;;
*)
if [ -f "$HOME/.profile" ]; then
SHELL_PROFILE="$HOME/.profile"
fi
;;
esac
if [ -z "$SHELL_PROFILE" ]; then
for profile in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile" "$HOME/.bash_profile"; do
if [ -f "$profile" ]; then
SHELL_PROFILE="$profile"
break
fi
done
fi
}
install_infs() {
check_dependencies
VERSION="${1:-$(get_latest_version)}"
PLATFORM=$(get_platform)
ASSET_NAME="infs-$PLATFORM"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/$ASSET_NAME"
info "Installing infs $VERSION for $PLATFORM..."
mkdir -p "$INSTALL_DIR"
TEMP_FILE=$(mktemp)
trap 'rm -f "$TEMP_FILE"' EXIT
info "Downloading from $DOWNLOAD_URL..."
if ! curl -fsSL "$DOWNLOAD_URL" -o "$TEMP_FILE"; then
error "Failed to download infs. The version may not have a release for your platform."
fi
chmod +x "$TEMP_FILE"
mv "$TEMP_FILE" "$INSTALL_DIR/$BINARY_NAME"
info "Installed infs to $INSTALL_DIR/$BINARY_NAME"
if ! echo ":$PATH:" | grep -q ":$INSTALL_DIR:"; then
detect_shell_profile
if [ -n "$SHELL_PROFILE" ]; then
info "Adding $INSTALL_DIR to PATH in $SHELL_PROFILE..."
echo "" >> "$SHELL_PROFILE"
echo "# Added by infs installer" >> "$SHELL_PROFILE"
if [[ "${SHELL##*/}" == "fish" ]]; then
echo "set -gx PATH \$PATH $INSTALL_DIR" >> "$SHELL_PROFILE"
else
echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >> "$SHELL_PROFILE"
fi
export PATH="$PATH:$INSTALL_DIR"
info "Added to PATH. Run 'source $SHELL_PROFILE' or restart your shell."
else
warn "Could not detect shell profile. Add the following manually:"
echo ""
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
fi
fi
"$INSTALL_DIR/$BINARY_NAME" --version
info "Installation complete!"
}
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: curl -fsSL https://raw.githubusercontent.com/dvaji/infera/main/install.sh | bash"
echo " or: curl -fsSL https://raw.githubusercontent.com/dvaji/infera/main/install.sh | bash -s -- v1.0.0"
echo ""
echo "Environment variables:"
echo " INSTALL_DIR - Directory to install infs (default: \$HOME/.local/bin)"
echo ""
echo "Examples:"
echo " INSTALL_DIR=/usr/local/bin curl -fsSL ... | bash"
exit 0
fi
install_infs "$1"