cliupd.zsh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. P_DARCS_SRV=http://darcs.openics.org
  2. P_DARCS_REP=kolter-dot-files
  3. P_LOG=darcs-$P_DARCS_REP.log
  4. P_TMPD=/tmp
  5. pdarcs_disp_log () {
  6. echo
  7. echo " | ERRORS |"
  8. echo "---8<---------------------------------------------------"
  9. cat $P_LOG
  10. echo "--------------------------------------------------->8---"
  11. echo
  12. }
  13. pdarcs_md5_diff () {
  14. # return 1 if different, 0 else
  15. _MD5SUM=$(whence md5sum)
  16. _MD5=$(whence md5)
  17. if [ -x "$_MD5SUM" ]; then
  18. MD5_1=$($_MD5SUM $1 |cut -d' ' -f1)
  19. MD5_2=$($_MD5SUM $2 |cut -d' ' -f1)
  20. elif [ -x "$_MD5" ]; then
  21. MD5_1=$($_MD5 -q $1)
  22. MD5_2=$($_MD5 -q $2)
  23. else
  24. MD5_1=1
  25. MD5_2=2
  26. fi
  27. if [ "$MD5_1" = "$MD5_2" ]; then
  28. echo 0
  29. else
  30. echo 1
  31. fi
  32. }
  33. pdarcs_clicnf_upd () {
  34. PREV_CWD=$(pwd)
  35. echo "**** updating files from '$P_DARCS_REP' ****"
  36. echo
  37. [ -n "$TMPDIR" ] && P_TMPD=$TMPDIR
  38. cd $P_TMPD
  39. echo " -> using temp directory '$P_TMPD'"
  40. echo -n " -> deleting any previous darcs repository local copy '$P_DARCS_REP' ... "
  41. rm -rf $P_DARCS_REP >/dev/null 2>&1
  42. [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
  43. echo -n " -> getting darcs repository '$P_DARCS_SRV/$P_DARCS_REP/' ... "
  44. darcs get $P_DARCS_SRV/$P_DARCS_REP/ > $P_LOG 2>&1
  45. [ $? != 0 ] && echo "[FAILED]" && pdarcs_disp_log && exit 1
  46. echo "[OK]"
  47. echo -n " -> changing directory '$P_DARCS_REP' ... "
  48. cd $P_DARCS_REP >/dev/null 2>&1
  49. [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
  50. echo -n " -> cleaning directory ... "
  51. rm -rf _darcs >/dev/null 2>&1
  52. [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
  53. for d in $(find -not -name . -type d | xargs) ; do
  54. dir=$HOME/$d
  55. [ -d "$dir" ] && continue
  56. echo -n " -> creating directory '$dir' ... "
  57. mkdir -p $dir >/dev/null 2>&1
  58. [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
  59. done
  60. for f in $(find -not -name . -not -type d | xargs) ; do
  61. file=$HOME/$f
  62. upd=0
  63. [ ! -e "$file" ] && upd=1
  64. if [ $upd = 0 ]; then
  65. upd=$(pdarcs_md5_diff $f $file)
  66. fi
  67. if [ $upd = 1 ]; then
  68. echo -n " -> updating file '$file' ... "
  69. rm -f $file >/dev/null 2>&1
  70. cp -f $f $file >/dev/null 2>&1
  71. [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
  72. fi
  73. done
  74. echo -n " -> changing directory for parent directory ... "
  75. cd .. >/dev/null 2>&1
  76. [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
  77. echo -n " -> deleting darcs repository local copy '$P_DARCS_REP' ... "
  78. rm -rf $P_DARCS_REP $P_LOG >/dev/null 2>&1
  79. [ $? = 0 ] && echo "[OK]" || echo "[FAILED]"
  80. cd $PREV_CWD >/dev/null 2>&1
  81. echo
  82. echo "**** end ****"
  83. }
  84. alias cliupd="pdarcs_clicnf_upd"