summaryrefslogtreecommitdiff
path: root/bin/mkworkdir
blob: 9691ee1bd16e8eb0743d3150b35a6501191df47f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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

4d7511d7e49af14e3c8113bb1440e0eb04f40ad'>tdf#106681 Styles category for the Add Commands dialogMaxim Monastirsky 2017-04-25remove bitmaps from .src filesCaolán McNamara 2017-04-21gbuild: Remove MSVC 2013 legacy codeDavid Ostrovsky