-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstall.sh
More file actions
156 lines (129 loc) · 5.57 KB
/
install.sh
File metadata and controls
156 lines (129 loc) · 5.57 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
#!/usr/bin/env bash
#
# A professional-grade installer for Termix.
#
# Usage:
# Install/Update: curl -fsSL https://raw.githubusercontent.com/amrohan/termix/main/install.sh | bash
# Install specific version: curl -fsSL https://raw.githubusercontent.com/amrohan/termix/main/install.sh | bash -s v1.5.0
# Uninstall: curl -fsSL https://raw.githubusercontent.com/amrohan/termix/main/install.sh | bash -s uninstall
set -euo pipefail
REPO="amrohan/termix"
EXE_NAME="termix"
INSTALL_DIR="$HOME/.local/bin"
if [[ -t 1 ]]; then
Color_Off='\033[0m'
Red='\033[0;31m'
Green='\033[0;32m'
Dim='\033[0;2m'
Bold_Green='\033[1;32m'
Bold_White='\033[1m'
else
Color_Off=''
Red=''
Green=''
Dim=''
Bold_Green=''
Bold_White=''
fi
error() {
echo -e "${Red}error${Color_Off}:" "$@" >&2
exit 1
}
info() { echo -e "${Dim}$@ ${Color_Off}"; }
info_bold() { echo -e "${Bold_White}$@ ${Color_Off}"; }
success() { echo -e "${Green}$@ ${Color_Off}"; }
tildify() { if [[ $1 = "$HOME"* ]]; then
local r=\~/
echo "${1/$HOME\//$r}"
else echo "$1"; fi; }
install_termix() {
info "Starting Termix installation..."
command -v curl >/dev/null || error "'curl' is required."
command -v unzip >/dev/null || error "'unzip' is required."
command -v jq >/dev/null || error "'jq' is required. Please install it first (e.g., 'brew install jq')."
local platform
platform=$(uname -ms)
case "$platform" in
'Darwin x86_64') local target=osx-x64 ;;
'Darwin arm64') local target=osx-arm64 ;;
'Linux aarch64' | 'Linux arm64') local target=linux-aarch64 ;;
'Linux x86_64') local target=linux-x64 ;;
*) error "Unsupported platform: $platform. Please open an issue at https://github.com/$REPO/issues" ;;
esac
if [[ $target = osx-x64 ]] && [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then
target=osx-arm64
info "Rosetta 2 detected. Downloading Termix for ARM64 instead."
fi
local tag="${1:-latest}"
local api_url="https://api.github.com/repos/$REPO/releases"
if [[ $tag = "latest" ]]; then local release_url="$api_url/latest"; else local release_url="$api_url/tags/$tag"; fi
if [[ $target == "linux"* ]]; then local asset_suffix="$target.tar.gz"; else local asset_suffix="$target.zip"; fi
info "Fetching release information for tag: $tag"
local download_url
download_url=$(curl -s "$release_url" | jq -r ".assets[] | select(.name | endswith(\"termix-$asset_suffix\")) | .browser_download_url")
if [ -z "$download_url" ]; then error "Could not find a release asset for your system (termix-$asset_suffix) with tag '$tag'."; fi
mkdir -p "$INSTALL_DIR" || error "Failed to create install directory \"$INSTALL_DIR\""
local temp_dir
temp_dir=$(mktemp -d)
local archive_path="$temp_dir/termix-$asset_suffix"
local exe_path="$INSTALL_DIR/$EXE_NAME"
info_bold "Downloading from $download_url"
curl --fail --location --progress-bar --output "$archive_path" "$download_url" || error "Failed to download Termix."
info "Extracting archive..."
if [[ $asset_suffix == *.zip ]]; then unzip -oqd "$temp_dir" "$archive_path"; else tar -xzf "$archive_path" -C "$temp_dir"; fi
local found_exe_path
found_exe_path=$(find "$temp_dir" -type f -name "$EXE_NAME" | head -n 1)
if [ -z "$found_exe_path" ]; then
error "Could not find the '$EXE_NAME' executable in the downloaded archive."
fi
mv "$found_exe_path" "$exe_path" || error 'Failed to move executable to destination.'
chmod +x "$exe_path" || error 'Failed to set permissions.'
if [[ $target == "osx"* ]]; then xattr -d com.apple.quarantine "$exe_path" 2>/dev/null || true; fi
rm -r "$temp_dir"
success "Termix was installed successfully to $Bold_Green$(tildify "$exe_path")"
local profile_file
profile_file=$(detect_profile)
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
if [ -n "$profile_file" ] && [ -w "$profile_file" ]; then
if ! grep -q "# Added by Termix installer" "$profile_file"; then
info "Adding '$INSTALL_DIR' to \$PATH in '$(tildify "$profile_file")'"
echo "" >>"$profile_file"
echo "# Added by Termix installer" >>"$profile_file"
echo "export PATH=\"\$PATH:$INSTALL_DIR\"" >>"$profile_file"
info "To get started, restart your terminal or run:"
info_bold " source $(tildify "$profile_file")"
fi
else
echo ""
info "Manually add the directory to your shell's PATH:"
info_bold " export PATH=\"\$PATH:$(tildify "$INSTALL_DIR")\""
fi
fi
echo ""
info "Run '$EXE_NAME' to get started!"
}
uninstall_termix() {
info "Starting Termix uninstallation..."
local exe_path="$INSTALL_DIR/$EXE_NAME"
if [ -f "$exe_path" ]; then
rm -f "$exe_path"
success "Termix has been uninstalled from $(tildify "$exe_path")"
else info "Termix not found. Nothing to do."; fi
local profile_file
profile_file=$(detect_profile)
if [ -n "$profile_file" ] && grep -q "# Added by Termix installer" "$profile_file"; then
echo ""
read -p "Found a Termix entry in '$(tildify "$profile_file")'. May we remove it? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
sed -i.bak -e '/# Added by Termix installer/,+1d' "$profile_file"
success "Removed PATH entry. A backup was created at $(tildify "${profile_file}.bak")."
fi
fi
}
detect_profile() {
local shell_name
shell_name=$(basename "$SHELL")
if [ "$shell_name" = "zsh" ]; then [ -f "$HOME/.zshrc" ] && echo "$HOME/.zshrc"; elif [ "$shell_name" = "bash" ]; then if [ -f "$HOME/.bashrc" ]; then echo "$HOME/.bashrc"; elif [ -f "$HOME/.bash_profile" ]; then echo "$HOME/.bash_profile"; fi; elif [ "$shell_name" = "fish" ]; then [ -f "$HOME/.config/fish/config.fish" ] && echo "$HOME/.config/fish/config.fish"; fi
}
if [ "${1:-}" = "uninstall" ]; then uninstall_termix; else install_termix "${1:-}"; fi