cvsupdate.sh 3.0 KB

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