cvsupdate.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. _find_cvs() {
  3. for _basepath in /{var/,usr/local/,}cvs ; do
  4. if [ -d ${_basepath}/CVSROOT -a \
  5. -d ${_basepath}/src -a \
  6. -d ${_basepath}/ports -a \
  7. -d ${_basepath}/xenocara ]; then
  8. CVSROOT=${_basepath}
  9. return 0
  10. fi
  11. done
  12. return 1
  13. }
  14. _usage() {
  15. echo "Usage: `basename $0` [-h] [-t TAG]" 1>&2
  16. }
  17. # Set the cvstag to an empty string, so that we can check if it was set via -t
  18. TAG=
  19. CVSOPTS="-Pd"
  20. # Parse the command line options
  21. while getopts ht: OPT; do
  22. case "${OPT}" in
  23. h) _usage
  24. exit 0
  25. ;;
  26. t) TAG="-r${OPTARG}"
  27. ;;
  28. \?) # Error from getopts
  29. _usage
  30. exit 1
  31. ;;
  32. esac
  33. done
  34. BSDSRCDIR=$(grep BSDSRCDIR /etc/mk.conf 2>/dev/null | sed 's/^.*=//g')
  35. BSDSRCDIR=${BSDSRCDIR:=/usr/src}
  36. # Set the CVSROOT, if there is an @ in the cvs root we will use compression
  37. if ! _find_cvs ; then
  38. # Try to get the CVSROOT from the existing source tree
  39. _cvsroot=${BSDSRCDIR}/CVS/Root
  40. test -e ${_cvsroot} \
  41. && CVSROOT=$(cat ${_cvsroot} | sed -e 's/[[:space:]]*//')
  42. COMPRESS=$(echo ${CVSROOT} | awk '/@/ { print "-z3"; }')
  43. fi
  44. # There is nothing we can do unless some CVSROOT was found
  45. test -z ${CVSROOT} && { echo "Unable to deduce CVSROOT, exiting..."; exit 2; }
  46. # Create the log directory if not existant
  47. mkdir -p ${HOME}/cvslogs
  48. # Create the Tag flag for cvs. Either from the uname output or an empty var
  49. # for current systems
  50. # The Tag file should not exist on -current trees
  51. if [ -f ${BSDSRCDIR}/CVS/Tag -a -z "${TAG}" ]; then
  52. # Make the openbsd specific tag for the system.
  53. TAG=$(uname -s -r | awk '{ print toupper($0); }' | tr " ." _)
  54. TAG="-r${TAG}"
  55. fi
  56. case ${TAG} in
  57. *HEAD)
  58. TAG=""
  59. CVSOPTS="-PdA"
  60. ;;
  61. *)
  62. ;;
  63. esac
  64. # The date we are updateing the sources on.
  65. DATE=$(date +%F)
  66. # Update ${BSDSRCDIR} (if it exists)
  67. if [ -d "${BSDSRCDIR}/CVS" ]; then
  68. echo "Starting CVS update for ${BSDSRCDIR} at $(date +%T)."
  69. cd "${BSDSRCDIR}" && \
  70. cvs -R ${COMPRESS} -d ${CVSROOT} -q up ${TAG} ${CVSOPTS} 2>&1 \
  71. | tee -a "${HOME}/cvslogs/cvs-src-${DATE}"
  72. echo "Finished CVS update for ${BSDSRCDIR} at $(date +%T)."
  73. else
  74. echo "Skipping ${BSDSRCDIR} (does not exist)"
  75. fi
  76. PORTSDIR=$(grep PORTSDIR= /etc/mk.conf 2>/dev/null | sed 's/^.*=//g')
  77. PORTSDIR=${PORTSDIR:=/usr/ports}
  78. # Update ${PORTSDIR} if the directory exists
  79. if [ -d "${PORTSDIR}/CVS" ]; then
  80. echo "Starting CVS update for ${PORTSDIR} at $(date +%T)."
  81. cd "${PORTSDIR}" && \
  82. cvs -R ${COMPRESS} -d ${CVSROOT} -q up ${TAG} ${CVSOPTS} 2>&1 \
  83. | tee -a "${HOME}/cvslogs/cvs-ports-${DATE}"
  84. echo "Finished CVS update for ${PORTSDIR} at $(date +%T)."
  85. else
  86. echo "Skipping ${PORTSDIR} (does not exist)"
  87. fi
  88. # Update $XSRCDIR if the directory exists
  89. XSRCDIR=$(grep XSRCDIR /etc/mk.conf 2>/dev/null| sed 's/^.*=//g')
  90. XSRCDIR=${XSRCDIR:=/usr/xenocara}
  91. if [ -d "${XSRCDIR}/CVS" ]; then
  92. echo "Starting CVS update for ${XSRCDIR}"
  93. cd "${XSRCDIR}" && \
  94. cvs -R ${COMPRESS} -d ${CVSROOT} -q up ${TAG} ${CVSOPTS} 2>&1 \
  95. | tee -a "${HOME}/cvslogs/cvs-xenocara-${DATE}"
  96. echo "Finished CVS update for ${XSRCDIR} at $(date +%T)."
  97. else
  98. echo "Skipping ${XSRCDIR} (does not exist)"
  99. fi