#!/usr/bin/env bash # Installation logic for shepherd-launcher # Handles binary installation, config deployment, and desktop entry setup # Get the directory containing this script INSTALL_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Source common utilities # shellcheck source=common.sh source "$INSTALL_LIB_DIR/common.sh" # Source build utilities for binary paths # shellcheck source=build.sh source "$INSTALL_LIB_DIR/build.sh" # Default installation paths DEFAULT_PREFIX="/usr/local" DEFAULT_BINDIR="bin" # Standard sway config location SWAY_CONFIG_DIR="/etc/sway" SHEPHERD_SWAY_CONFIG="shepherd.conf" # Desktop entry location DESKTOP_ENTRY_DIR="share/wayland-sessions" DESKTOP_ENTRY_NAME="shepherd.desktop" # Install release binaries install_bins() { local prefix="${1:-$DEFAULT_PREFIX}" local destdir="${DESTDIR:-}" require_root local bindir="$destdir$prefix/$DEFAULT_BINDIR" local target_dir target_dir="$(get_target_dir true)" # Ensure release build exists if ! binaries_exist true; then die "Release binaries not found. Run 'shepherd build --release' first." fi info "Installing binaries to $bindir..." ensure_dir "$bindir" 0755 for binary in "${SHEPHERD_BINARIES[@]}"; do local src="$target_dir/$binary" local dst="$bindir/$binary" info " Installing $binary..." install -m 0755 "$src" "$dst" done success "Installed binaries to $bindir" } # Install the sway configuration install_sway_config() { local destdir="${DESTDIR:-}" local repo_root repo_root="$(get_repo_root)" require_root local src_config="$repo_root/sway.conf" local dst_dir="$destdir$SWAY_CONFIG_DIR" local dst_config="$dst_dir/$SHEPHERD_SWAY_CONFIG" if [[ ! -f "$src_config" ]]; then die "Source sway.conf not found at $src_config" fi info "Installing sway configuration to $dst_config..." ensure_dir "$dst_dir" 0755 # Create a production version of the sway config # Replace debug paths with installed paths local prefix="${1:-$DEFAULT_PREFIX}" local bindir="$prefix/$DEFAULT_BINDIR" # Copy and modify the config for production use sed \ -e "s|./target/debug/shepherd-launcher|$bindir/shepherd-launcher|g" \ -e "s|./target/debug/shepherd-hud|$bindir/shepherd-hud|g" \ -e "s|./target/debug/shepherdd|$bindir/shepherdd|g" \ -e "s|./config.example.toml|~/.config/shepherd/config.toml|g" \ -e "s|-c ./sway.conf|-c $dst_config|g" \ "$src_config" > "$dst_config" chmod 0644 "$dst_config" success "Installed sway configuration" } # Install desktop entry for display manager install_desktop_entry() { local prefix="${1:-$DEFAULT_PREFIX}" local destdir="${DESTDIR:-}" require_root local dst_dir="$destdir$prefix/$DESKTOP_ENTRY_DIR" local dst_entry="$dst_dir/$DESKTOP_ENTRY_NAME" info "Installing desktop entry to $dst_entry..." ensure_dir "$dst_dir" 0755 cat > "$dst_entry" < [OPTIONS] Commands: bins Install release binaries config Deploy user configuration sway-config Install sway configuration desktop-entry Install display manager desktop entry all Install everything Options: --user USER Target user for config deployment (required for config/all) --prefix PREFIX Installation prefix (default: $DEFAULT_PREFIX) --source CONFIG Source config file (default: config.example.toml) --force, -f Overwrite existing configuration files Environment: DESTDIR Installation root for packaging (default: empty) Examples: shepherd install bins --prefix /usr/local shepherd install config --user kiosk shepherd install config --user kiosk --force shepherd install all --user kiosk --prefix /usr EOF ;; *) die "Unknown install command: $subcmd (try: shepherd install help)" ;; esac }