migrate file upload to rsync
This commit is contained in:
parent
48c38c8159
commit
cca0c68b27
4 changed files with 21 additions and 14 deletions
25
.aliases.sh
25
.aliases.sh
|
@ -78,26 +78,31 @@ function upload() {
|
|||
if [ "$#" -ne 2 ]; then
|
||||
echo "Invalid number of parameters"
|
||||
echo "usage: upload <target_dir> <file>"
|
||||
echo "example: upload tmp img.png"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -z "$FILE_STORAGE_API_KEY" ]; then
|
||||
echo "No API key set, did you forget to 'source ~/.tokens'?"
|
||||
if [ -z "$RSYNC_HOST" ]; then
|
||||
echo "No rsync env variables set, did you forget to source?"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Uploading to $1/$2"
|
||||
|
||||
curl --request PUT \
|
||||
--url "$FILE_STORAGE_API_URL/$1/$2" \
|
||||
--header "AccessKey: $FILE_STORAGE_API_KEY" \
|
||||
--header "Content-Type: application/octet-stream" \
|
||||
--header "accept: application/json" \
|
||||
--data-binary "@$2"
|
||||
rsync \
|
||||
--verbose \
|
||||
--recursive \
|
||||
--rsh "ssh -p $RSYNC_PORT -i $HOME/.ssh/$RSYNC_KEY" \
|
||||
"$2" \
|
||||
"$RSYNC_USER@$RSYNC_HOST:$RSYNC_DEST/$1"
|
||||
|
||||
if [ "$?" -ne 0 ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "$FILE_STORAGE_EXTERNAL_URL/$1/$2 (copied to clipboard)"
|
||||
echo "$FILE_STORAGE_EXTERNAL_URL/$1/$2" | xclip -sel clip
|
||||
echo "https://$RSYNC_HOST/$1/$2 (copied to clipboard)"
|
||||
echo "https://$RSYNC_HOST/$1/$2" | xclip -sel clip
|
||||
}
|
||||
|
||||
function upload_all() {
|
||||
|
|
5
.rsync_template
Normal file
5
.rsync_template
Normal file
|
@ -0,0 +1,5 @@
|
|||
RSYNC_USER=foo
|
||||
RSYNC_HOST=bar.com
|
||||
RSYNC_PORT=22
|
||||
RSYNC_KEY=my-ssh-key
|
||||
RSYNC_DEST=/var/www
|
|
@ -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
|
2
link.sh
2
link.sh
|
@ -9,4 +9,4 @@ sudo chmod +x ~/bin/*.sh
|
|||
mkdir -p ~/.config
|
||||
stow --target=$HOME/.config .config
|
||||
|
||||
cp --update=none .tokens_template ~/.tokens
|
||||
cp --update=none .rsync_template ~/.rsync
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue