-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·193 lines (161 loc) · 4.91 KB
/
install.sh
File metadata and controls
executable file
·193 lines (161 loc) · 4.91 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/sh
set -eu
REPO="mesa-dot-dev/mesafs"
BREW_TAP="mesa-dot-dev/tap"
AUTO_YES=false
INSTALL_TMPDIR=""
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
BOLD='\033[1m'
RESET='\033[0m'
else
RED='' GREEN='' CYAN='' YELLOW='' BOLD='' RESET=''
fi
info() { printf "%b-->%b %b\n" "${CYAN}" "${RESET}" "$1"; }
success() { printf "%b-->%b %b\n" "${GREEN}" "${RESET}" "$1"; }
warn() { printf "%b-->%b %b\n" "${YELLOW}" "${RESET}" "$1" >&2; }
error() { printf "%b-->%b %b\n" "${RED}" "${RESET}" "$1" >&2; exit 1; }
cleanup() {
if [ -n "${INSTALL_TMPDIR}" ] && [ -d "${INSTALL_TMPDIR}" ]; then
rm -rf "${INSTALL_TMPDIR}"
fi
}
trap cleanup EXIT
sudo_cmd() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
else
sudo "$@"
fi
}
parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
-y|--yes) AUTO_YES=true ;;
-h|--help)
printf "Usage: install.sh [OPTIONS]\n\n"
printf "Install or update mesafs.\n\n"
printf "Options:\n"
printf " -y, --yes Non-interactive mode (use defaults, requires root)\n"
printf " -h, --help Show this help message\n"
exit 0
;;
*) error "Unknown option: $1 (use -h for help)" ;;
esac
shift
done
}
detect_os() {
case "$(uname -s)" in
Darwin) OS="macos" ;;
Linux) OS="linux" ;;
*) error "Unsupported operating system: $(uname -s)" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*) error "Unsupported architecture: $(uname -m)" ;;
esac
}
# --- macOS (Homebrew) ---
install_macos() {
if ! command -v brew >/dev/null 2>&1; then
error "Homebrew is required but not found. Install it from https://brew.sh"
fi
_formula="${BREW_TAP}/mesafs"
_formula_name="mesafs"
if ! brew tap | grep -q "^${BREW_TAP}$"; then
info "Adding Homebrew tap ${BREW_TAP}..."
brew tap "${BREW_TAP}"
fi
if brew list --formula "${_formula_name}" >/dev/null 2>&1; then
info "mesafs is already installed. Upgrading..."
brew upgrade "${_formula}" || info "mesafs is already up to date."
else
info "Installing mesafs..."
brew install "${_formula}"
fi
}
# --- Linux (deb from GitHub Releases) ---
build_download_url() {
_arch="$1"
_filename="mesafs_${_arch}.deb"
echo "https://github.com/${REPO}/releases/latest/download/${_filename}"
}
install_deb_native() {
_filepath="$1"
if command -v apt >/dev/null 2>&1; then
info "Installing with apt..."
sudo_cmd apt install -y "${_filepath}"
elif command -v dpkg >/dev/null 2>&1; then
info "Installing with dpkg..."
if ! sudo_cmd dpkg -i "${_filepath}"; then
warn "dpkg reported dependency issues, attempting to resolve..."
sudo_cmd apt-get install -f -y || return 1
fi
else
return 1
fi
}
install_deb_extract() {
_filepath="$1"
if ! command -v ar >/dev/null 2>&1; then
error "Cannot install: no apt, dpkg, or ar found. Install one of these and retry."
fi
info "Extracting binary from deb package..."
_extract_dir="${INSTALL_TMPDIR}/extract"
mkdir -p "${_extract_dir}"
cd "${_extract_dir}"
ar x "${_filepath}"
tar xf data.tar.* ./usr/bin/mesafs
sudo_cmd install -m 755 ./usr/bin/mesafs /usr/local/bin/mesafs
cd /
warn "Note: mesafs requires FUSE3. Install it with your package manager if not already present."
}
install_linux() {
if ! command -v curl >/dev/null 2>&1; then
error "curl is required but not found. Install it with your package manager."
fi
_arch=$(detect_arch)
_url=$(build_download_url "${_arch}")
_filename="mesafs_${_arch}.deb"
if [ "${AUTO_YES}" = true ] && [ "$(id -u)" -ne 0 ]; then
error "Non-interactive mode requires root. Re-run with: sudo $0 --yes"
fi
INSTALL_TMPDIR=$(mktemp -d)
info "Downloading ${_filename}..."
curl -fSL -o "${INSTALL_TMPDIR}/${_filename}" "${_url}" \
|| error "Download failed. Check your internet connection and try again."
if ! install_deb_native "${INSTALL_TMPDIR}/${_filename}"; then
install_deb_extract "${INSTALL_TMPDIR}/${_filename}"
fi
}
# --- Main ---
verify_install() {
if command -v mesafs >/dev/null 2>&1; then
_version=$(mesafs --version 2>/dev/null || echo "unknown")
success "mesafs installed successfully! (${_version})"
else
success "mesafs installed successfully!"
fi
}
main() {
parse_args "$@"
printf "\n"
info "${BOLD}mesafs installer${RESET}"
printf "\n"
detect_os
if [ "${OS}" = "macos" ]; then
install_macos
else
install_linux
fi
verify_install
printf "\n"
}
main "$@"