From 7d2c10fe11f488c0895a7d863b4812a0017ae781 Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Tue, 7 Oct 2025 18:18:20 -0500 Subject: [PATCH] added install and uninstall scripts with systemd configuration --- rewrite/README.md | 129 +++++++++++++++++++++- rewrite/scripts/install.sh | 106 ++++++++++++++++++ rewrite/scripts/uninstall.sh | 82 ++++++++++++++ rewrite/systemd/redshift-rebooted.service | 12 ++ 4 files changed, 327 insertions(+), 2 deletions(-) create mode 100755 rewrite/scripts/install.sh create mode 100755 rewrite/scripts/uninstall.sh create mode 100644 rewrite/systemd/redshift-rebooted.service diff --git a/rewrite/README.md b/rewrite/README.md index fc5bfe9..1e43d82 100644 --- a/rewrite/README.md +++ b/rewrite/README.md @@ -33,6 +33,76 @@ cd rewrite cargo build --release ``` +## Installation + +### Quick Install (User Mode - Recommended) + +The easiest way to install redshift-rebooted is using the installation script: + +```bash +cd rewrite +./scripts/install.sh +``` + +This will: +1. Build the release binary +2. Install to `~/.local/bin/redshift-rebooted` +3. Install systemd user service to `~/.config/systemd/user/` +4. Provide instructions for enabling and starting the service + +### System-Wide Installation + +For system-wide installation (requires root): + +```bash +cd rewrite +sudo ./scripts/install.sh --system +``` + +This installs: +- Binary to `/usr/bin/redshift-rebooted` +- Systemd service to `/usr/lib/systemd/user/` (still runs as user service) + +### Starting the Service + +After installation, enable and start the service: + +```bash +# Enable service to start automatically at login +systemctl --user enable redshift-rebooted + +# Start the service now +systemctl --user start redshift-rebooted + +# Check service status +systemctl --user status redshift-rebooted + +# View logs +journalctl --user -u redshift-rebooted -f +``` + +### Uninstallation + +To uninstall redshift-rebooted: + +```bash +# User mode +./scripts/uninstall.sh + +# System mode +sudo ./scripts/uninstall.sh --system +``` + +### Configuration + +Before starting the service, configure your location in `~/.config/redshift/redshift.conf`. See [redshift.conf.sample](redshift.conf.sample) for an example configuration. + +The service will automatically: +- Start when you log in (if enabled) +- Restart on failure +- Run in the background continuously +- Adjust screen temperature based on time of day + ## Usage The basic command matches the legacy C version: @@ -97,6 +167,61 @@ src/ - Currently implements manual provider (user-specified lat/lon) - Ready for additional provider: GeoClue2 +## Systemd Service + +The systemd service integration allows redshift-rebooted to run automatically in the background: + +### Service Features + +- **Automatic startup**: Starts at login when enabled +- **Auto-restart**: Restarts automatically if it crashes (3-second delay) +- **User service**: Runs as your user account with display access +- **Graphical session**: Only starts after graphical session is available + +### Service Management + +```bash +# Enable auto-start at login +systemctl --user enable redshift-rebooted + +# Start immediately +systemctl --user start redshift-rebooted + +# Stop the service +systemctl --user stop redshift-rebooted + +# Disable auto-start +systemctl --user disable redshift-rebooted + +# Restart after config changes +systemctl --user restart redshift-rebooted + +# View status and recent logs +systemctl --user status redshift-rebooted + +# Follow logs in real-time +journalctl --user -u redshift-rebooted -f + +# View all logs +journalctl --user -u redshift-rebooted +``` + +### Troubleshooting + +**Service fails to start:** +- Check logs: `journalctl --user -u redshift-rebooted` +- Verify configuration file exists: `~/.config/redshift/redshift.conf` +- Test manually: `redshift-rebooted -v` to see errors + +**Screen temperature not changing:** +- Ensure you're using the correct gamma method for your system +- Check that location is configured correctly +- Verify service is running: `systemctl --user status redshift-rebooted` + +**Service not starting at login:** +- Enable the service: `systemctl --user enable redshift-rebooted` +- Ensure systemd user services are enabled (should be default on most systems) + ## Next Steps To complete the rewrite, the following work remains: @@ -107,8 +232,8 @@ To complete the rewrite, the following work remains: - VidMode (X11 VidMode extension, legacy, single output) 2. **Additional Location Provider** - Port automatic location detection: - GeoClue2 (Linux location service) -3. **Configuration File Support** - Parse and apply INI-style config files -4. **Signal Handling** - Respond to SIGUSR1 (toggle), SIGINT/SIGTERM (restore & exit) +3. ~~**Configuration File Support**~~ ✅ Complete - INI-style config files supported +4. ~~**Signal Handling**~~ ✅ Complete - SIGUSR1 (toggle), SIGINT/SIGTERM (restore & exit) 5. **Hook Scripts** - Execute user scripts on period changes ## Testing diff --git a/rewrite/scripts/install.sh b/rewrite/scripts/install.sh new file mode 100755 index 0000000..7425ea1 --- /dev/null +++ b/rewrite/scripts/install.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Determine script directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" + +# Default to user installation +INSTALL_MODE="user" +if [[ "$1" == "--system" ]]; then + INSTALL_MODE="system" +fi + +echo -e "${GREEN}Redshift Rebooted Installation Script${NC}" +echo "======================================" +echo "" + +# Check if running as root for system install +if [[ "$INSTALL_MODE" == "system" ]] && [[ $EUID -ne 0 ]]; then + echo -e "${RED}Error: System installation requires root privileges${NC}" + echo "Please run: sudo $0 --system" + exit 1 +fi + +# Build the project +echo -e "${YELLOW}Building redshift-rebooted...${NC}" +cd "$PROJECT_DIR" +cargo build --release + +if [[ ! -f "$PROJECT_DIR/target/release/redshift-rebooted" ]]; then + echo -e "${RED}Error: Build failed - binary not found${NC}" + exit 1 +fi + +echo -e "${GREEN}✓ Build successful${NC}" +echo "" + +# Set installation paths based on mode +if [[ "$INSTALL_MODE" == "user" ]]; then + BIN_DIR="$HOME/.local/bin" + SYSTEMD_DIR="$HOME/.config/systemd/user" + SYSTEMCTL_CMD="systemctl --user" + INSTALL_TYPE="user" +else + BIN_DIR="/usr/bin" + SYSTEMD_DIR="/usr/lib/systemd/user" + SYSTEMCTL_CMD="systemctl --user" + INSTALL_TYPE="system-wide (user service)" +fi + +echo -e "${YELLOW}Installing binary...${NC}" +mkdir -p "$BIN_DIR" +cp "$PROJECT_DIR/target/release/redshift-rebooted" "$BIN_DIR/redshift-rebooted" +chmod +x "$BIN_DIR/redshift-rebooted" +echo -e "${GREEN}✓ Binary installed to $BIN_DIR/redshift-rebooted${NC}" +echo "" + +echo -e "${YELLOW}Installing systemd service...${NC}" +mkdir -p "$SYSTEMD_DIR" +cp "$PROJECT_DIR/systemd/redshift-rebooted.service" "$SYSTEMD_DIR/redshift-rebooted.service" + +# Update ExecStart path in service file for system install +if [[ "$INSTALL_MODE" == "system" ]]; then + sed -i "s|%h/.local/bin/redshift-rebooted|/usr/bin/redshift-rebooted|g" "$SYSTEMD_DIR/redshift-rebooted.service" +fi + +echo -e "${GREEN}✓ Service file installed to $SYSTEMD_DIR/redshift-rebooted.service${NC}" +echo "" + +# Reload systemd +echo -e "${YELLOW}Reloading systemd daemon...${NC}" +$SYSTEMCTL_CMD daemon-reload +echo -e "${GREEN}✓ Systemd daemon reloaded${NC}" +echo "" + +# Print success message and instructions +echo -e "${GREEN}Installation complete!${NC}" +echo "" +echo "Next steps:" +echo "===========" +echo "" +echo "1. Enable the service to start at login:" +echo -e " ${YELLOW}systemctl --user enable redshift-rebooted${NC}" +echo "" +echo "2. Start the service now:" +echo -e " ${YELLOW}systemctl --user start redshift-rebooted${NC}" +echo "" +echo "3. Check service status:" +echo -e " ${YELLOW}systemctl --user status redshift-rebooted${NC}" +echo "" +echo "4. View service logs:" +echo -e " ${YELLOW}journalctl --user -u redshift-rebooted -f${NC}" +echo "" +echo "Notes:" +echo "------" +echo "- Configure your location and preferences in ~/.config/redshift/redshift.conf" +echo "- Sample config: $PROJECT_DIR/redshift.conf.sample" +echo "- Restart the service after config changes: systemctl --user restart redshift-rebooted" +echo "" diff --git a/rewrite/scripts/uninstall.sh b/rewrite/scripts/uninstall.sh new file mode 100755 index 0000000..01107fc --- /dev/null +++ b/rewrite/scripts/uninstall.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Default to user installation +INSTALL_MODE="user" +if [[ "$1" == "--system" ]]; then + INSTALL_MODE="system" +fi + +echo -e "${YELLOW}Redshift Rebooted Uninstallation Script${NC}" +echo "========================================" +echo "" + +# Check if running as root for system uninstall +if [[ "$INSTALL_MODE" == "system" ]] && [[ $EUID -ne 0 ]]; then + echo -e "${RED}Error: System uninstallation requires root privileges${NC}" + echo "Please run: sudo $0 --system" + exit 1 +fi + +# Set paths based on mode +if [[ "$INSTALL_MODE" == "user" ]]; then + BIN_PATH="$HOME/.local/bin/redshift-rebooted" + SERVICE_PATH="$HOME/.config/systemd/user/redshift-rebooted.service" + SYSTEMCTL_CMD="systemctl --user" +else + BIN_PATH="/usr/bin/redshift-rebooted" + SERVICE_PATH="/usr/lib/systemd/user/redshift-rebooted.service" + SYSTEMCTL_CMD="systemctl --user" +fi + +# Stop and disable service if running +echo -e "${YELLOW}Stopping and disabling service...${NC}" +if $SYSTEMCTL_CMD is-active --quiet redshift-rebooted 2>/dev/null; then + $SYSTEMCTL_CMD stop redshift-rebooted + echo -e "${GREEN}✓ Service stopped${NC}" +fi + +if $SYSTEMCTL_CMD is-enabled --quiet redshift-rebooted 2>/dev/null; then + $SYSTEMCTL_CMD disable redshift-rebooted + echo -e "${GREEN}✓ Service disabled${NC}" +fi +echo "" + +# Remove service file +if [[ -f "$SERVICE_PATH" ]]; then + echo -e "${YELLOW}Removing service file...${NC}" + rm -f "$SERVICE_PATH" + echo -e "${GREEN}✓ Service file removed: $SERVICE_PATH${NC}" +else + echo -e "${YELLOW}Service file not found: $SERVICE_PATH${NC}" +fi +echo "" + +# Remove binary +if [[ -f "$BIN_PATH" ]]; then + echo -e "${YELLOW}Removing binary...${NC}" + rm -f "$BIN_PATH" + echo -e "${GREEN}✓ Binary removed: $BIN_PATH${NC}" +else + echo -e "${YELLOW}Binary not found: $BIN_PATH${NC}" +fi +echo "" + +# Reload systemd +echo -e "${YELLOW}Reloading systemd daemon...${NC}" +$SYSTEMCTL_CMD daemon-reload +echo -e "${GREEN}✓ Systemd daemon reloaded${NC}" +echo "" + +echo -e "${GREEN}Uninstallation complete!${NC}" +echo "" +echo "Note: Configuration files in ~/.config/redshift/ were not removed." +echo "You can manually delete them if desired." +echo "" diff --git a/rewrite/systemd/redshift-rebooted.service b/rewrite/systemd/redshift-rebooted.service new file mode 100644 index 0000000..11abe1d --- /dev/null +++ b/rewrite/systemd/redshift-rebooted.service @@ -0,0 +1,12 @@ +[Unit] +Description=Redshift Rebooted display color temperature adjustment +Documentation=https://github.com/jonls/redshift +After=graphical-session.target + +[Service] +ExecStart=%h/.local/bin/redshift-rebooted +Restart=always +RestartSec=3 + +[Install] +WantedBy=default.target