diff --git a/systemd/system/bash_eternal_email.service b/systemd/system/bash_eternal_email.service new file mode 100644 index 0000000..d1a95f1 --- /dev/null +++ b/systemd/system/bash_eternal_email.service @@ -0,0 +1,9 @@ +[Unit] +Description=Emailing bash history +Wants=bash_eternal_email.timer + +[Service] +User=root +Group=root +Type=oneshot +ExecStart=/usr/local/bin/bash_eternal_email.sh diff --git a/systemd/system/bash_eternal_email.timer b/systemd/system/bash_eternal_email.timer new file mode 100644 index 0000000..6b40a42 --- /dev/null +++ b/systemd/system/bash_eternal_email.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Emailing bash history +Requires=bash_eternal_email.service + +[Timer] +Unit=bash_eternal_email.service +OnCalendar=Fri *-*-* 22:00:00 +RandomizedDelaySec=30min + +[Install] +WantedBy=timers.target diff --git a/systemd/system/timer-scripts/template.bash_eternal_email.sh b/systemd/system/timer-scripts/template.bash_eternal_email.sh new file mode 100755 index 0000000..4898806 --- /dev/null +++ b/systemd/system/timer-scripts/template.bash_eternal_email.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# Sends an encrypted email attachment of the bash eternal history directory + +declare -r backup_p=/home/emiliko/safe/bash_eternal_backups +declare -r email_msg="$(mktemp)" +declare -r encry_file="$(mktemp)" +chmod 666 "$encry_file" + +sudo -u emiliko bash < "$encry_file" +CMD + +declare -r MIMEType="$(file --mime-type "$encry_file" | sed 's/.*: //')" +declare -r attach_name="bash_full_backup_$(date +%s).tgz" + +cat <"$email_msg" +Dear Emiliko, + +I thought you might like a backup of your .bash_eternal_history files from all +devices I can access. I used $(hostname) as a central repository to back them +up. Hope you enjoy them! + +yours (truly), +Systemd +EMAIL + +curl --silent --ssl-reqd \ + --url 'smtps://smtp.fastmail.com:465' \ + --user 'emiliko%40mami2.moe:' \ + --mail-from "systemd@mami2.moe" \ + --mail-rcpt 'emiliko@cs.ox.ac.uk' \ + --mail-rcpt 'emiliko@mami2.moe' \ + -F '=(;type=multipart/mixed' \ + -F "=$(cat "$email_msg");type=text/plain" \ + -F "file=@${encry_file};type=${MIMEType};encoder=base64" \ + -F '=)' \ + -H "From: Systemd-chan " \ + -H "Subject: Your weekly bash backup" \ + -H "To: Emiliko Mirror " \ + -H "CC: Emiliko Mirror " \ + -H "Date: $(date)"