dennybaa
7/29/2011 - 2:04 PM

mvstage

mvstage

#!/bin/bash

cd /home/gitupdate

DESTS=("/etc/twiket" "/twiket")
SRCS=("twiket/etc" "twiket")

i=0
REV=`date +'%Y%m%d.%H%M%S'`

for s in ${DESTS[@]}; do
  # do on first run
  if [[ ! -L "$s" ]]; then
    cp -r ${s} ${s}.cur
    mv ${s} ${s}.pre
    ln -s ${s}.cur ${s}
  fi
  # move
  ls -1td ${s}?* | sed '1d' | while read old_rev; do
    rm -rf "${old_rev}"
  done
  cp -r "${SRCS[i]}" "${s}_${REV}"
  rm "${s}" ; ln -s "${s}_${REV}" "${s}"
  prev=`ls -1td ${s}?* | tail -n1`
  mv "${prev}" "${s}_pre"
  i=$((i+1))
done

# post move
rm -rf /twiket/etc
rm  /etc/twiket/twiketapi/modules &> /dev/null
ln -s /twiket_${REV}/twiketapi/mcore_modules /etc/twiket/twiketapi/modules