initial testing on using bash to build repos

This commit is contained in:
Joe Ferguson 2014-09-17 18:06:08 -06:00 committed by Tianon Gravi
commit c7226afb23
1 changed files with 64 additions and 0 deletions

64
build.sh Executable file
View File

@ -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