diff --git a/package.json b/package.json index ea4ee89..58aad10 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "dev": "vite", "build": "tsc && vite build", "preview": "vite preview", - "tauri": "tauri" + "tauri": "tauri", + "deps:check": "bash scripts/tauri-system-deps.sh check", + "deps:install": "bash scripts/tauri-system-deps.sh install" }, "dependencies": { "@tauri-apps/api": "^2.10.1", diff --git a/scripts/tauri-system-deps.sh b/scripts/tauri-system-deps.sh new file mode 100755 index 0000000..86326a9 --- /dev/null +++ b/scripts/tauri-system-deps.sh @@ -0,0 +1,132 @@ +#!/usr/bin/env bash +set -euo pipefail + +SCRIPT_NAME="$(basename "$0")" + +PKGCONFIG_MODULES=( + "webkit2gtk-4.1" + "libsoup-3.0" + "javascriptcoregtk-4.1" +) + +DEBIAN_PACKAGES=( + "pkg-config" + "libwebkit2gtk-4.1-dev" + "libsoup-3.0-dev" + "libjavascriptcoregtk-4.1-dev" +) + +usage() { + cat </dev/null 2>&1; then + missing+=("pkg-config (command not found)") + else + for module in "${PKGCONFIG_MODULES[@]}"; do + if ! pkg-config --exists "$module"; then + missing+=("$module") + fi + done + fi + + if [ "${#missing[@]}" -eq 0 ]; then + echo "All required system dependencies are installed." + return 0 + fi + + echo "Missing system dependencies:" + for dep in "${missing[@]}"; do + echo " - $dep" + done + + print_missing_hint + return 1 +} + +install_deps_debian() { + local prefix=() + + if [ "${EUID}" -ne 0 ]; then + if command -v sudo >/dev/null 2>&1; then + prefix=(sudo) + else + echo "Error: need root privileges (run as root or install sudo)." >&2 + return 1 + fi + fi + + echo "Installing Debian/Ubuntu packages: ${DEBIAN_PACKAGES[*]}" + "${prefix[@]}" apt-get update + "${prefix[@]}" apt-get install -y "${DEBIAN_PACKAGES[@]}" +} + +install_deps() { + if [ ! -f /etc/os-release ]; then + echo "Unsupported OS: /etc/os-release not found." >&2 + print_missing_hint + return 1 + fi + + # shellcheck source=/dev/null + . /etc/os-release + + case "${ID:-}" in + ubuntu|debian|linuxmint|pop) + install_deps_debian + ;; + *) + if echo "${ID_LIKE:-}" | grep -qi "debian"; then + install_deps_debian + else + echo "Unsupported distro for auto-install: ${ID:-unknown}" >&2 + echo "Please install packages manually for your distro." + print_missing_hint + return 1 + fi + ;; + esac + + echo + check_deps +} + +main() { + local cmd="${1:-check}" + + case "$cmd" in + check) + check_deps + ;; + install) + install_deps + ;; + help|-h|--help) + usage + ;; + *) + echo "Unknown command: $cmd" >&2 + usage >&2 + return 2 + ;; + esac +} + +main "$@"