Files
reterminal-dm4/emmc-provisioning/cloud-init/01-set-rotation-once.sh
nearxos 8b4930d4b9 Refactor screen rotation setup and GTK theme configuration in first-boot process
Update the one-shot script to set screen rotation using kanshi based on kernel command line parameters, replacing the previous wlr-randr method. The script now writes the configuration to ~/.config/kanshi/config and sets the GTK dark theme (PiXnoir or Adwaita-dark) at first login. Additionally, enhance documentation to reflect these changes and clarify the role of the new script in the first-boot process.
2026-02-23 09:59:32 +02:00

46 lines
2.1 KiB
Bash

#!/bin/bash
# One-shot: set screen rotation via kanshi (same as Control Center), then remove self.
# Reads video=DSI-1:rotate=N from kernel cmdline and writes ~/.config/kanshi/config.
# Runs once as user pi at first login; deletes its autostart and this script so it never runs again.
# Logs to /var/log/first-boot.log.
FIRST_BOOT_LOG="/var/log/first-boot.log"
BASE="$(basename "$0" .sh)"
log() { echo "[$(date -Iseconds)] [$BASE] $*" >> "$FIRST_BOOT_LOG" 2>/dev/null || true; }
ROTATE="270"
for f in /boot/firmware/cmdline.txt /boot/cmdline.txt; do
if [[ -f "$f" ]]; then
val=$(grep -o 'video=DSI-1:rotate=[0-9]*' "$f" 2>/dev/null | head -1)
val="${val#*rotate=}"
if [[ "$val" =~ ^(90|180|270)$ ]]; then ROTATE="$val"; break; fi
fi
done
log "writing kanshi config with transform $ROTATE (from cmdline)"
KANSHI_DIR="$HOME/.config/kanshi"
KANSHI_CONFIG="$KANSHI_DIR/config"
mkdir -p "$KANSHI_DIR"
cat > "$KANSHI_CONFIG" << EOF
profile {
output DSI-1 enable scale 1.000000 mode 800x1280@60.000 position 0,0 transform $ROTATE
}
EOF
log "kanshi config written to $KANSHI_CONFIG"
# Set GTK dark theme (same as first-boot step 08)
GTK_THEME_NAME="PiXnoir"
[[ -d /usr/share/themes/Adwaita-dark ]] && ! [[ -d /usr/share/themes/PiXnoir ]] && GTK_THEME_NAME="Adwaita-dark"
GTK_SETTINGS="$HOME/.config/gtk-3.0/settings.ini"
mkdir -p "$(dirname "$GTK_SETTINGS")"
if [[ ! -f "$GTK_SETTINGS" ]]; then
printf '%s\n' '[Settings]' 'gtk-application-prefer-dark-theme=1' "gtk-theme-name=$GTK_THEME_NAME" > "$GTK_SETTINGS"
else
grep -q '^gtk-application-prefer-dark-theme=' "$GTK_SETTINGS" && sed -i 's/^gtk-application-prefer-dark-theme=.*/gtk-application-prefer-dark-theme=1/' "$GTK_SETTINGS" || echo 'gtk-application-prefer-dark-theme=1' >> "$GTK_SETTINGS"
grep -q '^gtk-theme-name=' "$GTK_SETTINGS" && sed -i "s/^gtk-theme-name=.*/gtk-theme-name=$GTK_THEME_NAME/" "$GTK_SETTINGS" || echo "gtk-theme-name=$GTK_THEME_NAME" >> "$GTK_SETTINGS"
fi
log "Set dark theme ($GTK_THEME_NAME) in gtk-3.0/settings.ini"
log "removing one-shot desktop and script"
rm -f "$HOME/.config/autostart/${BASE}.desktop" "$HOME/${BASE}.sh"
log "finished"