mulle-bootstrap
5de2fbd6
 #! /bin/sh
 #
 #   Copyright (c) 2015 Nat! - Mulle kybernetiK
 #   All rights reserved.
 #
 #   Redistribution and use in source and binary forms, with or without
 #   modification, are permitted provided that the following conditions are met:
 #
 #   Redistributions of source code must retain the above copyright notice, this
 #   list of conditions and the following disclaimer.
 #
 #   Redistributions in binary form must reproduce the above copyright notice,
 #   this list of conditions and the following disclaimer in the documentation
 #   and/or other materials provided with the distribution.
 #
 #   Neither the name of Mulle kybernetiK nor the names of its contributors
 #   may be used to endorse or promote products derived from this software
 #   without specific prior written permission.
 #
 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 #   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 #   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 #   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 #   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 #   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 #   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 #   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 #   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 #   POSSIBILITY OF SUCH DAMAGE.
 
93bd7113
 VERSION=0.9.1
5de2fbd6
 
 #
 # This is the main user interface to mulle-bootstrap
 # sorta like git
 #
 BOOTSTRAP_SUBDIR=.bootstrap
 
 PATH="/usr/local/libexec/mulle-bootstrap:$PATH"
 export PATH
 
8e817cc1
 #
 # simple option handling
 #
422c21da
 if [ "$1" = "-a" ]
a7b563e1
 then
    MULLE_BOOTSTRAP_ANSWER="NO"
    export MULLE_BOOTSTRAP_ANSWER
    shift
422c21da
 else
    if [ "$1" = "-y" ] #  basically auto symlink everything
    then
       MULLE_BOOTSTRAP_ANSWER="YES"
       export MULLE_BOOTSTRAP_ANSWER
       shift
    fi
a7b563e1
 fi
 
422c21da
 
8e817cc1
 if [ "$1" = "-n" ]
 then
a7b563e1
    MULLE_BOOTSTRAP_DRY_RUN="YES"
8e817cc1
    export MULLE_BOOTSTRAP_DRY_RUN
    shift
 fi
 
93bd7113
 if [ "$1" = "-t" ]
3be635de
 then
93bd7113
    MULLE_BOOTSTRAP_TRACE="1848"
    export MULLE_BOOTSTRAP_TRACE
 
3be635de
    GITFLAGS="-v"
    export GITFLAGS
    shift
28ed6b30
 else
93bd7113
    if [ "$1" = "-v" ]
28ed6b30
    then
d7f96955
       if [ -z "${MULLE_BOOTSTRAP_TRACE}" ]
       then
93bd7113
          MULLE_BOOTSTRAP_TRACE="VERBOSE"
d7f96955
          export MULLE_BOOTSTRAP_TRACE
       fi
       GITFLAGS="-v"
28ed6b30
       export GITFLAGS
       shift
d7f96955
    else
93bd7113
       if [ "$1" = "-V" ]
d7f96955
       then
93bd7113
          if [ -z "${MULLE_BOOTSTRAP_TRACE}" ]
          then
             MULLE_BOOTSTRAP_TRACE="ALL"
             export MULLE_BOOTSTRAP_TRACE
          fi
          GITFLAGS="-v"
d7f96955
          export GITFLAGS
          shift
93bd7113
       else
          if [ "$1" = "-s" ] # silent
          then
             MULLE_BOOTSTRAP_TRACE=
             MULLE_BOOTSTRAP_TERSE="YES"
             export MULLE_BOOTSTRAP_TERSE
             GITFLAGS="-q"
             export GITFLAGS
             shift
          fi
d7f96955
       fi
28ed6b30
    fi
3be635de
 fi
 
 
