From e18752f75806b0914beba90b6086e63b4fef4291 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Tue, 31 Oct 2023 19:52:30 +0100 Subject: [PATCH 1/2] many things --- borg-backup.homeserver.sh | 2 +- download-with-sftp.sh | 3 ++- mount-docker-sockets.sh | 25 +++++++++++++++++++++++++ tailscale.sh | 5 +++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100755 mount-docker-sockets.sh create mode 100644 tailscale.sh diff --git a/borg-backup.homeserver.sh b/borg-backup.homeserver.sh index f292f42..8e23d5a 100755 --- a/borg-backup.homeserver.sh +++ b/borg-backup.homeserver.sh @@ -4,7 +4,7 @@ export BORG_REPO=/srv/data/backup/borg/homeserver # See the section "Passphrase notes" for more infos. -export BORG_PASSPHRASE="$(cat /root/secret/borg-homeserver.key)" +export BORG_PASSPHRASE="$(cat /root/secret/borg/borg-homeserver.key)" # some helpers and error handling: info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } diff --git a/download-with-sftp.sh b/download-with-sftp.sh index bdce71e..c370571 100755 --- a/download-with-sftp.sh +++ b/download-with-sftp.sh @@ -19,7 +19,8 @@ borg check -v data/backup/borg/snowboard status_check=$? echo "finished checking the downloaded repo. Status: $status_check" if [ "$status_check" -eq "0" ]; then - chown fileserver:fileserver $REPO_DIR/$backupdir + cd $REPO_ROOT + chown fileserver:fileserver $backupdir rm -r old else echo "the new repo was not checked successfully, keeping old repo." diff --git a/mount-docker-sockets.sh b/mount-docker-sockets.sh new file mode 100755 index 0000000..d5845e8 --- /dev/null +++ b/mount-docker-sockets.sh @@ -0,0 +1,25 @@ +#!/bin/bash +TARGET=/var/run/docker-snowboard.socket +MAX_FAILS=10 +SLEEP_TIME=2 + +echo "removing $TARGET" +rm /var/run/docker-snowboard.sock -rf +echo "relaying snowboards socket with ssh" +ssh -nNT -L /var/run/docker-snowboard.sock:/var/run/docker.sock root@cscherr.de & + +# check if the target is a socket, and adjust it. +for ((i=0; i<=MAX_FAILS; i++)); do + if [[ $(file -b /var/run/docker-snowboard.sock) = 'socket' ]]; then + set -e + echo "$TARGET is a socket, adjusting permissions" + chmod 660 /var/run/docker-snowboard.sock + chgrp docker /var/run/docker-snowboard.sock + exit 0 # good end + else + echo "$i: $TARGET is not a socket" + fi + sleep $SLEEP_TIME +done +echo "$TARGET is not a socket even after waiting" +exit 1 # bad end diff --git a/tailscale.sh b/tailscale.sh new file mode 100644 index 0000000..dbc2043 --- /dev/null +++ b/tailscale.sh @@ -0,0 +1,5 @@ +#!/bin/bash +tailscale up \ + --login-server https://vpn.cscherr.de \ + --advertise-exit-node \ + --accept-risk=lose-ssh From 68a2136e1f2f5315a84e29615ce171031856fde6 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Mon, 22 Apr 2024 12:21:33 +0200 Subject: [PATCH 2/2] add mail-script --- mail-script | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 mail-script diff --git a/mail-script b/mail-script new file mode 100755 index 0000000..28f4c95 --- /dev/null +++ b/mail-script @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +from email.message import EmailMessage +import sys + +if sys.argv[1] == "--help" or sys.argv[1] == "-h" or sys.argv[1] == "": + print(""" +This is just a hacked together python script from stackoverflow that can be used to add a proper +MIME header for file attachments to a mail. Pipe the outpit to sendmail -oi -t to send. + +usage: +mail-script "from@email.com" "to@email.com" "subject" /file/to/append < /body/of/mail | sendmail -oi -t +""") + exit(0) + +msg = EmailMessage() +msg['From'] = sys.argv[1] +msg['To'] = sys.argv[2] +msg['Subject'] = sys.argv[3] +# Don't mess with the preamble, the documentation is wrong to suggest you do + +msg.set_content(''.join([line for line in sys.stdin])) + +with open(sys.argv[4], 'r') as attachment: + #msg.add_attachment(attachment.read(), maintype='text', subtype='plain') + asStr = attachment.read() + asBytes = asStr.encode('utf-8') + msg.add_attachment(asBytes, maintype='application', subtype='octet-stream', filename="appendix.txt") + + print(msg.as_string())