-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·187 lines (152 loc) · 6.08 KB
/
install.sh
File metadata and controls
executable file
·187 lines (152 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# System Cluster Sync Lock - Installation script
set -e
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPTS_DIR="$PROJECT_ROOT/scripts"
SYSTEMD_DIR="$PROJECT_ROOT/systemd"
CONFIG_FILE="$PROJECT_ROOT/config"
SERVICE_FILE="$SYSTEMD_DIR/system-cluster-sync-lock.service"
SYSTEMD_TARGET="/etc/systemd/system/system-cluster-sync-lock.service"
# Best-effort helper to add an app to GNOME Shell favorites.
# Safe to call even when GNOME or gsettings is unavailable.
add_to_gnome_favorites() {
local app_id="$1"
if ! command -v gsettings >/dev/null 2>&1; then
return 0
fi
# Run gsettings as the non-root user when invoked via sudo.
local gsettings_cmd=("gsettings")
if [ "$EUID" -eq 0 ] && [ -n "$SUDO_USER" ]; then
if command -v sudo >/dev/null 2>&1; then
gsettings_cmd=("sudo" "-u" "$SUDO_USER" "gsettings")
fi
fi
local favorites
favorites="$("${gsettings_cmd[@]}" get org.gnome.shell favorite-apps 2>/dev/null)" || return 0
# If it's already present, nothing to do.
if [[ "$favorites" == *"'$app_id'"* ]]; then
return 0
fi
local new_favorites
if [[ "$favorites" == "@as []" || "$favorites" == "[]" ]]; then
new_favorites="['$app_id']"
else
new_favorites="${favorites%]}"
new_favorites="$new_favorites, '$app_id']"
fi
"${gsettings_cmd[@]}" set org.gnome.shell favorite-apps "$new_favorites" >/dev/null 2>&1 || true
}
echo "System Cluster Sync Screen Lock Installation"
echo "============================================="
echo ""
# Check if running as root for systemd installation
if [ "$EUID" -ne 0 ]; then
echo "Note: This script needs sudo privileges to install the systemd service."
echo "You can run: sudo $0"
echo ""
fi
# Make scripts executable
echo "Making scripts executable..."
chmod +x "$SCRIPTS_DIR"/*.sh
echo "✓ Scripts are now executable"
# Check if config exists
if [ ! -f "$CONFIG_FILE" ]; then
echo ""
echo "⚠ Config file not found. Creating from example..."
cp "$PROJECT_ROOT/config.example" "$CONFIG_FILE"
echo "✓ Created config file at $CONFIG_FILE"
echo ""
echo "⚠ IMPORTANT: Please edit $CONFIG_FILE with your settings before continuing!"
echo " - Set REMOTE_HOSTS to space or comma-separated list of SSH config host aliases"
echo " - Ensure these host aliases exist in your ~/.ssh/config file"
echo ""
read -p "Press Enter after editing the config file..."
fi
# Install systemd service
if [ "$EUID" -eq 0 ]; then
echo ""
echo "Installing systemd service..."
# Update service file with actual user home directory
ACTUAL_USER="${SUDO_USER:-$USER}"
USER_HOME=$(getent passwd "$ACTUAL_USER" | cut -d: -f6)
# Create a temporary service file with the correct user home
TEMP_SERVICE=$(mktemp)
sed "s|%h|$USER_HOME|g; s|%i|$ACTUAL_USER|g" "$SERVICE_FILE" > "$TEMP_SERVICE"
cp "$TEMP_SERVICE" "$SYSTEMD_TARGET"
rm "$TEMP_SERVICE"
systemctl daemon-reload
echo "✓ Systemd service installed at $SYSTEMD_TARGET"
echo ""
echo "To enable and start the service, run:"
echo " sudo systemctl enable system-cluster-sync-lock.service"
echo " sudo systemctl start system-cluster-sync-lock.service"
else
echo ""
echo "⚠ Skipping systemd service installation (requires root)"
echo "To install the service, run:"
echo " sudo $0"
fi
echo ""
echo "Installation complete!"
echo ""
echo "Next steps:"
echo "1. Edit $CONFIG_FILE and set REMOTE_HOSTS to your SSH config host aliases"
echo "2. Ensure your ~/.ssh/config contains entries for the hosts in REMOTE_HOSTS"
echo "3. Test SSH connection: ssh <host_alias> 'gnome-screensaver-command -q'"
echo "4. Enable service: sudo systemctl enable system-cluster-sync-lock.service"
echo "5. Start service: sudo systemctl start system-cluster-sync-lock.service"
echo ""
echo "Installing desktop shortcuts..."
# Determine the real target user and home (handles sudo vs non-sudo)
TARGET_USER="${SUDO_USER:-$USER}"
TARGET_HOME=$(getent passwd "$TARGET_USER" | cut -d: -f6)
if [ -z "$TARGET_HOME" ]; then
echo "⚠ Could not determine home directory for user $TARGET_USER; skipping desktop shortcut installation."
else
DESKTOP_DIR="$TARGET_HOME/.local/share/applications"
DESKTOP_FILE="$DESKTOP_DIR/system-cluster-sync-lock-toggle.desktop"
mkdir -p "$DESKTOP_DIR"
# Remove any existing shortcut so we always recreate a fresh one
if [ -f "$DESKTOP_FILE" ]; then
echo "Removing existing desktop shortcut at $DESKTOP_FILE"
rm -f "$DESKTOP_FILE"
fi
cat > "$DESKTOP_FILE" <<EOF
[Desktop Entry]
Name=Toggle cluster displays
Exec=$PROJECT_ROOT/scripts/display-toggle.sh
Comment=Toggle remote cluster displays on/off
Terminal=false
Icon=$PROJECT_ROOT/systemd/desktop-icon.png
Type=Application
Categories=Utility;
EOF
# Ensure ownership is correct for the non-root user when run via sudo
if [ "$EUID" -eq 0 ] && [ -n "$TARGET_USER" ]; then
chown "$TARGET_USER":"$TARGET_USER" "$DESKTOP_FILE" || true
fi
# Try to pin to GNOME favorites (dash)
add_to_gnome_favorites "system-cluster-sync-lock-toggle.desktop" || true
echo "✓ Desktop shortcut installed at $DESKTOP_FILE"
# Deskflow restart desktop entry
DESKFLOW_DESKTOP_FILE="$DESKTOP_DIR/system-cluster-deskflow-restart.desktop"
if [ -f "$DESKFLOW_DESKTOP_FILE" ]; then
echo "Removing existing desktop shortcut at $DESKFLOW_DESKTOP_FILE"
rm -f "$DESKFLOW_DESKTOP_FILE"
fi
cat > "$DESKFLOW_DESKTOP_FILE" <<EOF
[Desktop Entry]
Name=Restart cluster Deskflow
Exec=$PROJECT_ROOT/scripts/deskflow-restart.sh
Comment=Restart Deskflow (Flatpak org.deskflow.deskflow) on all configured cluster hosts
Terminal=false
Icon=$PROJECT_ROOT/systemd/deskflow-restart-icon.svg
Type=Application
Categories=Utility;
EOF
if [ "$EUID" -eq 0 ] && [ -n "$TARGET_USER" ]; then
chown "$TARGET_USER":"$TARGET_USER" "$DESKFLOW_DESKTOP_FILE" || true
fi
add_to_gnome_favorites "system-cluster-deskflow-restart.desktop" || true
echo "✓ Desktop shortcut installed at $DESKFLOW_DESKTOP_FILE"
fi