Fwd: documentation help

Chuck Hagenbuch <[email protected]> Sat, 15 Nov 2003 15:36:19 -0500
Newsgroups gmane.comp.horde.documentation
Message-ID <[email protected]>
This message is in MIME format.

--=_ybi8lwqgj0g
Content-Type: text/plain; charset="ISO-8859-1"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit



----- Forwarded message from [email protected] -----
    Date: Sat, 15 Nov 2003 11:31:52 -0900
    From: Barsalou <[email protected]>
Reply-To: Barsalou <[email protected]>
 Subject: documentation help
      To: [email protected]

I am willing to help with documentation as well.  I have updateded the
update script to better use what is already in play and make changes to
that when a person does a CVS update.  (That's a lotta updates!)

It it not really ready for prime time, but I have been using it to keep
my version of horde up to date and have even used it to install on fresh
machine.

I like the install_packages tool that you provide....do you think we can
use that for getting Log and some of the other packages that are
sometimes missing?

I work mostly with RedHat/Fedora, so some of the script may be specific
to that...I will keep on improving it.

Mike
--
Barsalou <[email protected]>


----- End forwarded message -----


-chuck

--
Charles Hagenbuch, <[email protected]>
"I'm really... I'm not too fascinated by green food." - Average Joe
--=_ybi8lwqgj0g
Content-Type: text/x-sh; charset="iso-8859-15"; name="update_horde.sh"
Content-Disposition: attachment; filename="update_horde.sh"
Content-Transfer-Encoding: 7bit

#!/bin/sh
# $Horde: horde/scripts/update_horde.sh,v 1.2 2002/07/08 23:46:42 chuck Exp $
#
# update_horde.sh - Marcus I. Ryan <[email protected]>
#
# I wrote this script for me, so there isn't really much documentation.
# I'll explain the few things that come to mind:
#
# Summary: This script facilitates the updating and/or installation of horde
# and its applications.
# * Create a temporary directory to hold a new install
# * Make a patch file of the various *.dist files and their non-dist versions
# * Copy the existing install or download fresh from CVS
# * Apply the patch made earlier
# * Make a backup of the existing install
# * Make the new download the current install
#
# Options/Variables:
# EDITOR      - Current editor in use
# NUM_SLASHES - Since I'm too lazy to code a better way, this is the number
#               of slashes to remove from the path of the TMPDIR destination
#               to make the patch work relative to the temprary directory.
# NUM_BACKUPS - How many backups do we want to keep?
# WEBDIR      - The actual install directory (this is the live version)
# BACKUPDIR   - Where do we want to keep the backups
# TMPDIR      - Where do we build the new version to install
# RELEASES    - A list of the various "releases" we've defined
# <rel>_dir   - The name of the "horde" dir (usually horde) for release <rel>
# <rel>_ver   - A list of the various CVS distributions for realease <ver>
#               and the CVS branches to download.  See examples.
#
# WARNING: I do not currently have it set up to check if a patch fails 
#          completely.  This is not usually a problem, but if a *.dist file
#          is drastically updated it has been known to cause problems.
#          If you use this script, please keep an eye out for this.  That
#          said, I updated both my installs (release and head) with it
#          over 50 times before I finally had a problem.

trim () {
  echo $@
}

######## CONFIGURATION ########

EDITOR=vi
### MISC. OPTIONS ###
# Count slashes of TMPDIR variable and add 2
NUM_SLASHES=4
NUM_BACKUPS=5

### DIRECTORIES ###
WEBDIR=/var/www/html
BACKUPDIR=/root/backup
TMPDIR=/root/hordetmp

### RELEASES ###
RELEASES="release head"

# For each release, we need _dir and _ver settings

#This is the "array" of applications and versions to get
release_dir=horde
release_ver="
        horde-RELENG_2
	imp-RELENG_3
	turba-RELENG_1
	kronolith-RELENG_1
	nag-RELENG_1
	mnemo-RELENG_1
"
release_ver=`trim ${release_ver}`

head_dir=horde
head_ver="
        horde-HEAD
	framework-HEAD
	hermes-HEAD
	imp-HEAD
	turba-HEAD
	kronolith-HEAD
	nag-HEAD
        mnemo-HEAD
	moment-HEAD
"
head_ver=`trim ${head_ver}`

######## MAIN CODE ########

APPVER=$head_ver
HORDEDIR=$head_dir

# check to see if any command line args are specified
for arg in $*
do
  name=${arg%%=*}
  name=${name##--}
  value=${arg##*=}
  if [ "$name" = "release" ]; then
    APPVER=`eval echo '$'$value'_ver'`
    HORDEDIR=`eval echo '$'$value'_dir'`
    if [ "$APPVER" = "" -o "$HORDEDIR" = "" ]; then
      echo "ERROR: No settings for release $value"
    fi
    continue
  fi
  echo "Unknown option $arg ('$name' = '$value')"
  exit 1
done

echo "Verifying distribution list"
if [ ! "${APPVER%%[- ]*}" = "horde" ]; then
  echo "  horde MUST be the first item in the APPVER list!"
  exit 1
fi

echo "Determining temporary directory..."
EXISTS=`ls -d ${TMPDIR}/${HORDEDIR}.TMP.[0-9]* | head -1`
TMPDIR="${TMPDIR}/${HORDEDIR}.TMP.$$"

if [ ! -z ${EXISTS} ]; then
  echo "  Found an existing (aborted?) update of horde (${EXISTS})."
  read -p "  Should I use it? [Yes]" USE_EXISTING
  case ${USE_EXISTING} in
  [Nn]|[Nn][Oo])
    read -p "  Should I delete ${EXISTS}? [Yes]" DELETE_EXISTING
    case ${DELETE_EXISTING} in
    [Nn]|[Nn][Oo])
      echo "    Not deleting ${EXISTS}"
      ;;
    *)
      echo "    Deleting ${EXISTS}"
      rm -rf ${EXISTS}
      ;;
    esac
    ;;
  *)
    TMPDIR=${EXISTS}
    ;;
  esac
  unset USE_EXISTING
