summarylogtreecommitdiffstats
path: root/snry-shell.install
blob: 54edca6c17bc4475fdc0dc27cfbad6d4baf21de6 (plain)
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
pre_upgrade() {
	# Stop the daemon BEFORE pacman replaces files.
	# This prevents QuickShell from hot-reloading partially-written QML
	# and crashing the compositor.
	local user
	user=$(logname 2>/dev/null || awk -F: '$3>=1000 && $3<65534 {print $1; exit}' /etc/passwd)

	if [ -z "$user" ]; then
		return 0
	fi

	local uid
	uid=$(id -u "$user")

	sudo -u "$user" XDG_RUNTIME_DIR="/run/user/$uid" \
		systemctl --user stop snry-daemon.service 2>/dev/null || true
}

post_install() {
	# Detect the installing user (not root)
	local user
	user=$(logname 2>/dev/null || awk -F: '$3>=1000 && $3<65534 {print $1; exit}' /etc/passwd)

	if [ -z "$user" ]; then
		echo ">>> Could not detect installing user. Run 'snry-daemon setup' manually."
		return 0
	fi

	local uid
	uid=$(id -u "$user")

	echo ">>> Setting up Snry Shell for user: $user"

	# Phase 1: System setup (groups, services, PAM, logind)
	HOME="/home/$user" snry-daemon setups 2>/dev/null || true

	# Note: Do NOT run 'snry-daemon install' here — it calls pacman
	# which deadlocks because pacman already holds the database lock.
	# Users should run it after pacman finishes.

	# Phase 2: Config sync (as the user)
	sudo -u "$user" HOME="/home/$user" XDG_RUNTIME_DIR="/run/user/$uid" \
		snry-daemon sync 2>/dev/null || true

	# Phase 3: Enable the daemon via systemd user service
	sudo -u "$user" XDG_RUNTIME_DIR="/run/user/$uid" \
		systemctl --user enable snry-daemon.service 2>/dev/null || true

	echo ""
	echo ">>> Snry Shell installed!"
	echo ">>> Run these commands to finish setup:"
	echo ">>>   snry-daemon install"
	echo ">>>   systemctl --user start snry-daemon.service"
	echo ""
	echo ">>> To enable the display manager (replaces your login screen):"
	echo ">>>   sudo pacman -S snry-dm"
	echo ">>>   sudo systemctl enable snry-dm.service"
}

post_upgrade() {
	local user
	user=$(logname 2>/dev/null || awk -F: '$3>=1000 && $3<65534 {print $1; exit}' /etc/passwd)

	if [ -z "$user" ]; then
		echo ">>> Could not detect installing user. Run 'snry-daemon setup' manually."
		return 0
	fi

	local uid
	uid=$(id -u "$user")

	# Note: Do NOT run 'snry-daemon install' here — it calls pacman
	# which deadlocks because pacman already holds the database lock.
	# Users should run 'snry-daemon install' manually if deps changed.

	echo ">>> Syncing Snry Shell configs for user: $user"

	sudo -u "$user" HOME="/home/$user" XDG_RUNTIME_DIR="/run/user/$uid" \
		snry-daemon sync 2>/dev/null || true

	# Start the daemon (pre_upgrade stopped it before files were replaced).
	# Use restart as a safety net in case pre_upgrade didn't run.
	sudo -u "$user" XDG_RUNTIME_DIR="/run/user/$uid" \
		systemctl --user start snry-daemon.service 2>/dev/null \
		|| sudo -u "$user" XDG_RUNTIME_DIR="/run/user/$uid" \
		systemctl --user restart snry-daemon.service 2>/dev/null || true

	echo ""
	echo ">>> Snry Shell updated!"
	echo ">>> The daemon has been restarted via systemd."
	echo ">>>"
	echo ">>> If runtime dependencies changed, run: snry-daemon install"
}

post_remove() {
	local user
	user=$(logname 2>/dev/null || awk -F: '$3>=1000 && $3<65534 {print $1; exit}' /etc/passwd)

	if [ -z "$user" ]; then
		echo ">>> Could not detect installing user."
		echo ">>> Disable the service manually: systemctl --user disable --now snry-daemon.service"
		return 0
	fi

	local uid
	uid=$(id -u "$user")

	# Stop and disable the daemon service
	sudo -u "$user" XDG_RUNTIME_DIR="/run/user/$uid" \
		systemctl --user disable --now snry-daemon.service 2>/dev/null || true

	echo ""
	echo ">>> Snry Shell has been removed."
	echo ">>> Config files in ~/.config/ were NOT deleted."
	echo ">>> To fully clean up, run (before removing this package):"
	echo ">>>   snry-daemon uninstall"
	echo ""
}