aboutsummaryrefslogtreecommitdiff
path: root/my-x200.initd
diff options
context:
space:
mode:
authorRobert Alessi <alessi@robertalessi.net>2021-02-07 11:50:26 +0100
committerRobert Alessi <alessi@robertalessi.net>2021-02-07 11:50:26 +0100
commit7d0a96e7b5cf4541b07570d54829e152ff9b9a5c (patch)
tree349c3fc6cb6a3a44eb28f12c281ac4616d59775f /my-x200.initd
downloadmy-x200-7d0a96e7b5cf4541b07570d54829e152ff9b9a5c.tar.gz
initial Debian/Devuan commit
Diffstat (limited to 'my-x200.initd')
-rw-r--r--my-x200.initd124
1 files changed, 124 insertions, 0 deletions
diff --git a/my-x200.initd b/my-x200.initd
new file mode 100644
index 0000000..5e1e7c1
--- /dev/null
+++ b/my-x200.initd
@@ -0,0 +1,124 @@
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides: my-x200
4# X-Start-Before: dhcpcd
5# Required-Start: $remote_fs $local_fs
6# Required-Stop: $remote_fs $local_fs
7# X-Stop-After: xdm
8# Default-Start: 2 3 4 5
9# Default-Stop: 0 1 6
10# Short-Description: Starts and stops my-x200
11# Description: Removes whining noise from Thinkpads X200, powers off the wifi on shutdown and optionally backups directories.
12### END INIT INFO
13
14# Copyright 2018-2021 Robert Alessi
15# Distributed under the terms of the GNU General Public License v2
16
17# Set variables
18NAME=my-x200
19
20# Source init functions
21. /lib/lsb/init-functions
22
23# Read configuration variable file if it is present
24[ -r /etc/default/$NAME ] && . /etc/default/$NAME
25
26x200_cmdfreq="/usr/bin/intel_reg"
27pwmfreq="${PWMFREQ_RATE}"
28x200_cmdfreq_args="write 0x00061254 $pwmfreq"
29autobackup="${conf_autobackup}"
30backup_path="${conf_backup_path}"
31control_file="${conf_control_file}"
32if [ "$use_rsnapshot" = "true" ]
33then
34 backup_cmd="/usr/bin/rsnapshot"
35 backup_args="${rsnapshot_args}"
36else
37 backup_cmd="/usr/bin/rsync"
38 backup_args="-aAX --relative --delete --quiet"
39fi
40
41set_pwmfreq() {
42 if [ "$is_thinkpad_x200" = "yes" ]
43 then
44 exec $x200_cmdfreq $x200_cmdfreq_args 2>/dev/null
45 fi
46}
47
48do_backup() {
49 if [ "$autobackup" = "true" ]
50 then
51 if [ -e "$backup_path"/"$control_file" ]
52 then
53 if [ "$use_rsnapshot" = "true" ]
54 then
55 $backup_cmd $backup_args
56 else
57 $backup_cmd $backup_args $conf_backup_dirs "$backup_path"
58 fi
59 fi
60 fi
61}
62
63do_privacy() {
64 if [ "$enable_privacy" = "true" ]
65 then
66 if [ -n "${wired_interface}" ]
67 then
68 printf '0004' > /var/lib/dhcpcd/duid
69 cat /proc/sys/kernel/random/boot_id >> /var/lib/dhcpcd/duid
70 /usr/bin/macchanger -r $wired_interface
71 fi
72 fi
73}
74
75do_refresh() {
76 set_pwmfreq
77}
78
79do_initbackup() {
80 do_backup
81}
82
83do_start() {
84 if [ "${RC_CMD}" = "restart" ]
85 then
86 /usr/sbin/rfkill block all
87 else
88 do_privacy
89 fi
90 /usr/sbin/rfkill block all
91 set_pwmfreq
92}
93
94do_stop() {
95 /usr/sbin/rfkill block all
96 do_backup
97}
98
99do_restart() {
100 /usr/sbin/rfkill block all
101 set_pwmfreq
102}
103
104case "$1" in
105 start)
106 do_start
107 ;;
108 stop)
109 do_stop
110 ;;
111 restart|force-reload)
112 do_restart
113 ;;
114 refresh)
115 do_refresh
116 ;;
117 initbackup)
118 do_initbackup
119 ;;
120 *)
121 echo "Usage: $NAME {start|stop|refresh|initbackup}" >&2
122 exit 3
123 ;;
124esac