summaryrefslogtreecommitdiff
path: root/bin/mkworkdir
diff options
context:
space:
mode:
Diffstat (limited to 'bin/mkworkdir')
-rwxr-xr-xbin/mkworkdir103
1 files changed, 103 insertions, 0 deletions
diff --git a/bin/mkworkdir b/bin/mkworkdir
new file mode 100755
index 000000000000..9691ee1bd16e
--- /dev/null
+++ b/bin/mkworkdir
@@ -0,0 +1,103 @@
+#!/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 --show-toplevel 2>/dev/null) || die "Cannot use the current working directory as implicit source: Not a git repository"
+ if [ -n "$BOOTSTRAP_DIR" ] ; then
+ if [ "$(basename $(git config remote.origin.url))" != "bootstrap" ] ; then
+ die "Cannot use the current working directory as implicit source: Not a bootstrap git repository"
+ fi
+ fi
+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
+