Permalink
Browse files

Add a bit more flexibility to the build process.

  • Loading branch information...
1 parent 1a200a9 commit f1202627a7821380f85da02f77849282066112a6 @VictorLowther VictorLowther committed Aug 12, 2011
Showing with 93 additions and 12 deletions.
  1. +10 −1 build_crowbar.sh
  2. +83 −11 redhat-5.6-extra/build_lib.sh
View
@@ -131,6 +131,12 @@ fi
[[ $GEM_CACHE ]] || GEM_CACHE="$CACHE_DIR/gems"
[[ $AMI_CACHE ]] || AMI_CACHE="$CACHE_DIR/amis"
+ # Directory where we will look for our package lists
+ [[ $PACKAGE_LISTS ]] || PACKAGE_LISTS="$BUILD_DIR/extra/packages"
+
+ # Tree-ish to check out in the build-cache"
+ [[ $CACHE_REVISION ]] || CACHE_REVISION="master"
+
# Make any directories we don't already have
for d in "$PKG_CACHE" "$GEM_CACHE" "$ISO_LIBRARY" "$ISO_DEST" \
"$IMAGE_DIR" "$BUILD_DIR" "$AMI_CACHE" \
@@ -177,12 +183,15 @@ fi
cp -r "$CROWBAR_DIR/$OS_TOKEN-extra"/* "$BUILD_DIR/extra"
cp -r "$CROWBAR_DIR/change-image"/* "$BUILD_DIR"
+ # Make sure we have the right branch of the cache checked out
+ (cd "$CACHE_DIR"; git checkout -f "$CACHE_REVISION")
+
# If we were asked to update our cache, do it.
maybe_update_cache "$@"
# Copy our extra pkgs, gems, and amis over
debug "Copying pkgs, gems, and amis"
- copy_pkgs "$IMAGE_DIR/pool" "$PKG_CACHE" "$BUILD_DIR/extra/pkgs"
+ copy_pkgs "$IMAGE_DIR" "$PKG_CACHE" "$BUILD_DIR/extra/pkgs"
cp -r "$GEM_CACHE" "$BUILD_DIR/extra"
cp -r "$AMI_CACHE/." "$BUILD_DIR/ami/."
@@ -132,16 +132,10 @@ update_caches() {
chroot_install rubygems ruby-devel make
debug "Fetching Gems"
echo "There may be build failures here, we can safely ignore them."
- gem_re='([^0-9].*)-([0-9].*)'
+
for gem in "${GEMS[@]}"; do
- if [[ $gem =~ $gem_re ]]; then
- echo "${BASH_REMATCH[*]}"
- gemname="${BASH_REMATCH[1]}"
- gemver="${BASH_REMATCH[2]}"
- else
- gemname="$gem"
- gemver=''
- fi
+ gemname=${gem%%-[0-9]*}
+ gemver=${gem#$gemname-}
gemopts=(install --no-ri --no-rdoc)
[[ $gemver ]] && gemopts+=(--version "= ${gemver}")
in_chroot /usr/bin/gem "${gemopts[@]}" "$gemname"
@@ -153,12 +147,90 @@ update_caches() {
done < <(tac /proc/self/mounts |grep "$CHROOT")
}
+num_re='^[0-9]+$'
+__cmp() {
+ [[ $1 || $2 ]] || return 255 # neither 1 nor 2 or set, we are done
+ [[ $1 && ! $2 ]] && return 2 # 1 is set and 2 is not, 1 > 2
+ [[ ! $1 && $2 ]] && return 0 # 2 is set and 1 is not, 1 < 2
+ local a="$1" b="$2"
+ if [[ $a =~ $num_re && $b =~ $num_re ]]; then #both numbers, numeric cmp.
+ # make sure leading zeros do not confuse us
+ a=${a##0} b=${b##0}
+ ((${a:=0} > ${b:=0})) && return 2
+ (($a < $b)) && return 0
+ return 1
+ else # string compare
+ [[ $a > $b ]] && return 2
+ [[ $a < $b ]] && return 0
+ return 1
+ fi
+}
+
+vercmp(){
+ # $1 = version string of first package
+ # $2 = version string of second package
+ local ver1=()
+ local ver2=()
+ local i=0
+ IFS='.-_ ' read -rs -a ver1 <<< "$1"
+ IFS='.-_ ' read -rs -a ver2 <<< "$2"
+ for ((i=0;;i++)); do
+ __cmp "${ver1[$i]}" "${ver2[$i]}"
+ case $? in
+ 2) return 0;;
+ 0) return 1;;
+ 255) return 1;;
+ esac
+ done
+}
+
copy_pkgs() {
# $1 = pool directory to build initial list of excludes against
# $2 = directory to copy from
# $3 = directory to copy to.
+ declare -A pool_pkgs
+ declare -A dest_pool
+ local pkgname=''
+ local pkgs_to_copy=()
mkdir -p "$3"
- cp -r -t "$3" "$2"/*
+ while read pkg; do
+ [[ -f $pkg && $pkg = *.rpm ]] || continue
+ [[ $pkg = *.i?86.rpm ]] && continue
+ pkgname=${pkg%%-[0-9]*}
+ pkgver=${pkg#$pkgname-}
+ pkgname="${pkgname##*/}"
+ pool_pkgs["$pkgname"]="$pkgver"
+ done < <(find "$1/Server" -name '*.rpm')
+ ( cd "$2"
+ declare -A target_dirs
+ while read f; do
+ [[ -f $f && $f = *.rpm ]] || continue
+ [[ $f = *.i?86.rpm ]] && continue
+ pkgname=${f%%-[0-9]*}
+
+ pkgdir=${f%/*}
+ [[ ${target_dirs["pkgdir"]} ]] || target_dirs["$pkgdir"]=$pkgdir
+ pkgver=${BASH_REMATCH[2]%.*.rpm}
+ if [[ ${dest_pool["$pkgname"]} ]]; then
+ if vercmp "$pkgver" "${dest_pool["$pkgname"]}"; then
+ pkgs_to_copy[$((${#pkgs_to_copy[@]} - 1))]="$f"
+ dest_pool["$pkgname"]="$pkgver"
+ fi
+ elif [[ ${pool_pkgs["${pkgname##*/}"]} ]]; then
+ if vercmp "$pkgver" "${pool_pkgs["${pkgname##*/}"]}"; then
+ pkgs_to_copy+=("$f")
+ dest_pool["$pkgname"]="$pkgver"
+ fi
+ else
+ pkgs_to_copy+=("$f")
+ dest_pool["$pkgname"]="$pkgver"
+ fi
+ done < <(find . -name '*.rpm' |sort)
+ for d in "${target_dirs[@]}"; do
+ mkdir -p "$3/$d"
+ done
+ cp -r -t "$3" "${pkgs_to_copy[@]}"
+ )
}
maybe_update_cache() {
@@ -167,7 +239,7 @@ maybe_update_cache() {
# Download and stash any extra files we may need
# First, build our list of repos, ppas, pkgs, and gems
REPOS=()
- for pkgfile in "$BUILD_DIR/extra/packages/"*.list; do
+ for pkgfile in "$PACKAGE_LISTS/"*.list; do
[[ -f $pkgfile ]] || continue
while read pkg_type rest; do
case $pkg_type in

0 comments on commit f120262

Please sign in to comment.