Skip to content

Instantly share code, notes, and snippets.

@jusa
Created May 8, 2014 12:35
Show Gist options
  • Select an option

  • Save jusa/a2bfd0e3310f41a36590 to your computer and use it in GitHub Desktop.

Select an option

Save jusa/a2bfd0e3310f41a36590 to your computer and use it in GitHub Desktop.
If it's worth doing it's worth overdoing. Nice with public key auth for uploading files.
#!/bin/bash
TARGET_HOST="example.org"
TARGET_DIR="webapps/upload_static"
TARGET_WEB="http://example.org/tmp"
declare -a uploaded
count=0
while [ $# -gt 0 ]; do
fname="$1"
bname="$(basename "$fname")"
dname="$(dirname "$fname")"
if [ ! -e "$fname" ]; then
echo "$bname SKIPPED, doesn't exist."
shift
continue
fi
size=$(du -s "$fname" | cut -d" " -f1)
((size=size/10))
echo -n "$bname $size / 0"
# Fucking magic
tar -C "$dname" -c -z "$bname" | ssh $TARGET_HOST tar -C $TARGET_DIR -x -z --checkpoint=10 --checkpoint-action=exec="bash\ -c\ set\|grep\ TAR_CHECKPOINT\|cut\ -d=\ -f2\|xargs\ echo\ -n\ '\r'\"$bname\"\ $size\ /"
# Old line for reference
#tar -C "$dname" -c -z "$bname" | ssh $TARGET_HOST tar -C $TARGET_DIR --checkpoint=10 --checkpoint-action=dot -x -z
if [ $? -eq 0 ]; then
ssh $TARGET_HOST chmod -R go+r $TARGET_DIR/"$bname" 2>/dev/null
echo -e "\r$bname $size / $size OK"
uploaded[$count]="$bname"
((count++))
else
echo -e "\r$bname $size / $size ERROR"
fi
shift
done
echo ""
if [ "$count" == "0" ]; then
echo "No files uploaded!"
exit 0
fi
((last=${#uploaded[@]}-1))
for i in $(seq 0 $last); do
echo "--> $TARGET_WEB/${uploaded[$i]// /%20}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment