-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_after_gnome_monitors.zsh.tmpl
More file actions
46 lines (39 loc) · 1.1 KB
/
Copy pathrun_after_gnome_monitors.zsh.tmpl
File metadata and controls
46 lines (39 loc) · 1.1 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
#!/usr/bin/env zsh
{{ if .headless }}
# We're headless.
exit 0
{{ end }}
set -o errexit -o nounset -o pipefail
from="$HOME/.config/monitors.xml"
to="/var/lib/gdm/.config/monitors.xml"
function perform_copy() {
local to_dir
to_dir=$(dirname "$to")
>&2 echo "Creating directory $to_dir..."
sudo mkdir -p "$to_dir"
>&2 echo "Changing folder permission $to_dir..."
sudo chmod 755 "$to_dir"
>&2 echo "Changing folder ownership $to_dir..."
sudo chown "$(id -u gdm):$(id -g gdm)" "$to_dir"
>&2 echo "Copying $from to $to..."
sudo cp "$from" "$to"
>&2 echo "Setting ownership to gdm..."
sudo chown "$(id -u gdm):$(id -g gdm)" "$to"
>&2 echo "Setting file permissions..."
sudo chmod 644 "$to"
}
if ! id -u gdm >/dev/null 2>&1; then
>&2 echo "gdm user does not exist, skipping monitor sync."
exit 0
fi
if [ ! -f "$from" ]; then
>&2 echo "$from does not exist."
elif test ! -f "$to"; then
>&2 echo "$to does not exist."
perform_copy
elif ! cmp --silent "$from" "$to"; then
>&2 echo "$from changed."
perform_copy
else
>&2 echo "$from == $to"
fi