-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystemd_on_resume_config.sh
executable file
·127 lines (101 loc) · 4.82 KB
/
systemd_on_resume_config.sh
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
#!/bin/bash
# trap 'err=$?; echo >&2 " ERROR: Exiting $0 on error $err"; sleep 10; exit $err' ERR
# code mentioned in lauchpad bug 1791427 (for X1 carbon gen 6 with NFC to fix non working after resume trackpoint), do not know how to check for PC model, seems now do not cause problems if run for others
# TODO test if fixes the issue if run on resume as programmed here (works if run manually after full wake up)
# result of test: not working. TODO find other ways to fix automatically, for now added custom keys to activate fix code in dconf_config.sh
if [ ! -e "${liveiso_path_scripts_root}" ] ; then liveiso_path_scripts_root=/usr/bin/am-scripts ; fi
folder_for_code_to_run_on_suspend="/lib/systemd/system-sleep/"
add_file_to_systemd_system-sleep () {
file_fully_qualified_name="${folder_for_code_to_run_on_suspend}/${file_name}"
if [ -e "$file_fully_qualified_name" ];then
1>&2 echo -e "\n WARNING: $file_fully_qualified_name exists, next is programmed NOT to add\n$file_contents\n to code potentially to be run via systemd suspend/resume\n"
else
# /dev/null not to output to terminal
echo "$file_contents" | 1>/dev/null sudo tee "$file_fully_qualified_name"
sudo chmod a+x "$file_fully_qualified_name"
fi
}
# reset trackpoint if stops working after suspend (happens on some ThinkPads)
# decided to use keyboard binding later - key) not post) - as only some models need that
file_contents='#!/bin/sh
case $1 in
pre) ;;
post) ;;
key)
echo -n "none" | sudo tee /sys/bus/serio/devices/serio1/drvctl
sleep 3
echo -n "reconnect" | sudo tee /sys/bus/serio/devices/serio1/drvctl
;;
esac'
file_name=trackpoint_reset
add_file_to_systemd_system-sleep
# set screen scaling as dconf scaling-factor value seems to be reset on resume
# Note: on Linux Mint 21 the command (gsettings set org.cinnamon.desktop.interface scaling-factor 2) seems does not work
file_name=scaling_factor
file_fully_qualified_name="${folder_for_code_to_run_on_suspend}/${file_name}"
if [ -e "$file_fully_qualified_name" ];then
1>&2 echo " WARNING: $file_fully_qualified_name exists, next is programmed not to configure code to run on resume for dconf scaling-factor issue fix (as probably configured already)"
else
# /dev/null not to output to terminal
# EOF is quoted to prevend expansion/substitution
sudo tee "$file_fully_qualified_name" >/dev/null <<-"EOF"
#!/bin/sh
case $1 in
pre) ;;
post) ;;
key)
dpm=$(xrandr | sed 's/x/ /g' | awk '/ connected/ {printf "%.0f",$4/$(NF-1)}') # dots per millimeter, rounded as bash test works with integers only
# at least gave "integer expression expected" for [ 3.4 -eq 45 ]
dpi=$(xrandr | sed 's/x/ /g' | awk '/ connected/ {printf "%.0f",$4/$(NF-1)*25.4}') # dots per inch, rounded
horizontal_relosution=$(xrandr | sed 's/x/ /g' | awk '/ connected/ {printf "%.0f",$4}')
if [ $dpm -ge 8 ] && [ $horizontal_relosution -ge 2000 ];then # maybe will be run on small displays, not change default scaling in such case
gsettings set org.cinnamon.desktop.interface scaling-factor 2
# standard 100%, large 150%, larger 200%, largest 400%; small 66%, smaller 50%, smallest 33%
gsettings set org.nemo.list-view default-zoom-level 'standard'
fi
# temporary to set color profiles until found a way to run on boot
$liveiso_path_scripts_root/set_color_profile.sh
;;
esac
EOF
sudo chmod a+x "$file_fully_qualified_name"
fi
# to activate screensaver before suspend to try to get rid of image of the workspace displayed for a moment after resume
# Edit: did not work
#
# Trying another (seemingly advised by man pages of xscreensaver): manually running xscreensaver-systemd resulted in "failed to connect as org.freedesktop.ScreenSaver: File exists"
# meaning AFAIK Cinnamon screensaver had already registered with D-Bus and only one screensaver can do that
# TODO fix the issue mentioned in line 1 of those block of comments
# Seems running via systemd service with Before=systemd-suspend.service works, so comment out here:
#file_contents='#!/bin/sh
#
#case $1 in
# pre)
# xscreensaver-command -suspend
# ;;
# post) ;;
#esac'
#
#file_name=xscreensaver_lock_screen
#add_file_to_systemd_system-sleep
#
# to save datetime of suspend to check duration of suspend/sleep later
file_contents='#!/bin/sh
case $1 in
pre)
date --iso-8601=seconds | tee --append /tmp/amendediso_suspended_datetime.txt
;;
post)
echo "$(date --iso-8601=seconds) resumed" | tee --append /tmp/amendediso_suspended_datetime.txt ;;
esac'
file_name=suspended_datetime
add_file_to_systemd_system-sleep
# to turn fan off - does not work for some reason; TODO: test hypothesis that fan is reset after post) during resume; TODO: find out why seems to be NO "resume.target" in systemd
file_contents='#!/bin/sh
case $1 in
pre) ;;
post)
stopfan ;;
esac'
file_name=fan_stopfan
add_file_to_systemd_system-sleep