aboutsummaryrefslogtreecommitdiff
path: root/x200-my.initd
blob: de88ff06b64d55f1aef1f523513564ea911a15e0 (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
#!/sbin/openrc-run
# Copyright 2018-2019 Robert Alessi
# Distributed under the terms of the GNU General Public License v2

description="Removes whining noise from Thinkpads X200, powers off the wifi on shutdown and optionally backups directories."

command="/usr/bin/intel_reg"
pwmfreq="${PWMFREQ_RATE}"

command_args="write 0x00061254 $pwmfreq"

extra_started_commands="initbackup"

autobackup="${conf_autobackup}"
backup_path="${conf_backup_path}"
control_file="${conf_control_file}"
if [ $use_rsnapshot = "true" ]
then
    backup_cmd="/usr/bin/rsnapshot"
    backup_args="${rsnapshot_args}"
else
    backup_cmd="/usr/bin/rsync"
    backup_args="-aAX --relative --delete --quiet"
fi

do_listofpackages() {
    /usr/bin/pacman -Qqetn > "$backup_path"/pkglist.txt
    /usr/bin/pacman -Qqem > "$backup_path"/foreignpkglist.txt
}

do_backup () {
    if [ $autobackup = "true" ]
    then
	if [ -e "$backup_path"/"$control_file" ]
	then
	    do_listofpackages
	    if [ $use_rsnapshot = "true" ]
	    then
		$backup_cmd $backup_args
	    else
		for dir in "${conf_backup_dirs[@]}"
		do
		    if [ -d "$dir" ]
		    then
			$backup_cmd $backup_args "$dir" "$backup_path"
		    fi
		done
	    fi
	fi
    fi
}

initbackup() {
    do_backup
}

start() {
    if [ "${RC_CMD}" = "restart" ];
    then
      /usr/bin/nmcli radio all off
    fi
    
    exec $command $command_args 2>/dev/null
}

stop() {
    /usr/bin/nmcli radio all off
    do_backup
}