|
| 1 | +#!/bin/bash |
| 2 | +# Hypercube GDM Theme Installation |
| 3 | +# Modifies gnome-shell-theme.gresource to customize GDM login screen |
| 4 | +# |
| 5 | +# This script extracts the GNOME Shell theme gresource, patches the CSS |
| 6 | +# to use our custom background, and recompiles it. |
| 7 | + |
| 8 | +set -euo pipefail |
| 9 | + |
| 10 | +GRESOURCE="/usr/share/gnome-shell/gnome-shell-theme.gresource" |
| 11 | +WORKDIR="/var/tmp/gdm-theme-workdir" |
| 12 | +LOGO_PATH="/usr/share/pixmaps/hypercube-logo.png" |
| 13 | + |
| 14 | +echo "Installing Hypercube GDM theme..." |
| 15 | + |
| 16 | +# Verify required files exist |
| 17 | +if [ ! -f "$GRESOURCE" ]; then |
| 18 | + echo "ERROR: $GRESOURCE not found" |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +if [ ! -f "$LOGO_PATH" ]; then |
| 23 | + echo "ERROR: $LOGO_PATH not found" |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +# Verify gresource tools are available |
| 28 | +if ! command -v gresource &> /dev/null; then |
| 29 | + echo "ERROR: gresource command not found. Install glib2-devel." |
| 30 | + exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +if ! command -v glib-compile-resources &> /dev/null; then |
| 34 | + echo "ERROR: glib-compile-resources command not found. Install glib2-devel." |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +# Create working directory |
| 39 | +rm -rf "$WORKDIR" |
| 40 | +mkdir -p "$WORKDIR/theme" |
| 41 | + |
| 42 | +# Extract all resources from the gresource file |
| 43 | +echo "Extracting gnome-shell-theme.gresource..." |
| 44 | +for resource in $(gresource list "$GRESOURCE"); do |
| 45 | + # Remove /org/gnome/shell/ prefix for local path |
| 46 | + local_path="${resource#/org/gnome/shell/}" |
| 47 | + mkdir -p "$WORKDIR/$(dirname "$local_path")" |
| 48 | + gresource extract "$GRESOURCE" "$resource" > "$WORKDIR/$local_path" |
| 49 | +done |
| 50 | + |
| 51 | +# Copy our logo to the theme directory so it can be embedded |
| 52 | +cp "$LOGO_PATH" "$WORKDIR/theme/hypercube-logo.png" |
| 53 | + |
| 54 | +# Patch the CSS files to use our custom background |
| 55 | +# We need to modify both light and dark variants |
| 56 | +for css_file in "$WORKDIR/theme/gnome-shell.css" "$WORKDIR/theme/gnome-shell-light.css" "$WORKDIR/theme/gnome-shell-dark.css"; do |
| 57 | + if [ -f "$css_file" ]; then |
| 58 | + echo "Patching $(basename "$css_file")..." |
| 59 | + |
| 60 | + # Replace the #lockDialogGroup background |
| 61 | + # The original typically has: background-color: $system_bg_color; or similar |
| 62 | + # We replace any existing #lockDialogGroup block with our custom one |
| 63 | + |
| 64 | + if grep -q '#lockDialogGroup' "$css_file"; then |
| 65 | + # Use sed to replace the existing #lockDialogGroup block |
| 66 | + # This handles multi-line blocks by replacing just the background property |
| 67 | + sed -i 's|#lockDialogGroup {|#lockDialogGroup { background: #000000 url(resource:///org/gnome/shell/theme/hypercube-logo.png) no-repeat center center; background-size: auto;|' "$css_file" |
| 68 | + # Remove any duplicate/old background properties that might conflict |
| 69 | + sed -i '/#lockDialogGroup/,/}/ { /background-color:/d; }' "$css_file" |
| 70 | + else |
| 71 | + # If #lockDialogGroup doesn't exist, append it |
| 72 | + echo ' |
| 73 | +#lockDialogGroup { |
| 74 | + background: #000000 url(resource:///org/gnome/shell/theme/hypercube-logo.png) no-repeat center center; |
| 75 | + background-size: auto; |
| 76 | +}' >> "$css_file" |
| 77 | + fi |
| 78 | + fi |
| 79 | +done |
| 80 | + |
| 81 | +# Create the gresource XML manifest |
| 82 | +echo "Creating gresource manifest..." |
| 83 | +cat > "$WORKDIR/gnome-shell-theme.gresource.xml" << 'XMLEOF' |
| 84 | +<?xml version="1.0" encoding="UTF-8"?> |
| 85 | +<gresources> |
| 86 | + <gresource prefix="/org/gnome/shell/theme"> |
| 87 | +XMLEOF |
| 88 | + |
| 89 | +# Add all files in theme directory to the manifest |
| 90 | +find "$WORKDIR/theme" -type f | while read -r file; do |
| 91 | + relpath="${file#$WORKDIR/theme/}" |
| 92 | + echo " <file>theme/$relpath</file>" >> "$WORKDIR/gnome-shell-theme.gresource.xml" |
| 93 | +done |
| 94 | + |
| 95 | +cat >> "$WORKDIR/gnome-shell-theme.gresource.xml" << 'XMLEOF' |
| 96 | + </gresource> |
| 97 | +</gresources> |
| 98 | +XMLEOF |
| 99 | + |
| 100 | +# Compile the new gresource |
| 101 | +echo "Compiling new gresource..." |
| 102 | +cd "$WORKDIR" |
| 103 | +glib-compile-resources gnome-shell-theme.gresource.xml --target=gnome-shell-theme.gresource |
| 104 | + |
| 105 | +# Backup original and install new gresource |
| 106 | +# Use cp instead of mv to avoid SELinux issues |
| 107 | +echo "Installing new gresource..." |
| 108 | +cp "$GRESOURCE" "${GRESOURCE}.backup" |
| 109 | +cp "$WORKDIR/gnome-shell-theme.gresource" "$GRESOURCE" |
| 110 | + |
| 111 | +# Cleanup |
| 112 | +rm -rf "$WORKDIR" |
| 113 | + |
| 114 | +echo "Hypercube GDM theme installed successfully" |
0 commit comments