fi
if [ -e ${TMPDIR} ]; then
  echo "  Using ${TMPDIR}"
else
  echo "  Creating new directory ${TMPDIR}"
  mkdir ${TMPDIR}
  if [ ! -e ${TMPDIR} ]; then
    echo "ERROR: Couldn't create ${TMPDIR}"
    exit 1
  fi
fi

if [ -e "${WEBDIR}/${HORDEDIR}" ]; then
  read -p "Do you want to fetch new (N) or update (U)? [U] " FETCH_NEW
else
  FETCH_NEW=new
fi

case ${FETCH_NEW} in
  [Nn]|[Nn][Ee][Ww])
    for APP in ${APPVER}
    {
      app=${APP%%-*}
      rel=${APP##*-}
      if [ ${app} = ${APP} ]; then
        echo "  No release specified...assuming HEAD"
        rel=HEAD
      fi

      case ${app} in
        horde)
          APPDIR=${TMPDIR}
          EXISTDIR="${TMPDIR}/${HORDEDIR}"
          ;;
        *)
          APPDIR=${TMPDIR}/${HORDEDIR}
          EXISTDIR="${TMPDIR}/${HORDEDIR}/${app}"
          ;;
      esac

      if [ -e $EXISTDIR ]; then
        case ${REGET} in
        [Aa]|[Aa][Ll][Ll])
          echo "  Removing existing ${APPDIR}/${app}...";
          rm -rf ${APPDIR}/${app}
          echo "  Retrieving ${app} $rel..."
          cd ${APPDIR}
          cvs -Q -z3 -d :pserver:[email protected]:/repository co \
           -r $rel ${app}
          ;;
        [Nn][Oo][Nn][Ee])
          REGET="NONE"
          echo "  Using existing ${APPDIR}/${app}"
          ;;
        *)
          echo "  ${app} exists. Should I get ${app} anyway?"
          if [ "${app}" = "horde" ]; then
            echo "  NOTE: regetting horde does not clear out any existing files"
          fi
          read -p "   [Y]es/[N]o/[A]ll/None (default None): " REGET
          case ${REGET} in
          [Yy]|[Yy][Ee][Ss]|[Aa]|[Aa][Ll][Ll])
            echo "  Removing existing ${APPDIR}/${app}...";
            rm -rf ${APPDIR}/${app}
            echo "  Retrieving ${app} $rel..."
            cd ${APPDIR}
            cvs -Q -z3 -d :pserver:[email protected]:/repository co \
             -r $rel ${app}
            ;;
          [Nn]|[Nn][Oo])
            echo "  Using existing ${APPDIR}/${app}"
            ;;
          *)
            echo "  Using existing ${APPDIR}/${app}"
            REGET=NONE
            ;;
          esac
          ;;
        esac
      else
        echo -n "  Retrieving ${app} $rel..."
        cd ${APPDIR}
        cvs -Q -z3 -d :pserver:[email protected]:/repository co \
         -r $rel ${app}
	echo "done"
      fi
      if [ "$app" = "horde" -a "$HORDEDIR" != "horde" ]; then
	echo "  Moving ${TMPDIR}/horde to ${TMPDIR}/${HORDEDIR}"
        mv ${TMPDIR}/horde ${TMPDIR}/${HORDEDIR}
      fi
    }
    ;;
  *)
    if [ -e "${TMPDIR}/${HORDEDIR}" ]; then
       echo "Temporary directory already exists...using it"
    else
       mkdir ${TMPDIR}/${HORDEDIR}
    fi
    echo "Copying ${WEBDIR}/${HORDEDIR} to temporary directory ${TMPDIR}/${HORDEDIR}"
    cp -Rpf ${WEBDIR}/${HORDEDIR}/* ${TMPDIR}/${HORDEDIR}
    cd ${TMPDIR}/${HORDEDIR}
    cvs update -PdC
    ;;
esac

echo "Setting up config files..."
    for APP in ${APPVER}
    {
      app=${APP%%-*}
      rel=${APP##*-}
      if [ ${app} = ${APP} ]; then
        echo "  No release specified...assuming HEAD"
        rel=HEAD
      fi

      case ${app} in
        horde)
          APPDIR="${WEBDIR}/${HORDEDIR}"
          EXISTDIR="${TMPDIR}/${HORDEDIR}/config"
          ;;
        *)
          APPDIR="${WEBDIR}/${HORDEDIR}/${app}"
          EXISTDIR="${TMPDIR}/${HORDEDIR}/${app}/config"
          ;;
      esac
      cp -i --reply=no ${APPDIR}/config/*.php ${EXISTDIR}
    }

echo "Creating a patch file from existing config horde at ${WEBDIR}/${HORDEDIR}"
if [ -e ${TMPDIR}/update.patch ]; then
  read -p "  This directory includes a patch. Use it? [Yes]" USE_EXISTING
  case ${USE_EXISTING} in
  [Nn]|[Nn][Oo])
    echo "  Clearing existing update.patch"
    rm -f ${TMPDIR}/update.patch || exit 1
    ;;
  *)
    USE_EXISTING=YES
    ;;
  esac
fi

if [ ! -e ${TMPDIR}/update.patch ]; then
  if [ ! -e ${WEBDIR}/${HORDEDIR} ]; then
    echo "  No existing horde distribution found.  Can't create patch."
  else
    read -p "  Do you want to create a patch from the existing install? [Yes]" MAKE_PATCH
    case ${MAKE_PATCH} in
    [Nn]|[Nn][Oo])
      echo "  Not creating a patch"
      ;;
    *)
      echo "  Creating patch...this could take a bit..."
      find ${TMPDIR}/${HORDEDIR} -type f -name \*.dist -print \
       | perl -ne 's/\.dist[\r\n]*//; print "$_.dist\n$_\n";' \
       | xargs -n 2 diff -u > ${TMPDIR}/update.patch
      ;;
    esac
    unset MAKE_PATCH
  fi
