Files
hyprland-hdmi-revive/scripts/install.sh
T

73 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
START_SERVICE=0
case "${1:-}" in
'') ;;
--start) START_SERVICE=1 ;;
--help) printf 'Usage: %s [--start]\nInstall for the current user; --start also enables and restarts the service.\n' "$0"; exit 0 ;;
*) printf 'Unknown argument: %s\n' "$1" >&2; exit 2 ;;
esac
(( $# <= 1 )) || { printf 'Too many arguments\n' >&2; exit 2; }
if (( EUID == 0 )); then
printf 'Run this installer as the desktop user, without sudo.\n' >&2
exit 1
fi
REPO_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
BIN_DIR="$HOME/.local/bin"
LIB_DIR="$HOME/.local/lib/hyprland-hdmi-revive"
CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
[[ "$CONFIG_HOME" == /* ]] || { printf 'XDG_CONFIG_HOME must be absolute\n' >&2; exit 1; }
SYSTEMD_DIR="$CONFIG_HOME/systemd/user"
CONFIG_DIR="$CONFIG_HOME/revive-monitor"
LOGTAG=revive-monitor-install
# shellcheck source=lib/common.sh
source "$REPO_ROOT/lib/common.sh"
require_commands systemctl udevadm stdbuf timeout loginctl hyprctl jq flock sudo stat install || exit 1
[[ -x /usr/bin/chvt ]] || { printf 'Missing /usr/bin/chvt (Arch package: kbd)\n' >&2; exit 1; }
# Validate existing config before overwriting any installed files.
load_config || exit 1
if (( START_SERVICE )); then
[[ -n "${HYPRLAND_INSTANCE_SIGNATURE:-}" ]] || {
printf 'Use --start from a terminal inside Hyprland.\n' >&2; exit 1;
}
fi
# Avoid replacing Bash files while a running watcher/recovery is reading them.
if systemctl --user is-active --quiet revive-monitor-drm-watch.service; then
systemctl --user stop revive-monitor-drm-watch.service
fi
mkdir -p -- "$BIN_DIR" "$LIB_DIR" "$SYSTEMD_DIR" "$CONFIG_DIR"
install -m 0755 "$REPO_ROOT/scripts/revive-monitor-fix.sh" "$BIN_DIR/revive-monitor-fix"
install -m 0755 "$REPO_ROOT/scripts/revive-monitor-drm-watch.sh" "$BIN_DIR/revive-monitor-drm-watch"
install -m 0644 "$REPO_ROOT/lib/common.sh" "$LIB_DIR/common.sh"
install -m 0644 "$REPO_ROOT/systemd/user/revive-monitor-drm-watch.service" "$SYSTEMD_DIR/revive-monitor-drm-watch.service"
if [[ ! -e "$CONFIG_DIR/config.env" ]]; then
install -m 0600 "$REPO_ROOT/config/revive-monitor.env.example" "$CONFIG_DIR/config.env"
printf 'Created %s\n' "$CONFIG_DIR/config.env"
else
printf 'Keeping existing config: %s\n' "$CONFIG_DIR/config.env"
fi
if (( START_SERVICE )); then
systemctl --user import-environment HYPRLAND_INSTANCE_SIGNATURE
# Keep the service and installer on the same configuration root.
export XDG_CONFIG_HOME="$CONFIG_HOME"
systemctl --user import-environment XDG_CONFIG_HOME
systemctl --user daemon-reload
systemctl --user enable revive-monitor-drm-watch.service
systemctl --user restart revive-monitor-drm-watch.service
systemctl --user is-active --quiet revive-monitor-drm-watch.service
else
printf 'Files installed. Activation is explicit; follow README.md before starting.\n'
fi
cat <<'MSG'
Next steps:
1. Set MONITOR in ${XDG_CONFIG_HOME:-$HOME/.config}/revive-monitor/config.env
2. Configure chvt permission with visudo using the sudoers/ templates.
3. Add the Hyprland environment/start hook documented in README.md.
4. Run ./scripts/install.sh --start from Hyprland to activate or update.
5. Check: journalctl --user -u revive-monitor-drm-watch.service -b
MSG