This repository was archived by the owner on Feb 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-cli
More file actions
248 lines (215 loc) · 10.2 KB
/
install-cli
File metadata and controls
248 lines (215 loc) · 10.2 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
#!/usr/bin/env bash
set -euo pipefail
Color_Off=''
Red=''
Green=''
Dim=''
Bold_White=''
Yellow=''
if [[ -t 1 ]]; then
Color_Off='\033[0m'
Red='\033[0;31m'
Green='\033[0;32m'
Dim='\033[0;2m'
Bold_White='\033[1m'
Yellow='\033[0;33m'
fi
error() { echo -e "${Red}error${Color_Off}: $*" >&2; }
info() { echo -e "${Dim}$*${Color_Off}"; }
info_bold() { echo -e "${Bold_White}$*${Color_Off}"; }
success() { echo -e "${Green}$*${Color_Off}"; }
warn() { echo -e "${Yellow}warning${Color_Off}: $*"; }
MIN_GLIBC_VERSION="2.35"
check_glibc_version() {
info "--> Checking operating system compatibility (GLIBC version)..."
local glibc_version
glibc_version=$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $NF}' || echo "0.0")
if [[ "$glibc_version" == "0.0" ]]; then
warn "Could not determine GLIBC version. Compatibility cannot be guaranteed."
return
fi
if ! printf '%s\n' "$MIN_GLIBC_VERSION" "$glibc_version" | sort -V -C; then
error "Your operating system is not supported."
echo
info "The Wayclip binaries require GLIBC version ${MIN_GLIBC_VERSION} or newer, but your system has version ${glibc_version}."
info_bold "This script cannot proceed."
exit 1
fi
success "GLIBC version ($glibc_version) is compatible."
}
check_media_libs() {
info "--> Checking for required media libraries and encoders..."
info "--> Clearing GStreamer cache for a fresh check..."
rm -rf "${HOME}/.cache/gstreamer-1.0"
if gst-inspect-1.0 nvh264enc >/dev/null 2>&1; then
success "Hardware encoding detected: NVIDIA NVENC (nvh264enc) is available."
if lspci | grep -qi 'VGA.*NVIDIA' && command -v nvidia-smi &>/dev/null; then
info "--> Checking NVIDIA driver status..."
if ! nvidia_smi_output=$(nvidia-smi 2>&1); then
if echo "$nvidia_smi_output" | grep -qi "Driver/library version mismatch"; then
warn "NVIDIA driver/library version mismatch detected."
info "This commonly occurs after a system or kernel update. Please REBOOT to fix it."
else
warn "The 'nvidia-smi' command failed, indicating a potential driver issue."
fi
else
success "NVIDIA driver appears to be operational."
fi
fi
return
elif gst-inspect-1.0 vaapih264enc >/dev/null 2>&1; then
success "Hardware encoding detected: VA-API (vaapih264enc) is available for AMD/Intel."
return
elif gst-inspect-1.0 x264enc >/dev/null 2>&1; then
success "Software encoding fallback detected: x264enc is available."
warn "For better performance, consider installing hardware-specific GStreamer plugins."
return
fi
warn "No suitable GStreamer H.264 encoder found (nvh264enc, vaapih264enc, x264enc)."
info_bold "Attempting to guide installation of required GStreamer plugins..."
echo
if command -v pacman >/dev/null; then
info_bold "Arch Linux detected."
if lspci | grep -qi 'VGA.*NVIDIA'; then
info "NVIDIA GPU detected. The 'gstreamer-nvidia' package from the AUR is required for hardware encoding."
AUR_HELPER=""
if command -v yay >/dev/null 2>&1; then
AUR_HELPER="yay"
elif command -v paru >/dev/null 2>&1; then AUR_HELPER="paru"; fi
if [[ -n "$AUR_HELPER" ]]; then
read -p "Install 'gstreamer-nvidia' using '$AUR_HELPER' now? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
if ! $AUR_HELPER -S --needed gstreamer-nvidia; then
error "AUR helper failed to install 'gstreamer-nvidia'."
exit 1
fi
else
info "Installation cancelled. Please install 'gstreamer-nvidia' manually."
exit 1
fi
else
warn "No common AUR helper (yay, paru) found. Please install 'gstreamer-nvidia' manually from the AUR."
exit 1
fi
elif lspci | grep -qi 'VGA.*\(AMD\|Intel\)'; then
info "AMD/Intel GPU detected. Installing VA-API plugins..."
if ! sudo pacman -S --needed --noconfirm gstreamer-vaapi; then
error "Failed to install 'gstreamer-vaapi'."
exit 1
fi
else
info "No specific supported GPU detected. Installing software encoder..."
if ! sudo pacman -S --needed --noconfirm gst-plugins-ugly; then
error "Failed to install 'gst-plugins-ugly' for software encoding."
exit 1
fi
fi
elif command -v apt-get >/dev/null; then
info_bold "Debian/Ubuntu detected. Installing required GStreamer packages..."
if ! (sudo apt-get update && sudo apt-get install -y gstreamer1.0-plugins-bad gstreamer1.0-vaapi gstreamer1.0-plugins-ugly); then
error "Failed to install GStreamer packages. Please run the command manually."
exit 1
fi
elif command -v dnf >/dev/null; then
info_bold "Fedora detected. Installing required GStreamer packages from RPM Fusion..."
sudo dnf install -y \
"https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm" \
"https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm"
if ! sudo dnf install -y gstreamer1-plugins-bad-freeworld gstreamer1-vaapi gstreamer1-plugins-ugly; then
error "Failed to install GStreamer packages. Please run the command manually."
exit 1
fi
else
error "Could not detect a supported package manager."
info "Please install GStreamer plugins for NVIDIA (nvh264enc), VA-API (vaapih264enc), or x264 (x264enc) for your distribution."
exit 1
fi
info "--> Re-checking for plugins after installation..."
rm -rf "${HOME}/.cache/gstreamer-1.0"
if gst-inspect-1.0 nvh264enc >/dev/null 2>&1 || gst-inspect-1.0 vaapih264enc >/dev/null 2>&1 || gst-inspect-1.0 x264enc >/dev/null 2>&1; then
success "GStreamer plugins are now available."
else
error "Plugins are still not available after installation attempt."
info "Please ensure the installation was successful and that your drivers are correctly configured."
exit 1
fi
}
if command -v wayclip-cli >/dev/null; then
INSTALLED_PATH=$(command -v wayclip-cli)
if [[ "$INSTALLED_PATH" != "$HOME/.local/bin"* ]]; then
success "Wayclip is already installed system-wide at: $INSTALLED_PATH"
info "Please use your system package manager to update or remove it."
exit 0
fi
fi
for cmd in curl jq lspci gst-inspect-1.0; do
if ! command -v "$cmd" >/dev/null 2>&1; then
error "Required command '$cmd' not found. Please install it first."
exit 1
fi
done
check_glibc_version
check_media_libs
echo
CLI_REPO="Wayclip/cli"
CORE_REPO="Wayclip/core"
INSTALL_DIR="${WAYCLIP_INSTALL_DIR:-$HOME/.local/bin}"
info_bold "Starting Wayclip installation..."
mkdir -p "$INSTALL_DIR"
TMP_DIR=$(mktemp -d)
info "--> Fetching latest CLI release information..."
CLI_API_URL="https://api.github.com/repos/${CLI_REPO}/releases/latest"
CLI_RELEASE_DATA=$(curl -s "$CLI_API_URL")
CLI_VERSION=$(echo "$CLI_RELEASE_DATA" | jq -r '.tag_name')
info "--> Downloading CLI binary..."
CLI_BINARY_URL=$(echo "$CLI_RELEASE_DATA" | jq -r '.assets[] | select(.name == "wayclip-cli-x86_64-unknown-linux-gnu") | .browser_download_url')
[[ -z "$CLI_BINARY_URL" ]] && error "Could not find a downloadable CLI binary." && exit 1
curl -L --progress-bar -o "${INSTALL_DIR}/wayclip-cli" "$CLI_BINARY_URL"
chmod +x "${INSTALL_DIR}/wayclip-cli"
success "Installed CLI ${CLI_VERSION} → ${INSTALL_DIR}/wayclip-cli"
echo
info "--> Downloading and installing systemd service..."
SERVICE_URL=$(echo "$CLI_RELEASE_DATA" | jq -r '.assets[] | select(.name == "wayclip-daemon.service") | .browser_download_url')
[[ -z "$SERVICE_URL" ]] && error "Could not find the systemd service file." && exit 1
SERVICE_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
mkdir -p "$SERVICE_DIR"
info "Setting ExecStart path to ${INSTALL_DIR}/wayclip-daemon"
curl -sL "$SERVICE_URL" | sed "s|^ExecStart=.*|ExecStart=${INSTALL_DIR}/wayclip-daemon|" >"${SERVICE_DIR}/wayclip-daemon.service"
chmod 644 "${SERVICE_DIR}/wayclip-daemon.service"
systemctl --user daemon-reload
success "Installed and reloaded systemd service → ${SERVICE_DIR}/wayclip-daemon.service"
echo
info "--> Fetching core components..."
CORE_API_URL="https://api.github.com/repos/${CORE_REPO}/releases/latest"
CORE_TARBALL_PATTERN="^wayclip-v.*-x86_64-unknown-linux-gnu\\.tar\\.gz$"
CORE_DOWNLOAD_URL=$(curl -s "$CORE_API_URL" | jq -r --arg pattern "$CORE_TARBALL_PATTERN" \
'.assets[] | select(.name | test($pattern)) | .browser_download_url')
CORE_VERSION=$(curl -s "$CORE_API_URL" | jq -r '.tag_name')
[[ -z "$CORE_DOWNLOAD_URL" ]] && error "Could not find a downloadable core components release." && exit 1
info "Downloading core components version ${CORE_VERSION}..."
CORE_TARBALL_PATH="${TMP_DIR}/core.tar.gz"
curl -L --progress-bar -o "$CORE_TARBALL_PATH" "$CORE_DOWNLOAD_URL"
info "Extracting and installing core components..."
tar -xzf "$CORE_TARBALL_PATH" -C "$TMP_DIR"
install -m 755 "${TMP_DIR}/wayclip-binaries/daemon" "${INSTALL_DIR}/wayclip-daemon"
install -m 755 "${TMP_DIR}/wayclip-binaries/trigger" "${INSTALL_DIR}/wayclip-trigger"
success "Installed daemon ${CORE_VERSION} → ${INSTALL_DIR}/wayclip-daemon"
success "Installed trigger ${CORE_VERSION} → ${INSTALL_DIR}/wayclip-trigger"
rm -rf "$TMP_DIR"
case ":$PATH:" in
*":$HOME/.local/bin:"*) : ;;
*)
echo
warn "$HOME/.local/bin is not in your PATH."
warn "Add this to your shell config (e.g., ~/.bashrc or ~/.zshrc):"
info_bold " export PATH=\"\$HOME/.local/bin:\$PATH\""
warn "Then, restart your shell or run 'source ~/.bashrc' for the change to take effect."
;;
esac
echo
success "Wayclip installed successfully!"
info_bold "Start and check daemon status with:"
info_bold " wayclip-cli daemon start"
info_bold " wayclip-cli daemon status"
echo