40fe269d
 usage()
 {
    cat <<EOF
93bd7113
 usage: mulle-bootstrap [-a|-y][-n][-v|-s|-t] [command] [--help]
fa860fc9
        version ${VERSION}
40fe269d
 
  Specify the -h or --help option after each command to get more help.
 
28ed6b30
  Flags (-n must be first, if present)
a7b563e1
    -a        : always chose default answer to questions
422c21da
    -y        : always say yes to questions (scripts wont be checked)
93bd7113
 
40fe269d
    -n        : do nothing creative or destructive
93bd7113
 
d7f96955
    -v        : be more verbose (-V even more verbose)
40fe269d
    -s        : be more terse
93bd7113
    -t        : turns on shell tracing for development
40fe269d
 
  Common user commands:
    bootstrap : does fetch and build recursively [default]
    nomagic   : does fetch and build, but not recursively
    clean     : cleans mulle-bootstrap produced files.
 
  Common maintainer commands:
    init      : initializes a bootstrap project
    xcode     : sets up the xcodeproj settings
    tag       : tag this project and fetched repositories
 
  Specialized commands:
    build     : builds fetched repositories
    fetch     : fetches required repositories recursively.
    update    : updates repositories (pull).
 EOF
 }
 
 
8ca22e9e
 check_and_usage_and_help()
 {
    cat <<EOF
 usage: bootstrap
    There is nothing more to it.
 EOF
 }
 
 
5de2fbd6
 command=${1:-"bootstrap"}
 shift
 
 
 bootstrap()
 {
40fe269d
    if [ "$1" = "-h" -o "$1" = "--help" ]
    then
        check_and_usage_and_help >&2
        exit 1
    fi
5de2fbd6
 
    #
    # this is run when checking mulle-project itself out
    #
    if [ -f mulle-bootstrap-local-environment.sh -a -x install.sh ]
    then
       . install.sh "$@"
       export MULLE_BOOTSTRAP=mulle-bootstrap
3ed530a3
    else
422c21da
       mulle-bootstrap-warn-scripts.sh "${BOOTSTRAP_SUBDIR}" || exit 1
5de2fbd6
    fi
 
    if [ "${DONT_RECURSE}" = "" ]
    then
40fe269d
       mulle-bootstrap-fetch.sh || exit 1
5de2fbd6
    else
40fe269d
       mulle-bootstrap-fetch.sh nonrecursive  || exit 1
5de2fbd6
    fi
40fe269d
    mulle-bootstrap-build.sh  || exit 1
5de2fbd6
 }
 
 
40fe269d
 main()
 {
28ed6b30
 
    if [ ! -d "${BOOTSTRAP_SUBDIR}" -a "${command}" != "init" ]
    then
       echo "there is no ${BOOTSTRAP_SUBDIR} here, can't continue" >&2
       exit 1
    fi
 
40fe269d
    case "${command}" in
       bootstrap)
          bootstrap "$@" || exit 1
          ;;
 
       nomagic)
          DONT_RECURSE=YES bootstrap "$@" || exit 1
          ;;
 
       build)
          mulle-bootstrap-build.sh "$@" || exit 1
          ;;
 
       clean)
          mulle-bootstrap-clean.sh "$@" || exit 1
          ;;
 
a7b563e1
       dist-clean)
          mulle-bootstrap-clean.sh "dist"  || exit 1
          ;;
 
40fe269d
       fetch)
422c21da
          DONT_ASK_AFTER_WARNING=YES mulle-bootstrap-fetch.sh "$@" || exit 1
40fe269d
          ;;
 
       update)
          COMMAND="update" mulle-bootstrap-fetch.sh "$@" || exit 1
          ;;
 
       init)
          mulle-bootstrap-init.sh "$@" || exit 1
          ;;
 
       setup-xcode|xcode)
          mulle-bootstrap-xcode.sh "$@"|| exit 1
          ;;
 
       tag)
          mulle-bootstrap-tag.sh "$@" || exit 1
          ;;
 
fa860fc9
       version)
          echo "${VERSION}" || exit 1
          ;;
 
40fe269d
       *)
          usage >&2
          exit 1
d388168a
          ;;
40fe269d
       esac
 }
 
 main "$@"