#!/bin/sh shout() { echo "$0: $*" >&2; } die() { shout "$*"; exit 111; } try() { "$@" || die "cannot $*"; } # Designed to fetch -RELEASE, -STABLE, and -CURRENT via cron # (being used for crochet-freebsd builds) # # ALLCAPS variables below can be passed to this script as ENV at runtime, e.g.: # $ REL="9.2.1" thisprogram # can run from cron easily, # 1 5 * * * USER lockf -t 300 /tmp/fetchsrcs.lock /usr/local/bin/fetchsrcs /home/USER/srcs logger "START: '$0 $*'" if [ "${1}" != "" ] ; then _srcs="${1}" else die "Need one path argument to continue, (where to put sources, e.g. ${HOME}/srcs )." fi # SVN mirror # http://www5.us.freebsd.org/doc/handbook/svn-mirrors.html MIRROR="${MIRROR:-https://svn0.us-east.FreeBSD.org}" # the 3 mainline FreeBSD branches, # RELEASE, STABLE, and CURRENT REL="${REL:-9.2.0}" # actual: base/release/9.2.0 STA="${STA:-10}" # actual: base/stable/10 CUR="${CUR:-11}" # actual: base/head (using version as nickname here) # LOCAL PATHS _localrel="${_srcs}/${REL}-RELEASE" _localsta="${_srcs}/${STA}-STABLE" _localcur="${_srcs}/${CUR}-CURRENT" # REMOTE repo url paths _reporel="${MIRROR}/base/release/${REL}" _reposta="${MIRROR}/base/stable/${STA}" _repocur="${MIRROR}/base/head" ## action try mkdir -p "${_srcs}" fetchbranch() { # accepts args: remote, local _remote="$1" _local="$2" if [ ! -d "${_local}" ] ; then try cd "${_srcs}" try svn checkout --non-interactive --quiet "${_remote}" "${_local}" else try cd "${_local}" try svn cleanup --non-interactive "${_svnflags}" # a blunt hammer to make this script more reliable try svn update --non-interactive --quiet "${_svnflags}" fi } fetchbranch "${_reporel}" "${_localrel}" fetchbranch "${_reposta}" "${_localsta}" fetchbranch "${_repocur}" "${_localcur}" logger "FINISH: '$0 $*'" true