diff options
author | Norbert Thiebaud <norbert@sqdata.com> | 2010-11-20 23:06:14 -0600 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2010-11-30 20:25:21 -0600 |
commit | f61644158ef2f3a268f4af14a55b449ae10ac348 (patch) | |
tree | 368150d1c233072da0631f23aab065e1f348c73f /bin/mkworkdir | |
parent | correct the instructions:./download and ./g clone are implicit with make (diff) | |
download | core-f61644158ef2f3a268f4af14a55b449ae10ac348.tar.gz core-f61644158ef2f3a268f4af14a55b449ae10ac348.zip |
add some utility scripts to create new workdir
based on kohei blog on the subject, adapted for the 'bootstrap' build
Diffstat (limited to 'bin/mkworkdir')
-rwxr-xr-x | bin/mkworkdir | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/bin/mkworkdir b/bin/mkworkdir new file mode 100755 index 000000000000..10630f83062e --- /dev/null +++ b/bin/mkworkdir @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +BASEDIR=$(dirname $0) +GIT_NEW_WORKDIR=`which git-new-workdir 2>/dev/null` +if [ -z $GIT_NEW_WORKDIR ] ; then + GIT_NEW_WORKDIR="$BASEDIR/git-new-workdir" +fi + +print_help() { + echo "Usage: $1 [-s | --source bootstrap_reference_repo_path] [ -d | --workdir-base-path path] [ --as alias_name] [branch name]" + echo "--source is optional if you are currently in a bootstrap git repository, in which case that repository is used as source" + echo "--workdir-base-path is optional if you have defined LO_BASE_WORKDIR in your environement" + echo "--as is the name of the directory that will be the bootstrap of your new workdir ensemble. the default is the branch name used to create the workdir" + echo "the branch name is optional, the default is 'master'" +} + +die() { + echo $1 + exit 1 +} + +BOOTSTRAP_DIR= +DEST_DIR=${LO_BASE_WORKDIR:-} +BRANCH="master" + +while [ "${1:-}" != "" ] ; do + case $1 in + -s | --source ) + shift + BOOTSTRAP_DIR="$1" + ;; + -d | --workdir-base-path ) + shift + DEST_DIR="$1" + ;; + --as ) + shift + WKDIR_NAME="$1" + ;; + -h | --help ) + print_help $0 + exit 0 + ;; + -* ) + die "invalid option $1" + ;; + *) + if [ -z "$BRANCH" ] ; then + BRANCH="$1" + else + die "Too many arguments" + fi + ;; + esac + shift +done + + +if [ -z "$BOOTSTRAP_DIR" ]; then + BOOTSTRAP_DIR=$(git rev-parse --git-dir 2>/dev/null) || die "Cannot use the current working directory as implicit source: Not a git repository" + + case "$BOOTSTRAP_DIR" in + .git) + BOOTSTRAP_DIR="$(pwd)" + ;; + .) + cd .. && BOOTSTRAP_DIR=$(pwd) + ;; + esac +fi + +if [ -z "$DEST_DIR" ]; then + echo "destination directory is missing." + print_help $0 + exit 1 +fi + +if [ -z "$WKDIR_NAME" ]; then + WKDIR_NAME="$BRANCH" +fi + +if [ -e "$DEST_DIR/$WKDIR_NAME" ]; then + die "$DEST_DIR/$WKDIR_NAME already exists." +fi + +echo "===== bootstrap =====" +$GIT_NEW_WORKDIR $BOOTSTRAP_DIR "$DEST_DIR/$WKDIR_NAME" $BRANCH + +echo "creating directory $DEST_DIR/$WKDIR_NAME/clone" +mkdir -p "$DEST_DIR/$WKDIR_NAME/clone" || die "failed to create $DEST_DIR/$WKDIR_NAME/clone" + +REPOS=$(cat ${BASEDIR}/repo-list) + +cd "$DEST_DIR/$WKDIR_NAME" + +for repo in $REPOS; do + repo_path="${BOOTSTRAP_DIR}/clone/$repo" + echo "===== $repo =====" + $GIT_NEW_WORKDIR $repo_path "$DEST_DIR/$WKDIR_NAME/clone/$repo" $BRANCH + for link in $(ls ./clone/$repo) ; do + if [ ! -e "$link" ] ; then + echo "Creating link $link" + ln -s "./clone/$repo/$link" "$link" + fi + done + +done + |