#!/usr/bin/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." x200_cmdfreq="/usr/bin/intel_reg" pwmfreq="${PWMFREQ_RATE}" x200_cmdfreq_args="write 0x00061254 $pwmfreq" extra_started_commands="initbackup refresh" 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 depend() { need localmount before net } set_pwmfreq() { if [ $is_thinkpad_x200 = "yes" ] then exec $x200_cmdfreq $x200_cmdfreq_args 2>/dev/null 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 } do_privacy() { if [ $enable_privacy = "true" ] then if [ -n "${wired_interface}" ] then rm -rf /etc/dhcpcd.duid /sbin/macchanger -r $wired_interface fi fi } refresh() { set_pwmfreq } initbackup() { do_backup } start() { if [ "${RC_CMD}" = "restart" ] then /usr/sbin/rfkill block all else do_privacy fi /usr/sbin/rfkill block all set_pwmfreq } stop() { /usr/sbin/rfkill block all do_backup }