From 43c52017c78bbc67ec7a7ab3b690fdf2ffb0f98a Mon Sep 17 00:00:00 2001 From: Robert Alessi Date: Fri, 13 Dec 2019 16:09:44 +0100 Subject: new option to backup repositories --- PKGBUILD | 8 ++++---- x200-my.confd | 17 +++++++++++++++++ x200-my.initd | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index f01fe9c..ff3b102 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,9 +1,9 @@ # Maintainer: Robert Alessi pkgname=x200-my -pkgver=0.2 +pkgver=0.3 pkgrel=1 -pkgdesc="Service which removes whining noise from Thinkpads X200. Also powers off the wifi on shutdown." +pkgdesc="Service to remove whining noise from Thinkpads X200, power off the wifi on shutdown and optionally backup directories." arch=(any) license=(GPL2) url="http://git.robertalessi.net/x200-my" @@ -14,8 +14,8 @@ source=('x200-my.initd' 'x200-my-lid.sh' 'x200-my-sleep.sh' 'x200-my.sh') -sha512sums=('b8cab7790ecb542fa8aa930f26ac3f293bce772585643a0de189285415a0d7c12f5e9fb98602dd15ff9bb52afdc93acbcd658b153f1b9c1cb640646e55c3b73c' - '172d5def88c12118c9d736404bb7a028ee39578dd6f2dd632224e7c03ee30a34a19412725fb09c17f31aedc14846e0f2f0682f1d9077c4ff202bd7b7cf48c467' +sha512sums=('96579d18e8639da441b2f0104e453f2ffd34a1c14c77ad08709fc090b168d0030f5074d8c54f116739a4f421286c5d2b64181c66fabd2eee91c371d8aa856395' + '9129a88db1c0a8385a053060ae3f737e75be1c50d7ae17a8804121ae20365b9938ed47c06b55250e72df2c20036c5043e70c84fb63e57d4548afb20ee9b29c94' '0dc141f1a26f2cd570d49a05bcc9496ba4c49fde39afad46f5a0783e83c07ec810ca81454a28c3241bcffc62ac31274e2a8d726bbd3c1e91d8cf5315b783c3f8' '610564aa853c5dbc4e370ec2a4d3b5590e53ed235a1960927c0986a31f6c77d135086b1f5752b56fd511ea4a0294082fc7e98ee2fa7b69b37776a59f45c2ec34' 'cb765075f02b5cd16bcfc31571cf7c31ddcd74ff3aa832df1acd96bd8feb62855c0cf90c31c3e0028180765a51eafc5c74fb1f0406dd9172bdc0f5ec02b39f8c') diff --git a/x200-my.confd b/x200-my.confd index 44312bc..a65dd69 100644 --- a/x200-my.confd +++ b/x200-my.confd @@ -3,3 +3,20 @@ # Options to pass to the x200-my daemon. PWMFREQ_RATE="0x8bb7b16dc5b6a" + +# +# Backup options +# +# Activate autobackup on shutdown (true/false) +conf_autobackup="false" +# Path to backup directory: +conf_backup_path="/mnt/disk" +# Control file. This (empty) file must exist in the backup directory: +conf_backup_control_file="dobackup" +# Directories to backup: +conf_backup_dirs=( + "/etc" + "/root" + "/usr/local" + "/home" +) diff --git a/x200-my.initd b/x200-my.initd index 8edefd6..b026b5b 100644 --- a/x200-my.initd +++ b/x200-my.initd @@ -1,14 +1,44 @@ #!/sbin/openrc-run -# Copyright 2018 Robert Alessi +# Copyright 2018-2019 Robert Alessi # Distributed under the terms of the GNU General Public License v2 -description="Removes whining noise from Thinkpads X200 and powers off the wifi on shutdown." +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}" +backup_cmd="/usr/bin/rsync" +backup_args="-aAX --relative --delete --quiet" + +do_listofpackages() { + /usr/bin/pacman -Qqetn > "$backup_path"/pkglist.txt + /usr/bin/pacman -Qqem > "$backup_path"/foreignpkglist.txt +} + +initbackup() { + if [ $autobackup = "true" ] + then + if [ -e "$backup_path"/"$control_file" ] + then + do_listofpackages + for dir in "${conf_backup_dirs[@]}" + do + if [ -d "$dir" ] + then + $backup_cmd $backup_args "$dir" "$backup_path" + fi + done + fi + fi +} + start() { if [ "${RC_CMD}" = "restart" ]; then @@ -20,4 +50,18 @@ start() { stop() { /usr/bin/nmcli radio all off + if [ $autobackup = "true" ] + then + if [ -e "$backup_path"/"$control_file" ] + then + do_listofpackages + for dir in "${conf_backup_dirs[@]}" + do + if [ -d "$dir" ] + then + $backup_cmd $backup_args "$dir" "$backup_path" + fi + done + fi + fi } -- cgit v1.2.3