fi

echo "  Copying unpatched default config files...to `pwd` "
find ${TMPDIR}/${HORDEDIR} -type f -name \*.dist -print \
 | perl -ne 'print "$_"; s/\.dist//; print "$_"' \
 | xargs -n 2 cp

echo "Applying patch..."
echo "  Clearing out any old reject files..."
find ${TMPDIR} -name \*.rej -type f -exec rm {} \; -print
echo "  Done."

if [ ! -e ${TMPDIR}/update.patch ]; then
  echo "  I can't seem to find the patch file ${TMPDIR}/update.patch!"
  read -p "  Do you want me to load all config files in $EDITOR? [No]" EDIT
  case ${EDIT} in
  [Yy]|[Yy][Ee][Ss])
    find ${TMPDIR}/${HORDEDIR} -type f -name \*.dist \
     | perl -ne 's/\.dist[\r\n]*//; print "$_\n";' \
     | xargs -n 2 echo $EDITOR > ${TMPDIR}/edit.sh
    sh ${TMPDIR}/edit.sh
    rm ${TMPDIR}/edit.sh 
    ;;
  *)
    echo "  WARNING: You need to change the config files later!"
    ;;
  esac
else
  if [ "${USE_EXISTING}" = "YES" ]; then
    echo "  We are using the default configuration files."
    read -p "  Should we apply the patch? [No] " PATCH
    case ${PATCH} in
    [Yy]|[Yy][Ee][Ss])
      PATCH=YES
      ;;
    *)
      PATCH=NO
      ;;
    esac
  fi

  if [ "${PATCH:=YES}" = "YES" ]; then
    echo "  running patch"
    cd ${TMPDIR}
    echo `pwd`
    FOO=`patch -p${NUM_SLASHES} -s < ${TMPDIR}/update.patch`
    if [  "${FOO}x" = "x" ]; then
      echo "  Patch applied successfully"
    else
      echo "The patch failed...we will edit the reject files by hand."
      find ${TMPDIR}/${HORDEDIR} -type f -name \*.rej \
       | perl -ne 's/\.rej[\r\n]*//; print "$_.rej\n$_\n"; ' \
       | xargs -n 1 echo $EDITOR > ${TMPDIR}/edit.sh
      sh ${TMPDIR}/edit.sh
      rm ${TMPDIR}/edit.sh
    fi
  fi
