commit c7226afb2397aa90fcda9a6f5c5a460713bbde9a Author: Joe Ferguson Date: Wed Sep 17 18:06:08 2014 -0600 initial testing on using bash to build repos diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a7126e7 --- /dev/null +++ b/build.sh @@ -0,0 +1,64 @@ +#!/bin/bash +set -e + +cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" + +# TODO config file of some kind +LIBDIR='../library' + +# arg handling: all args are [repo|repo:tag] +# no argument means build all repos in $LIBDIR +repos=( "$@" ) +if [ ${#repos[@]} -eq 0 ]; then + repos=( $(cd "$LIBDIR" && echo *) ) +fi +repos=( "${repos[@]%/}" ) + +# globals for handling the repo queue and repo info parsed from library +queue=() +declare -A repoGitRepo=() +declare -A repoGitRef=() +declare -A repoGitDir=() + +# gather all the `repo:tag` combos to build +for repoTag in "${repos[@]}"; do + if [ "$repoTag" = 'MAINTAINERS' ]; then + continue + fi + + if [ "${repoGitRepo[$repoTag]}" ]; then + queue+=( "$repoTag" ) + continue + fi + repo="${repoTag%:*}" + + # parse the repo library file + IFS=$'\n' + repoTagLines=( $(cat "$LIBDIR/$repo" | grep -vE '^#|^\s*$') ) + unset IFS + + tags=() + for line in "${repoTagLines[@]}"; do + tag="$(echo "$line" | awk -F ': +' '{ print $1 }')" + fullGitUrl="$(echo "$line" | awk -F ' +' '{ print $2 }')" + gitDir="$(echo "$line" | awk -F ' +' '{ print $3 }')" + + gitUrl="${fullGitUrl%%@*}" + gitRef="${fullGitUrl#*@}" + + repoGitRepo[$repo:$tag]="$gitUrl" + repoGitRef[$repo:$tag]="$gitRef" + repoGitDir[$repo:$tag]="$gitDir" + tags+=( "$repo:$tag" ) + done + + if [ "$repo" = "$repoTag" ]; then + # add all tags we just parsed + queue+=( "${tags[@]}" ) + else + queue+=( "$repoTag" ) + fi +done + +echo "${queue[@]}" +# TODO clone and build