From 0d785167952f6fce45e3954060d37c86bc0e6e07 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 26 Apr 2023 11:51:26 +0200 Subject: [PATCH] Added draft for auto-usb-backup --- roles/independent-auto-usb-backup/README.md | 6 ++++++ roles/independent-auto-usb-backup/meta/main.yml | 2 ++ .../templates/usb-auto-backup.rule.j2 | 1 + .../templates/usb-auto-backup.sh.j2 | 8 ++++++++ 4 files changed, 17 insertions(+) create mode 100644 roles/independent-auto-usb-backup/README.md create mode 100644 roles/independent-auto-usb-backup/meta/main.yml create mode 100644 roles/independent-auto-usb-backup/templates/usb-auto-backup.rule.j2 create mode 100644 roles/independent-auto-usb-backup/templates/usb-auto-backup.sh.j2 diff --git a/roles/independent-auto-usb-backup/README.md b/roles/independent-auto-usb-backup/README.md new file mode 100644 index 00000000..dddfce9f --- /dev/null +++ b/roles/independent-auto-usb-backup/README.md @@ -0,0 +1,6 @@ +# independent-auto-usb-backup +This tool role allows to make an automatic backup to an usb stick + +## More information +- https://unix.stackexchange.com/questions/67464/how-to-get-uuid-for-a-usb-drive +- https://unix.stackexchange.com/questions/65891/how-to-execute-a-shellscript-when-i-plug-in-a-usb-device \ No newline at end of file diff --git a/roles/independent-auto-usb-backup/meta/main.yml b/roles/independent-auto-usb-backup/meta/main.yml new file mode 100644 index 00000000..11dcdd3f --- /dev/null +++ b/roles/independent-auto-usb-backup/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: +- independent_user-administrator diff --git a/roles/independent-auto-usb-backup/templates/usb-auto-backup.rule.j2 b/roles/independent-auto-usb-backup/templates/usb-auto-backup.rule.j2 new file mode 100644 index 00000000..f843fc92 --- /dev/null +++ b/roles/independent-auto-usb-backup/templates/usb-auto-backup.rule.j2 @@ -0,0 +1 @@ +ATTRS{idVendor}=="152d", ATTRS{idProduct}=="2329", RUN+="/tmp/test.sh" \ No newline at end of file diff --git a/roles/independent-auto-usb-backup/templates/usb-auto-backup.sh.j2 b/roles/independent-auto-usb-backup/templates/usb-auto-backup.sh.j2 new file mode 100644 index 00000000..821e1d30 --- /dev/null +++ b/roles/independent-auto-usb-backup/templates/usb-auto-backup.sh.j2 @@ -0,0 +1,8 @@ +#! /bin/sh + +env >>/tmp/test.log +file "/sys${DEVPATH}" >>/tmp/test.log + +if [ "${ACTION}" = add -a -d "/sys${DEVPATH}" ]; then +echo "add ${DEVPATH}" >>/tmp/test.log +fi \ No newline at end of file