Skip to content

Instantly share code, notes, and snippets.

@bartman
Created August 11, 2010 20:49
Show Gist options
  • Save bartman/519729 to your computer and use it in GitHub Desktop.
Save bartman/519729 to your computer and use it in GitHub Desktop.
#!/bin/zsh
# (c) 2010 Bart Trojanowski <bart@jukie.net>
set -e
DSThost="mail.jukie.net"
DSTpath="public_html/tmp/"
DSTurl="http://$DSThost/~$(id -u -n)/${DSTpath#public_html/}"
die() { echo >&2 "$@" ; exit 1 ; }
[[ -z "$1" ]] && die "need at least one file to publish"
for f in $@ ; do
[[ -f "$f" ]] || die "$f: no such file"
[[ -r "$f" ]] || die "$f: cannot read file"
done
key() {
local file=$1
md5sum "$file" | cut -d ' ' -f 1
#| cut -c -8
}
typeset -a copied
typeset -a wgetcmds
for f in $@ ; do
k=$(key $f)
scp -q -q "$f" "$DSThost:$DSTpath/$k"
copied[$#copied+1]=$k
wgetcmds[$#wgetcmds+1]="wget -O $(basename $f) $DSTurl/$k"
done
echo .
for c in $wgetcmds[*] ; do
echo "$c"
done
echo .
read -s "ignoreme?Push ENTER to delete remote files; CTRL-C to keep them."
echo
for k in $copied[*] ; do
cmd="cd \"$DSTpath\" && echo \"$k $k\" | md5sum -c --status && rm -f \"$k\""
#echo $cmd
ssh -q -q $DSThost <<<"$cmd"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment