-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·276 lines (252 loc) · 9.95 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·276 lines (252 loc) · 9.95 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/bin/sh
# Mirai installer — multi-distro, standalone.
# Copyright (C) 2026 Leriart
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Supports: Arch, Manjaro, CachyOS, EndeavourOS, Garuda, Artix, Debian, Ubuntu,
# Fedora, openSUSE, Alpine, Void, NixOS, and generic fallback.
set -eu
REPO="${REPO:-https://github.com/Leriart/Mirai}"
BRANCH="${BRANCH:-main}"
PREFIX="${PREFIX:-/usr/local}"
PYTHON="${PYTHON:-python3}"
TMPDIR="${TMPDIR:-/tmp}"
SRC_DIR="$TMPDIR/mirai-install-$$"
info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33m==>\033[0m %s\n' "$*" >&2; }
error() { printf '\033[1;31m==> ERROR:\033[0m %s\n' "$*" >&2; exit 1; }
command_exists() { command -v "$1" >/dev/null 2>&1; }
detect_distro() {
if [ -r /etc/os-release ]; then
# shellcheck source=/dev/null
. /etc/os-release
# Use ID_LIKE when ID itself is not in our list (e.g. cachyos -> arch).
printf '%s' "${ID:-unknown}"
else
printf 'unknown'
fi
}
detect_distro_family() {
if [ -r /etc/os-release ]; then
# shellcheck source=/dev/null
. /etc/os-release
case " ${ID_LIKE:-} " in
*" arch "*) printf 'arch' ;;
*" debian "*) printf 'debian' ;;
*" fedora "*|*" rhel "*) printf 'fedora' ;;
*" suse "*) printf 'opensuse' ;;
*) printf 'unknown' ;;
esac
else
printf 'unknown'
fi
}
require_sudo() {
if [ "$(id -u)" -eq 0 ]; then
return 0
fi
if command_exists sudo; then
info "Requesting root privileges..."
sudo -v || error "Unable to obtain root privileges."
# Keep sudo alive while the script runs.
( while true; do sudo -n true; sleep 60; done ) >/dev/null 2>&1 &
SUDO_KEEPALIVE_PID=$!
trap 'kill "$SUDO_KEEPALIVE_PID" 2>/dev/null || true' EXIT
return 0
fi
error "This installer needs root privileges. Please install sudo or run as root."
}
maybe_sudo() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
else
sudo "$@"
fi
}
install_aur_deps() {
# Try to install the given AUR packages using the first AUR helper
# available (paru, yay, or a fresh yay-bin clone). Skips silently if
# none is available and the user is on a system that might not need them.
[ "$family" = "arch" ] || return 0
[ $# -gt 0 ] || return 0
# Detect which packages are still missing on the system.
local missing=()
local pkg
for pkg in "$@"; do
if ! command -v "${pkg%-git}" >/dev/null 2>&1 \
&& ! pacman -Qq "$pkg" >/dev/null 2>&1; then
missing+=("$pkg")
fi
done
[ ${#missing[@]} -gt 0 ] || return 0
# Pick an AUR helper. Prefer the user's installed one.
local helper=""
if command_exists paru; then
helper="paru"
elif command_exists yay; then
helper="yay"
fi
if [ -z "$helper" ]; then
info "AUR helper (paru / yay) not found — installing yay-bin…"
local YAY_TMP
YAY_TMP="$TMPDIR/yay-bin-$$"
if command_exists git && command_exists makepkg; then
git clone --depth 1 https://aur.archlinux.org/yay-bin.git "$YAY_TMP" 2>/dev/null || {
warn "Could not clone yay-bin. Install the AUR packages manually:"
printf ' %s\n' "${missing[@]}" >&2
return 1
}
( cd "$YAY_TMP" && maybe_sudo makepkg -si --noconfirm ) || {
warn "yay-bin build failed. Install the AUR packages manually:"
printf ' %s\n' "${missing[@]}" >&2
rm -rf "$YAY_TMP"
return 1
}
rm -rf "$YAY_TMP"
helper="yay"
else
warn "git or makepkg not found; cannot bootstrap an AUR helper."
printf ' %s\n' "${missing[@]}" >&2
return 1
fi
fi
info "Installing AUR packages with $helper: ${missing[*]}"
maybe_sudo "$helper" -S --needed --noconfirm "${missing[@]}" \
|| warn "AUR install failed for some packages. Install them manually:"
# Print the failed ones if any are still missing.
local still=()
for pkg in "${missing[@]}"; do
if ! command -v "${pkg%-git}" >/dev/null 2>&1 \
&& ! pacman -Qq "$pkg" >/dev/null 2>&1; then
still+=("$pkg")
fi
done
if [ ${#still[@]} -gt 0 ]; then
printf ' %s\n' "${still[@]}" >&2
return 1
fi
return 0
}
install_deps() {
distro="${1:-$(detect_distro)}"
family="${2:-$(detect_distro_family)}"
# Fallback to family when the exact distro is unknown but ID_LIKE matches.
if [ "$distro" = "unknown" ] && [ "$family" != "unknown" ]; then
distro="$family"
fi
info "Detected distribution: ${1:-$(detect_distro)} (family: $family)"
case "$distro" in
arch|manjaro|cachyos|endeavouros|garuda|artix)
command_exists pacman || { warn "pacman not found"; return; }
info "Installing dependencies with pacman..."
maybe_sudo pacman -S --needed --noconfirm \
python python-dbus wpa_supplicant \
gstreamer gst-plugins-base gst-plugins-good \
gst-plugins-bad gst-plugins-ugly gst-libav \
mpv networkmanager avahi || warn "Some pacman deps failed"
# miraclecast and gnome-network-displays are not in the official
# Arch / CachyOS / Manjaro repos. Fall back to an AUR helper
# (paru → yay → manual) so the install does not silently leave
# the Miracast stack half-installed.
install_aur_deps \
miraclecast-git \
gnome-network-displays
;;
debian|ubuntu|pop|mint|elementary|zorin|kali)
command_exists apt-get || { warn "apt-get not found"; return; }
info "Installing dependencies with apt..."
maybe_sudo apt-get update
maybe_sudo apt-get install -y \
python3 python3-dbus miraclecast wpasupplicant \
gstreamer1.0-tools gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly gstreamer1.0-libav \
gnome-network-displays mpv network-manager avahi-daemon || warn "Some deps failed"
;;
fedora|rhel|centos|almalinux|rocky)
if command_exists dnf; then
info "Installing dependencies with dnf..."
maybe_sudo dnf install -y \
python3 python3-dbus miraclecast wpa_supplicant \
gstreamer1 gstreamer1-plugins-base \
gstreamer1-plugins-good gstreamer1-plugins-bad-free \
gstreamer1-plugins-ugly gstreamer1-libav \
gnome-network-displays mpv NetworkManager avahi || warn "Some deps failed"
elif command_exists yum; then
maybe_sudo yum install -y \
python3 python3-dbus wpa_supplicant \
gstreamer1 gstreamer1-plugins-base \
gstreamer1-plugins-good gstreamer1-plugins-bad-free \
gstreamer1-plugins-ugly gstreamer1-libav \
mpv NetworkManager avahi || warn "Some deps failed"
fi
;;
opensuse|suse|tumbleweed|leap)
command_exists zypper || { warn "zypper not found"; return; }
info "Installing dependencies with zypper..."
maybe_sudo zypper --non-interactive install \
python3 python3-dbus miraclecast wpa_supplicant \
gstreamer gstreamer-plugins-base \
gstreamer-plugins-good gstreamer-plugins-bad \
gstreamer-plugins-ugly gstreamer-plugins-libav \
gnome-network-displays mpv NetworkManager avahi || warn "Some deps failed"
;;
alpine)
command_exists apk || { warn "apk not found"; return; }
info "Installing dependencies with apk..."
maybe_sudo apk add \
python3 py3-dbus miraclecast wpa_supplicant \
gstreamer gst-plugins-base gst-plugins-good \
gst-plugins-bad gst-plugins-ugly gst-libav \
mpv networkmanager avahi || warn "Some deps failed"
;;
void)
command_exists xbps-install || { warn "xbps-install not found"; return; }
info "Installing dependencies with xbps..."
maybe_sudo xbps-install -Sy \
python3 python3-dbus miraclecast wpa_supplicant \
gstreamer gst-plugins-base1 gst-plugins-good1 \
gst-plugins-bad1 gst-plugins-ugly1 gst-libav \
mpv NetworkManager avahi || warn "Some deps failed"
;;
nixos)
warn "NixOS detected."
warn "Please use the flake instead: nix run github:Leriart/Mirai"
warn "Or add the NixOS module from the repository."
;;
*)
warn "Unknown distribution. Please install dependencies manually."
warn "See README.md#dependencies for the list."
;;
esac
}
clone_and_install() {
[ -d "$SRC_DIR" ] && rm -rf "$SRC_DIR"
if command_exists git; then
info "Cloning Mirai from $REPO ($BRANCH)..."
git clone --depth 1 --branch "$BRANCH" "$REPO" "$SRC_DIR"
else
info "Downloading Mirai archive..."
mkdir -p "$SRC_DIR"
curl -fsSL "$REPO/archive/refs/heads/$BRANCH.tar.gz" | tar -xz -C "$SRC_DIR" --strip-components=1
fi
cd "$SRC_DIR"
info "Installing Mirai to $PREFIX..."
maybe_sudo make install PREFIX="$PREFIX"
info "Mirai installed successfully."
info "Start the daemon with: sudo mirai daemon"
}
cleanup() {
if [ -d "$SRC_DIR" ]; then
maybe_sudo rm -rf "$SRC_DIR"
fi
}
trap cleanup EXIT
main() {
require_sudo
if [ "${SKIP_DEPS:-0}" != "1" ]; then
install_deps "$(detect_distro)" "$(detect_distro_family)"
fi
clone_and_install
}
main "$@"