Created
June 2, 2023 03:30
-
-
Save raffifu/447c46510d6b22140d50518ff4eac99e to your computer and use it in GitHub Desktop.
Backup Video to Telegram & S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SPACE="<space-name>" | |
REGION="<region-code>" | |
STORAGETYPE="STANDARD" | |
KEY="<key>" | |
SECRET="$SECRET" | |
function uploadVideo() { | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 [file-to-upload]" | |
exit 1 | |
fi | |
file="$1" | |
space="${SPACE}" | |
date=$(date -u +"%a, %d %b %Y %T GMT") | |
acl="x-amz-acl:private" | |
content_type="application/octet-stream" | |
storage_type="x-amz-storage-class:${STORAGETYPE}" | |
string="PUT\n\n$content_type\n$date\n$acl\n$storage_type\n/$space${file:14}" | |
# This is custom binary to generate HMAC SHA1 | |
# Command below equal to echo -en "${string}" | openssl -hmac sha1 "$SECRET" | base64 | |
signature=$(hmac_sha1 "$SECRET" "$(echo -en "${string}")" | base64) | |
curl -s -k -X PUT -T "$file" \ | |
-H "Host: $space.${REGION}.digitaloceanspaces.com" \ | |
-H "Date: $date" \ | |
-H "Content-Type: $content_type" \ | |
-H "$storage_type" \ | |
-H "$acl" \ | |
-H "Authorization: AWS ${KEY}:$signature" \ | |
"https://$space.${REGION}.digitaloceanspaces.com${file:14}" | |
} | |
echo "Triggered at $(date)" | |
for file in /tmp/sd/record/*/*.mp4; do | |
if ! [ -f $file ]; then | |
echo "Not Found" | |
exit 1 | |
fi | |
uploadVideo $file | |
if [ $? -ne 0 ]; then | |
echo "Upload failed for $file" | |
exit 1 | |
fi | |
rm $file | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CHAT_ID=<your-chat-id> # Get it from https://t.me/myidbot | |
BOT_TOKEN=$SECRET_BOT_TOKEN | |
function sendText() { | |
curl -k -X POST -H "Content-Type:multipart/form-data" -F chat_id=$CHAT_ID -F text="$1" "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" | |
} | |
function sendVideo() { | |
curl -k -X POST -H "Content-Type:multipart/form-data" -F chat_id=$CHAT_ID -F video=@$1 -F caption="Filename: $1" "https://api.telegram.org/bot$BOT_TOKEN/sendVideo" | |
} | |
sendText "Script Triggered at $(date)" | |
for file in /tmp/sd/record/*/*.mp4; do | |
if ! [ -f $file ]; then | |
echo "Not Found" | |
exit 1 | |
fi | |
sendVideo $file | |
rm $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment