Skip to content

Instantly share code, notes, and snippets.

@usagi
Created February 24, 2012 09:24
Show Gist options
  • Select an option

  • Save usagi/1899711 to your computer and use it in GitHub Desktop.

Select an option

Save usagi/1899711 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -lt 2 ]; then
echo "usage: $0 <SOURCE> <DESTINATION>"
exit 1
fi
force_trailing_slash() {
case $1 in
*/) echo -n "$1" ;;
*) echo -n "$1/" ;;
esac
}
SRC=`force_trailing_slash $1`
DST=`force_trailing_slash $2`
[ -d "${DST}3" ] && rm -rf "${DST}3"
[ -d "${DST}2" ] && mv "${DST}2" "${DST}3"
[ -d "${DST}1" ] && mv "${DST}1" "${DST}2"
[ -d "${DST}latest" ] && mv "${DST}latest" "${DST}1"
[ -d "${DST}latest" ] || mkdir -p "${DST}latest"
#[ -d "${DST}1" ] && \ # missing --link-dest dir will be ignored
LINK_DEST="--link-dest=../1"
echo "rsync -vvaHz --delete $LINK_DEST ${SRC} ${DST}latest/"
exec rsync -vvaHz --delete $LINK_DEST "${SRC}" "${DST}latest/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment