#!/bin/sh # ### BEGIN INIT INFO # Provides: my-x200 # X-Start-Before: dhcpcd # Required-Start: $remote_fs $local_fs # Required-Stop: $remote_fs $local_fs # X-Stop-After: xdm # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Starts and stops my-x200 # Description: Removes whining noise from Thinkpads X200, powers off the wifi on shutdown and optionally backups directories. ### END INIT INFO # Copyright 2018-2021 Robert Alessi # Distributed under the terms of the GNU General Public License v2 # Set variables NAME=my-x200 # Source init functions . /lib/lsb/init-functions # Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Read additional configuration files in /etc/default/my-x200.d/ confdir="/etc/default/my-x200.d" if [ -d "$confdir" ] && [ -f "$confdir"/*.conf ] then for file in "$confdir"/*.conf do . "$file" done fi # Get my-x200 variables x200_cmdfreq="/usr/bin/intel_reg" pwmfreq="${PWMFREQ_RATE}" x200_cmdfreq_args="write 0x00061254 $pwmfreq" 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 set_pwmfreq() { if [ "$is_thinkpad_x200" = "yes" ] then exec $x200_cmdfreq $x200_cmdfreq_args 2>/dev/null fi } do_backup() { if [ "$autobackup" = "true" ] then if [ -e "$backup_path"/"$control_file" ] then if [ "$use_rsnapshot" = "true" ] then $backup_cmd $backup_args else $backup_cmd $backup_args $conf_backup_dirs "$backup_path" fi fi fi } do_privacy() { if [ "$enable_privacy" = "true" ] then /usr/sbin/rfkill block all if [ -n "${wired_interface}" ] then printf '0004' > /var/lib/dhcpcd/duid cat /proc/sys/kernel/random/boot_id >> /var/lib/dhcpcd/duid /usr/bin/macchanger "$macchanger_options" $wired_interface fi if [ -n "${wireless_interface}" ] then /usr/bin/macchanger "$macchanger_options" $wireless_interface fi fi } do_refresh() { set_pwmfreq } do_initbackup() { do_backup } do_start() { do_privacy set_pwmfreq } do_stop() { if [ "$enable_privacy" = "true" ] then /usr/sbin/rfkill block all fi do_backup } do_restart() { if [ "$enable_privacy" = "true" ] then /usr/sbin/rfkill block all fi set_pwmfreq } case "$1" in start) do_start ;; stop) do_stop ;; restart|force-reload) do_restart ;; refresh) do_refresh ;; initbackup) do_initbackup ;; *) echo "Usage: $NAME {start|stop|refresh|initbackup}" >&2 exit 3 ;; esac