Skip to content

Instantly share code, notes, and snippets.

@mal1k-me
Last active November 20, 2025 23:39
Show Gist options
  • Select an option

  • Save mal1k-me/0bb423781896ca0865fd95e92a1c5fbb to your computer and use it in GitHub Desktop.

Select an option

Save mal1k-me/0bb423781896ca0865fd95e92a1c5fbb to your computer and use it in GitHub Desktop.
Install XLibre's X Server on Chimera Linux
#!/usr/bin/env bash
set -euo pipefail
BASE_DIR="/srv/xlibre/website/chimera/main/x86_64"
PORT=47188
REPO_URL="http://localhost:$PORT/website/chimera/main"
APK_REPOS="/etc/apk/repositories"
# Check for root privileges
if [[ $EUID -ne 0 ]]; then
if command -v sudo &>/dev/null; then
echo "Script requires root privileges. Re-running with sudo..."
exec sudo bash "$0" "$@"
elif command -v doas &>/dev/null; then
echo "Script requires root privileges. Re-running with doas..."
exec doas bash "$0" "$@"
else
echo "ERROR: This script requires root privileges." >&2
exit 1
fi
fi
# Check if port is busy
if ss -tulpn 2>/dev/null | grep -q ":$PORT "; then
PID=$(ss -tulpn 2>/dev/null | grep ":$PORT " | awk '{print $7}' | cut -d',' -f2)
echo "ERROR: Port $PORT is already in use by PID $PID. Please free the port before running this script." >&2
exit 1
fi
echo "Downloading files from GitHub..."
rm -rf "$BASE_DIR/*"
curl -s "https://api.github.com/repos/xlibre-alpine/website/contents/chimera/main/x86_64" |
jq -r '.[] | select(.type=="file") | .download_url' |
xargs -n1 -P4 wget -q -P "$BASE_DIR"
echo "Starting Python HTTP server on port $PORT..."
cd /srv/xlibre
python3 -m http.server -b localhost "$PORT" >/dev/null 2>&1 &
PYTHON_PID=$!
# Trap to kill python server on script exit
cleanup() {
echo "Stopping Python HTTP server (PID $PYTHON_PID)..."
kill "$PYTHON_PID" 2>/dev/null || true
SED_INPLACE=(-i)
if sed --version >/dev/null 2>&1; then
: # GNU sed
else
SED_INPLACE=(-i '') # BSD sed
fi
sed "${SED_INPLACE[@]}" "\|^http://localhost:${PORT}/website/chimera/main$|d" /etc/apk/repositories
rm -rf /srv/xlibre
}
trap cleanup EXIT
# Add local repo URL to apk repositories if missing
wget -q -O /etc/apk/keys/xlibre.rsa.pub https://raw.githubusercontent.com/xlibre-alpine/website/refs/heads/main/main/xlibre.rsa.pub
if ! grep -Fxq "$REPO_URL" "$APK_REPOS"; then
echo "Adding local repo $REPO_URL to $APK_REPOS..."
echo "$REPO_URL" >>"$APK_REPOS"
fi
found=0
for _ in {1..5}; do
if curl --silent --head --fail "http://localhost:$PORT/website/chimera/main/x86_64/APKINDEX.tar.gz" >/dev/null; then
found=1
break
fi
sleep 1
done
if [ $found -eq 0 ]; then
echo "ERROR: HTTP server not responding with APKINDEX.tar.gz after waiting. Exiting." >&2
exit 1
fi
echo "Updating apk package index..."
apk update
echo "Installing xserver-xlibre package..."
apk add xserver-xlibre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment