office-gobmx/bin/mkworkdir
Norbert Thiebaud f61644158e add some utility scripts to create new workdir
based on kohei blog on the subject, adapted for the 'bootstrap' build
2010-11-30 20:25:21 -06:00

108 lines
2.6 KiB
Bash
Executable file

#!/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