migrate file upload to rsync

This commit is contained in:
Lauri Räsänen 2025-01-09 21:35:30 +02:00
parent 48c38c8159
commit cca0c68b27
4 changed files with 21 additions and 14 deletions

View file

@ -78,26 +78,31 @@ function upload() {
if [ "$#" -ne 2 ]; then if [ "$#" -ne 2 ]; then
echo "Invalid number of parameters" echo "Invalid number of parameters"
echo "usage: upload <target_dir> <file>" echo "usage: upload <target_dir> <file>"
echo "example: upload tmp img.png"
return return
fi fi
if [ -z "$FILE_STORAGE_API_KEY" ]; then if [ -z "$RSYNC_HOST" ]; then
echo "No API key set, did you forget to 'source ~/.tokens'?" echo "No rsync env variables set, did you forget to source?"
return return
fi fi
echo "Uploading to $1/$2" echo "Uploading to $1/$2"
curl --request PUT \ rsync \
--url "$FILE_STORAGE_API_URL/$1/$2" \ --verbose \
--header "AccessKey: $FILE_STORAGE_API_KEY" \ --recursive \
--header "Content-Type: application/octet-stream" \ --rsh "ssh -p $RSYNC_PORT -i $HOME/.ssh/$RSYNC_KEY" \
--header "accept: application/json" \ "$2" \
--data-binary "@$2" "$RSYNC_USER@$RSYNC_HOST:$RSYNC_DEST/$1"
if [ "$?" -ne 0 ]; then
return
fi
echo "" echo ""
echo "$FILE_STORAGE_EXTERNAL_URL/$1/$2 (copied to clipboard)" echo "https://$RSYNC_HOST/$1/$2 (copied to clipboard)"
echo "$FILE_STORAGE_EXTERNAL_URL/$1/$2" | xclip -sel clip echo "https://$RSYNC_HOST/$1/$2" | xclip -sel clip
} }
function upload_all() { function upload_all() {

5
.rsync_template Normal file
View file

@ -0,0 +1,5 @@
RSYNC_USER=foo
RSYNC_HOST=bar.com
RSYNC_PORT=22
RSYNC_KEY=my-ssh-key
RSYNC_DEST=/var/www

View file

@ -1,3 +0,0 @@
FILE_STORAGE_API_KEY=my-secret-key
FILE_STORAGE_API_URL=https://my-file-host-api.url
FILE_STORAGE_EXTERNAL_URL=https://hello-friend-have-a-file.url

View file

@ -9,4 +9,4 @@ sudo chmod +x ~/bin/*.sh
mkdir -p ~/.config mkdir -p ~/.config
stow --target=$HOME/.config .config stow --target=$HOME/.config .config
cp --update=none .tokens_template ~/.tokens cp --update=none .rsync_template ~/.rsync