fi

read -p "Are you ready to put the new CVS into production? [Yes]" PROD
case ${PROD} in
[Nn]|[Nn][Oo])
  echo "${TMPDIR} has not been put in production."
  ;;
*)
  if [ -e ${WEBDIR}/${HORDEDIR} ]; then
    i=1
    while [ ${i} != ${NUM_BACKUPS} ]
    do
      if [ ! -e ${BACKUPDIR}/${HORDEDIR}.${i} ]; then
        break;
      fi
      i=$((${i}+1))
    done

    if [ ${i} = ${NUM_BACKUPS} ] && [ -e ${BACKUPDIR}/${HORDEDIR}.${i} ]; then
      echo "  Removing oldest backup directory (${BACKUPDIR}/${HORDEDIR}.${i})"
      rm -rf ${BACKUPDIR}/${HORDEDIR}.${i} || exit 1
    fi

    while [ ${i} != 1 ]
    do
      echo "  Moving ${BACKUPDIR}/${HORDEDIR}.$((${i}-1)) to ${BACKUPDIR}/${HORDEDIR}.${i}"
      mv ${BACKUPDIR}/${HORDEDIR}.$((${i}-1)) ${BACKUPDIR}/${HORDEDIR}.${i} || exit 1
      i=$((${i}-1))
    done

    echo "  Moving ${WEBDIR}/${HORDEDIR} to ${BACKUPDIR}/${HORDEDIR}.1"
    mv ${WEBDIR}/${HORDEDIR} ${BACKUPDIR}/${HORDEDIR}.1 || exit 1

    echo "  Moving ${TMPDIR}/${HORDEDIR} ${WEBDIR}/${HORDEDIR}"
    mv ${TMPDIR}/${HORDEDIR} ${WEBDIR}/${HORDEDIR} || exit 1

    echo "  Removing ${TMPDIR}"
    rm -rf ${TMPDIR}

    echo "New CVS horde is now in production!"
  else
    echo "${WEBDIR}/${HORDEDIR} does not exist.  Copying ${TMPDIR}/${HORDEDIR} to ${WEBDIR}/${HORDEDIR}"
    cp ${TMPDIR}/${HORDEDIR} ${WEBDIR}/${HORDEDIR}
  fi
  ;;
esac
#####

--=_ybi8lwqgj0g
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


-- 
Documentation mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]

--=_ybi8lwqgj0g--