123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- P_DARCS_SRV=http://darcs.openics.org
- P_DARCS_REP=kolter-dot-files
- P_LOG=darcs-$P_DARCS_REP.log
- P_TMPD=/tmp
- pdarcs_disp_log () {
- echo
- echo " | ERRORS |"
- echo "---8<---------------------------------------------------"
- cat $P_LOG
- echo "--------------------------------------------------->8---"
- echo
- }
- pdarcs_md5_diff () {
- # return 1 if different, 0 else
- _MD5SUM=$(whence md5sum)
- _MD5=$(whence md5)
- if [ -x "$_MD5SUM" ]; then
- MD5_1=$($_MD5SUM $1 |cut -d' ' -f1)
- MD5_2=$($_MD5SUM $2 |cut -d' ' -f1)
- elif [ -x "$_MD5" ]; then
- MD5_1=$($_MD5 -q $1)
- MD5_2=$($_MD5 -q $2)
- else
- MD5_1=1
- MD5_2=2
- fi
-
- if [ "$MD5_1" = "$MD5_2" ]; then
- echo 0
- else
- echo 1
- fi
- }
- pdarcs_clicnf_upd () {
- PREV_CWD=$(pwd)
- echo "**** updating files from '$P_DARCS_REP' ****"
- echo
- [ -n "$TMPDIR" ] && P_TMPD=$TMPDIR
- cd $P_TMPD
- echo " -> using temp directory '$P_TMPD'"
- echo -n " -> deleting any previous darcs repository local copy '$P_DARCS_REP' ... "
- rm -rf $P_DARCS_REP >/dev/null 2>&1
- [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
-
- echo -n " -> getting darcs repository '$P_DARCS_SRV/$P_DARCS_REP/' ... "
- darcs get $P_DARCS_SRV/$P_DARCS_REP/ > $P_LOG 2>&1
- [ $? != 0 ] && echo "[FAILED]" && pdarcs_disp_log && exit 1
- echo "[OK]"
-
- echo -n " -> changing directory '$P_DARCS_REP' ... "
- cd $P_DARCS_REP >/dev/null 2>&1
- [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
-
- echo -n " -> cleaning directory ... "
- rm -rf _darcs >/dev/null 2>&1
- [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
-
- for d in $(find -not -name . -type d | xargs) ; do
- dir=$HOME/$d
- [ -d "$dir" ] && continue
- echo -n " -> creating directory '$dir' ... "
- mkdir -p $dir >/dev/null 2>&1
- [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
- done
-
- for f in $(find -not -name . -not -type d | xargs) ; do
- file=$HOME/$f
- upd=0
- [ ! -e "$file" ] && upd=1
- if [ $upd = 0 ]; then
- upd=$(pdarcs_md5_diff $f $file)
- fi
- if [ $upd = 1 ]; then
- echo -n " -> updating file '$file' ... "
- rm -f $file >/dev/null 2>&1
- cp -f $f $file >/dev/null 2>&1
- [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
- fi
- done
-
- echo -n " -> changing directory for parent directory ... "
- cd .. >/dev/null 2>&1
- [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
- echo -n " -> deleting darcs repository local copy '$P_DARCS_REP' ... "
- rm -rf $P_DARCS_REP $P_LOG >/dev/null 2>&1
- [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
-
- cd $PREV_CWD >/dev/null 2>&1
- echo
- echo "**** end ****"
- }
- alias cliupd="pdarcs_clicnf_upd"
|