src/mulle-bootstrap-scm.sh
c81c8721
 #! /usr/bin/env bash
7fdfcd11
 #
 #   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
 #
a3018cdd
 MULLE_BOOTSTRAP_SCM_SH="included"
 
d9c7fdec
 
2279ad91
 git_is_repository()
 {
e5b54e85
    [ -d "${1}/.git" ] || [ -d  "${1}/refs" -a -f "${1}/HEAD" ]
2279ad91
 }
 
a3018cdd
 
602ae7d9
 git_is_bare_repository()
 {
    local is_bare
 
2279ad91
    # if bare repo, we can only clone anyway
8f951e19
    is_bare=`(
                cd "$1" &&
                git rev-parse --is-bare-repository 2> /dev/null
             )` || internal_fail "wrong \"$1\" for \"`pwd`\""
2279ad91
    [ "${is_bare}" = "true" ]
602ae7d9
 }
 
 
fcf4306a
 git_get_url()
 {
    local remote
d9c7fdec
 
fcf4306a
    remote="$2"
 
8f951e19
    (
       cd "$1" &&
ea74a237
       git remote get-url "${remote}"  >&2
8f951e19
    ) || internal_fail "wrong \"$1\" or \"${remote}\" for \"`pwd`\""
fcf4306a
 }
 
 
 git_set_url()
 {
    local remote
    local url
 
    remote="$2"
    url="$3"
 
    (
8f951e19
       cd "$1" &&
ea74a237
       git remote set-url "${remote}" "${url}"  >&2 &&
       git fetch "${remote}"  >&2  # prefetch to get new branches
8f951e19
    ) || exit 1
fcf4306a
 }
 
 
 #
 # prefer origin over others, probably could be smarter
 # by passing in the desired branch and figuring more
 # stuff out
 #
 git_get_default_remote()
 {
    local i
    local match
 
    match=""
    IFS="
 "
    for i in `( cd "$1" ; git remote)`
    do
       case "$i" in
          origin)
             match="$i"
             break
          ;;
 
          *)
             if [ -z "${match}" ]
             then
                match="$i"
             fi
          ;;
       esac
    done
 
    IFS="${DEFAULT_IFS}"
 
    echo "$match"
 }
 
 
 git_has_branch()
 {
8f951e19
    (
       cd "$1" &&
       git branch | cut -c3- | fgrep -q -s -x "$2" > /dev/null
    ) || exit 1
fcf4306a
 }
 
 
602ae7d9
 git_get_branch()
 {
8f951e19
    (
       cd "$1" &&
       git rev-parse --abbrev-ref HEAD 2> /dev/null
    ) || exit 1
602ae7d9
 }
 
 
8f951e19
 git_checkout()
7fdfcd11
 {
550b5448
    [ $# -ge 7 ] || internal_fail "git_checkout: parameters missing"
7fdfcd11
 
8f951e19
    local reposdir="$1" ; shift
    local name="$1"; shift
    local url="$1"; shift
    local branch="$1"; shift
    local scm="$1"; shift
    local tag="$1"; shift
    local stashdir="$1"; shift
7fdfcd11
 
8f951e19
    [ -z "${stashdir}" ] && internal_fail "stashdir is empty"
    [ -z "${tag}" ]      && internal_fail "tag is empty"
fcf4306a
 
    local options
23cfa536
 
    # checkout don't know -v
fcf4306a
    options="${GITOPTIONS}"
    if [ "${options}" = "-v" ]
23cfa536
    then
fcf4306a
       options=""
23cfa536
    fi
 
fcfae396
    local branch
7fdfcd11
 
8f951e19
    branch="`git_get_branch "${stashdir}"`"
7fdfcd11
 
fcfae396
    if [ "${branch}" != "${tag}" ]
    then
8f951e19
       log_info "Checking out version ${C_RESET_BOLD}${tag}${C_INFO} of ${C_MAGENTA}${C_BOLD}${stashdir}${C_INFO} ..."
       (
          exekutor cd "${stashdir}" ;
ea74a237
          exekutor git ${GITFLAGS} checkout ${options} "${tag}"  >&2
e400db11
       ) || return 1
fcfae396
 
       if [ $? -ne 0 ]
       then
8f951e19
          log_error "Checkout failed, moving ${C_CYAN}${C_BOLD}${stashdir}${C_ERROR} to ${C_CYAN}${C_BOLD}${stashdir}.failed${C_ERROR}"
fcfae396
          log_error "You need to fix this manually and then move it back."
 
8f951e19
          rmdir_safer "${stashdir}.failed"
ea74a237
          exekutor mv "${stashdir}" "${stashdir}.failed"  >&2
e400db11
          return 1
fcfae396
       fi
    else
       log_fluff "Already on proper branch \"${branch}\""
7fdfcd11
    fi
 }
 
 
23dc6164
 _git_clone()
7fdfcd11
 {
23dc6164
    [ $# -ge 2 ] || internal_fail "_git_clone: parameters missing"
8f951e19
 
    local url="$1"; shift
    local stashdir="$1"; shift
23dc6164
    local branch="$1"; [ $# -ne 0 ] && shift
7fdfcd11
 
8f951e19
    [ ! -z "${url}" ]      || internal_fail "url is empty"
    [ ! -z "${stashdir}" ] || internal_fail "stashdir is empty"
7fdfcd11
 
e3244671
    [ -e "${stashdir}" ] && internal_fail "${stashdir} already exists"
 
8f951e19
    local options
06ffde28
    local dstdir
602ae7d9
 
06ffde28
    dstdir="${stashdir}"
8f951e19
    options="$*"
602ae7d9
    if [ ! -z "${branch}" ]
    then
06ffde28
       log_info "Cloning branch ${C_RESET_BOLD}$branch${C_INFO} of ${C_MAGENTA}${C_BOLD}${url}${C_INFO} into \"${stashdir}\" ..."
fcf4306a
       options="`concat "${options}" "-b ${branch}"`"
602ae7d9
    else
06ffde28
       log_info "Cloning ${C_MAGENTA}${C_BOLD}${url}${C_INFO} into \"${stashdir}\" ..."
602ae7d9
    fi
7fdfcd11
 
23dc6164
 
    # "remote urls" go through caches
    case "${url}" in
       file:*|/*|~*|.*)
       ;;
 
       *:*)
          if [ ! -z "${CLONE_CACHE}" ]
          then
e3244671
             local cachedir
 
23dc6164
             mkdir_if_missing "${CLONE_CACHE}"
e3244671
             cachedir="${CLONE_CACHE}/`basename ${url}`" # try to keep it global
 
             if [ ! -d "${cachedir}" ]
             then
                if ! exekutor git ${GITFLAGS} clone --bare ${options} ${GITOPTIONS} -- "${url}" "${cachedir}" >&2
                then
                   log_error "git clone of \"${url}\" into \"${cachedir}\" failed"
                   return 1
                fi
4272d072
             else
                # refetch (this shjoz)
                local refresh_cache
 
                refresh_cache="`read_config_setting "refresh_cache" "YES"`"
                if [ "${refresh_cache}" = "YES" ]
                then
                (
                   cd "${cachedir}";
                   if ! exekutor git ${GITFLAGS} fetch --tags >&2
                   then
                      log_warning "git fetch from \"${url}\" failed, using old state"
                   fi
                )
                fi
e3244671
             fi
             url="${cachedir}"
23dc6164
          fi
       ;;
    esac
 
8f951e19
 #
 # callers responsibility
 #
 #   local parent
 #
 #    parent="`dirname -- "${stashdir}"`"
 #   mkdir_if_missing "${parent}"
 
e3244671
    if [ "${stashdir}" = "${url}" ]
23dc6164
    then
e3244671
       # since we know that stash dir does not exist, this
       # message is a bit less confusing
       log_error "Clone source \"${url}\" does not exist."
       return 1
23dc6164
    fi
 
e3244671
    if ! exekutor git ${GITFLAGS} clone ${options} ${GITOPTIONS} -- "${url}" "${stashdir}"  >&2
23dc6164
    then
e3244671
       log_error "git clone of \"${url}\" into \"${stashdir}\" failed"
       return 1
23dc6164
    fi
7fdfcd11
 
fcf4306a
    if [ ! -z "${tag}" ]
7fdfcd11
    then
8f951e19
       git_checkout "$@"
7fdfcd11
    fi
 }
 
 
23dc6164
 
 git_clone()
 {
    [ $# -ge 7 ] || internal_fail "git_clone: parameters missing"
 
    local reposdir="$1" ; shift
    local name="$1"; shift
    local url="$1"; shift
    local branch="$1"; shift
    local scm="$1"; shift
    local tag="$1"; shift
    local stashdir="$1"; shift
 
    _git_clone "${url}" "${stashdir}" "${branch}" "$@"
 }
 
 
8f951e19
 git_fetch()
7fdfcd11
 {
8f951e19
    [ $# -ge 7 ] || internal_fail "git_fetch: parameters missing"
 
    local reposdir="$1" ; shift
    local name="$1"; shift
    local url="$1"; shift
    local branch="$1"; shift
    local scm="$1"; shift
    local tag="$1"; shift
    local stashdir="$1"; shift
 
    log_info "Fetching ${C_MAGENTA}${C_BOLD}${stashdir}${C_INFO} ..."
 
    (
       exekutor cd "${stashdir}" &&
550b5448
       exekutor git ${GITFLAGS} fetch "$@" ${GITOPTIONS}  >&2
8f951e19
    ) || fail "git fetch of \"${stashdir}\" failed"
 }
7fdfcd11
 
 
8f951e19
 git_pull()
 {
550b5448
    [ $# -ge 7 ] || internal_fail "git_pull: parameters missing"
7fdfcd11
 
8f951e19
    local reposdir="$1" ; shift
    local name="$1"; shift
    local url="$1"; shift
    local branch="$1"; shift
    local scm="$1"; shift
    local tag="$1"; shift
    local stashdir="$1"; shift
602ae7d9
 
8f951e19
    log_info "Pulling ${C_MAGENTA}${C_BOLD}${stashdir}${C_INFO} ..."
 
    (
       exekutor cd "${stashdir}" &&
ea74a237
       exekutor git ${GITFLAGS} pull $* ${GITOPTIONS}  >&2
8f951e19
    ) || fail "git pull of \"${stashdir}\" failed"
7fdfcd11
 
fcf4306a
    if [ ! -z "${tag}" ]
7fdfcd11
    then
ea74a237
       git_checkout "$@"  >&2
7fdfcd11
    fi
 }
 
 
4805e856
 git_status()
 {
    [ $# -ge 7 ] || internal_fail "git_status: parameters missing"
 
    local reposdir="$1" ; shift
    local name="$1"; shift
    local url="$1"; shift
    local branch="$1"; shift
    local scm="$1"; shift
    local tag="$1"; shift
    local stashdir="$1"; shift
 
    log_info "Status ${C_MAGENTA}${C_BOLD}${stashdir}${C_INFO} ..."
 
    (
       exekutor cd "${stashdir}" &&
ea74a237
       exekutor git ${GITFLAGS} status $* ${GITOPTIONS} >&2
4805e856
    ) || fail "git status of \"${stashdir}\" failed"
 }
 
 
7fdfcd11
 svn_checkout()
 {
550b5448
    [ $# -ge 7 ] || internal_fail "svn_checkout: parameters missing"
7fdfcd11
 
8f951e19
    local reposdir="$1" ; shift
    local name="$1"; shift
    local url="$1"; shift
    local branch="$1"; shift
    local scm="$1"; shift
    local tag="$1"; shift
    local stashdir="$1"; shift
7fdfcd11
 
8f951e19
    local options
7fdfcd11
 
8f951e19
    options="$*"
602ae7d9
    if [ ! -z "${branch}" ]
7fdfcd11
    then
8f951e19
       log_info "SVN checkout ${C_RESET_BOLD}${branch}${C_INFO} of ${C_MAGENTA}${C_BOLD}${url}${C_INFO} ..."
       options="`concat "${options}" "-r ${branch}"`"
602ae7d9
    else
       if [ ! -z "${tag}" ]
       then
8f951e19
          log_info "SVN checkout ${C_RESET_BOLD}${tag}${C_INFO} of ${C_MAGENTA}${C_BOLD}${url}${C_INFO} ..."
          options="`concat "${options}" "-r ${tag}"`"
602ae7d9
       else
8f951e19
          log_info "SVN checkout ${C_MAGENTA}${C_BOLD}${url}${C_INFO} ..."
602ae7d9
       fi
7fdfcd11
    fi
602ae7d9
 
11a51a36
    if ! exekutor svn checkout ${options} ${SVNOPTIONS} "${url}" "${stashdir}"  >&2
    then
       log_error "svn clone of \"${url}\" into \"${stashdir}\" failed"
       return 1
    fi
7fdfcd11
 }
 
 
 svn_update()
 {
550b5448
    [ $# -ge 7 ] || internal_fail "svn_update: parameters missing"
8f951e19
 
    local reposdir="$1" ; shift
    local name="$1"; shift
    local url="$1"; shift
    local branch="$1"; shift
    local scm="$1"; shift
    local tag="$1"; shift
    local stashdir="$1"; shift
7fdfcd11
 
8f951e19
    local options
7fdfcd11
 
8f951e19
    options="$*"
7fdfcd11
 
8f951e19
    [ ! -z "${stashdir}" ] || internal_fail "stashdir is empty"
7fdfcd11
 
8f951e19
    log_info "SVN updating ${C_MAGENTA}${C_BOLD}${stashdir}${C_INFO} ..."
7fdfcd11
 
602ae7d9
    if [ ! -z "$branch" ]
7fdfcd11
    then
8f951e19
       options="`concat "-r ${branch}" "${options}"`"
602ae7d9
    else
       if [ ! -z "$tag" ]
       then
8f951e19
          options="`concat "-r ${tag}" "${options}"`"
602ae7d9
       fi
7fdfcd11
    fi
 
8f951e19
    (
       exekutor cd "${stashdir}" ;
ea74a237
       exekutor svn update ${options} ${SVNOPTIONS}  >&2
8f951e19
    ) || fail "svn update of \"${stashdir}\" failed"
7fdfcd11
 }
8f77be37
 
 
4805e856
 svn_status()
 {
550b5448
    [ $# -ge 7 ] || internal_fail "svn_status: parameters missing"
4805e856
 
    local reposdir="$1" ; shift
    local name="$1"; shift
    local url="$1"; shift
    local branch="$1"; shift
    local scm="$1"; shift
    local tag="$1"; shift
    local stashdir="$1"; shift
 
    local options
 
    options="$*"
 
    [ ! -z "${stashdir}" ] || internal_fail "stashdir is empty"
 
    (
       exekutor cd "${stashdir}" ;
ea74a237
       exekutor svn status ${options} ${SVNOPTIONS}  >&2
4805e856
    ) || fail "svn update of \"${stashdir}\" failed"
 }
 
 
8f951e19
 append_dir_to_gitignore_if_needed()
108c932f
 {
4805e856
    local directory=$1
 
    [ -z "${directory}" ] && internal_fail "empty directory"
 
    case "${directory}" in
8f951e19
       "${REPOS_DIR}/"*)
          return 0
       ;;
    esac
108c932f
 
4805e856
    # strip slashes
    case "${directory}" in
8f951e19
       /*/)
4805e856
          directory="`echo "$1" | sed 's/.$//' | sed 's/^.//'`"
8f951e19
       ;;
 
       /*)
4805e856
          directory="`echo "$1" | sed 's/^.//'`"
8f951e19
       ;;
 
       */)
          directory="`echo "/$1" | sed 's/.$//'`"
       ;;
 
       *)
4805e856
          directory="$1"
8f951e19
       ;;
    esac
 
    #
    # prepend \n because it is safer, in case .gitignore has no trailing
    # LF which it often seems to not have
4805e856
    # fgrep is bugged on at least OS X 10.x, so can't use -e chaining
    if [ -f ".gitignore" ]
    then
       local pattern0
       local pattern1
       local pattern2
       local pattern3
 
 
       # variations with leadinf and trailing slashes
       pattern0="${directory}"
       pattern1="${pattern0}/"
       pattern2="/${pattern0}"
       pattern3="/${pattern0}/"
 
       if fgrep -q -s -x -e "${pattern0}" .gitignore ||
          fgrep -q -s -x -e "${pattern1}" .gitignore ||
          fgrep -q -s -x -e "${pattern2}" .gitignore ||
          fgrep -q -s -x -e "${pattern3}" .gitignore
       then
          return
       fi
    fi
 
    local line
    local lf
    local terminator
 
    line="/${directory}"
f67f6857
    terminator="`tail -c 1 ".gitignore" 2> /dev/null | tr '\012' '|'`"
4805e856
 
    if [ "${terminator}" != "|" ]
8f951e19
    then
4805e856
       line="${lf}/${directory}"
8f951e19
    fi
4805e856
 
    log_info "Adding \"/${directory}\" to \".gitignore\""
    redirect_append_exekutor .gitignore echo "${line}" || fail "Couldn\'t append to .gitignore"
108c932f
 }
 
 
4d45dff2
 #
 # will this run over embedded too ?
 #
 _run_git_on_stash()
 {
    local i="$1" ; shift
 
    if [ -d "${i}/.git" -o -d "${i}/refs" ]
    then
       log_info "### $i:"
       (
          cd "$i" ;
          exekutor git ${GITFLAGS} "$@" ${GITOPTIONS}  >&2
       ) || fail "git failed"
       log_info
    fi
 }
 
 
 #
 # todo: let user select what repositories are affected
 #
 run_git()
 {
    local i
 
    IFS="
 "
    for i in `all_repository_stashes`
    do
       IFS="${DEFAULT_IFS}"
 
       _run_git_on_stash "$i" "$@"
    done
 
    for i in `all_embedded_repository_stashes`
    do
       IFS="${DEFAULT_IFS}"
 
       _run_git_on_stash "$i" "$@"
    done
 
    for i in `all_deep_embedded_repository_stashes`
    do
       IFS="${DEFAULT_IFS}"
 
       _run_git_on_stash "$i" "$@"
    done
 
    IFS="${DEFAULT_IFS}"
 }
 
 
108c932f
 git_main()
 {
9339a58a
    log_debug "::: git :::"
108c932f
 
    [ -z "${MULLE_BOOTSTRAP_LOCAL_ENVIRONMENT_SH}" ] && . mulle-bootstrap-local-environment.sh
ea74a237
    [ -z "${MULLE_BOOTSTRAP_SCRIPTS_SH}" ]           && . mulle-bootstrap-scripts.sh
108c932f
 
    while :
    do
       if [ "$1" = "-h" -o "$1" = "--help" ]
       then
          git_usage
       fi
 
       break
    done
 
bba581f8
    if dir_has_files "${REPOS_DIR}"
108c932f
    then
e3244671
       log_fluff "Will run \"git $*\" over clones" >&2
108c932f
    else
73f50c63
       log_verbose "There is nothing to run git over."
108c932f
       return 0
    fi
 
cc4c45ef
    run_git "$@"
108c932f
 }
 
 
550b5448
 _validate_download()
 {
    local filename="$1"
    local options="$2"
 
    local checksum
    local expected
 
    case "${options}" in
       *shasum256*)
          case "${UNAME}" in
             mingw)
                log_fluff "mingw does not support shasum" # or does it ?
             ;;
 
             *)
                log_verbose "Validating ${C_MAGENTA}${C_BOLD}${filename}${C_INFO} ..."
 
 
                expected="`echo "${options}" | sed -n 's/shasum256=\([a-f0-9]*\).*/\1/p'`"
                checksum="`shasum -a 256 -p "${filename}" | awk '{ print $1 }'`"
                if [ "${expected}" != "${checksum}" ]
                then
                   fail "${filename} sha256 is ${checksum}, not ${expected} as expected"
                fi
             ;;
          esac
       ;;
    esac
 }
 
 
 _single_directory_in_directory()
 {
    local count
    local filename
 
    filename="`ls -1 "${tmpdir}"`"
 
    count="`echo "$filename}" | wc -l`"
    if [ $count -ne 1 ]
    then
       return
    fi
 
    echo "${tmpdir}/${filename}"
 }
 
 
 _move_stuff()
 {
    local tmpdir="$1"
    local stashdir="$2"
    local archivename="$3"
    local name="$4"
 
    local src
    local toremove
 
    toremove="${tmpdir}"
    src="${tmpdir}/${archivename}"
    if [ ! -d "${src}" ]
    then
       src="${tmpdir}/${name}"
       if [ ! -d "${src}" ]
       then
          src="`_single_directory_in_directory "${tmpdir}"`"
          if [ -z "${src}" ]
          then
             src="${tmpdir}"
             toremove=""
          fi
       fi
    fi
 
    exekutor mv "${src}" "${stashdir}"
 
    if [ ! -z "${toremove}" ]
    then
       rmdir_safer "${toremove}"
    fi
 }
 
 #
 # What we do is
 # a) download the package using curl
1a85f08e
 # b) optionally copy it into a cache for next time
 # c) create a temporary directory, extract into it
 # d) move it into place
550b5448
 #
1a85f08e
 _tar_download()
 {
    local download="$1"
 
    local archive_cache
    local cachable_path
    local cached_archive
 
    archive_cache="`read_config_setting "archive_cache" "${DEFAULT_ARCHIVE_CACHE}"`"
 
    if [ ! -z "${archive_cache}" -a "${archive_cache}" != "NO" ]
    then
       cachable_path="${archive_cache}/${download}"
       if [ -e "${cachable_path}" ]
       then
          cached_archive="${cachable_path}"
       fi
    fi
 
    if [ ! -z "${cached_archive}" ] && [ -f "${cached_archive}" ]
    then
       log_info "Using cached \"${cached_archive}\" for ${C_MAGENTA}${C_BOLD}${url}${C_INFO} ..."
       exekutor ln -s "${cached_archive}" || fail "failed to symlink \"${cached_archive}\""
       cachable_path=""
    else
       exekutor curl -O -L ${CURLOPTIONS} "${url}" || fail "failed to download \"${url}\""
    fi
 
    _validate_download "${download}" "${SCM_OPTIONS}" || exit 1
 
    if [ ! -z "${cachable_path}" ]
    then
       log_info "Saving \"${download}\" to archive cache \"${archive_cache}\" ..."
       mkdir_if_missing "${archive_cache}" || fail "failed to create archive cacheĀ \"${archive_cache}\""
       exekutor cp "${download}" "${cachable_path}" || fail "failed to copy \"${download}\" to cache \"${archive_cache}\""
    fi
 }
 
550b5448
 
 tar_unpack()
 {
    [ $# -ge 7 ] || internal_fail "tar_unpack: parameters missing"
 
 #   local reposdir="$1"
    local name="$2"
    local url="$3"
 #   local branch="$4"
 #   local scm="$5"
 #   local tag="$6"
    local stashdir="$7"
 
    local tmpdir
    local archive
    local download
    local options
    local archivename
 
    download="`basename "${url}"`"
    archive="${download}"
 
    # remove .tar (or .zip et friends)
    archivename="`extension_less_basename "${download}"`"
    case "${archivename}" in
       *.tar)
          archivename="`extension_less_basename "${archivename}"`"
       ;;
    esac
 
0b9e9e49
    rmdir_safer "${name}.tmp"
1ca4c8bc
    tmpdir="`exekutor mktemp -d "${name}.XXXX.tmp"`" || return 1
550b5448
    (
11a51a36
       exekutor cd "${tmpdir}" || return 1
550b5448
 
11a51a36
       _tar_download "${download}" || return 1
550b5448
 
       case "${url}" in
          *.zip)
11a51a36
             exekutor unzip "${download}" || return 1
550b5448
             archive="`basename "${download}" .zip`"
11a51a36
             exekutor rm "${download}" || return 1
550b5448
          ;;
       esac
 
       case "${UNAME}" in
          darwin)
          ;;
 
          *)
             case "${url}" in
                *.gz)
                   options="-z"
                ;;
 
                *.bz2)
                   options="-j"
                ;;
 
                *.x)
                   options="-J"
                ;;
             esac
          ;;
       esac
 
       log_verbose "Extracting ${C_MAGENTA}${C_BOLD}${archive}${C_INFO} ..."
 
11a51a36
       exekutor tar xf ${TAROPTIONS} ${options} "${archive}" || return 1
       exekutor rm "${archive}"
    ) || return 1
550b5448
 
    _move_stuff "${tmpdir}" "${stashdir}" "${archivename}" "${name}"
 }
 
 
 zip_unpack()
 {
    [ $# -ge 7 ] || internal_fail "zip_unpack: parameters missing"
 
 #   local reposdir="$1"
    local name="$2"
    local url="$3"
 #   local branch="$4"
 #   local scm="$5"
 #   local tag="$6"
    local stashdir="$7"
 
    local tmpdir
    local download
    local archivename
 
    download="`basename --  "${url}"`"
    archivename="`extension_less_basename "${download}"`"
 
0b9e9e49
    rmdir_safer "${name}.tmp"
1ca4c8bc
    tmpdir="`exekutor mktemp -d "${name}.XXXX.tmp"`" || exit 1
550b5448
    (
11a51a36
       exekutor cd "${tmpdir}" || return 1
550b5448
 
       log_info "Downloading ${C_MAGENTA}${C_BOLD}${url}${C_INFO} ..."
 
11a51a36
       exekutor curl -O -L ${CURLOPTIONS} "${url}" || return 1
       _validate_download "${download}" "${SCM_OPTIONS}" || return 1
550b5448
 
       log_verbose "Extracting ${C_MAGENTA}${C_BOLD}${download}${C_INFO} ..."
 
11a51a36
       exekutor unzip "${download}" || return 1
       exekutor rm "${download}"
    ) || return 1
550b5448
 
    _move_stuff "${tmpdir}" "${stashdir}" "${archivename}" "${name}"
 }
 
 
 
8f77be37
 scm_initialize()
 {
9339a58a
    log_debug ":scm_initialize:"
ec2b9bc2
    [ -z "${MULLE_BOOTSTRAP_FUNCTIONS_SH}" ] && . mulle-bootstrap-functions.sh
cc4c45ef
    [ -z "${MULLE_BOOTSTRAP_REPOSITORIES_SH}" ] && . mulle-bootstrap-repositories.sh
cbad10ec
 
    #
    # "repository" caches can and usually are outside the project folder
    # this can be multiple paths!
    CACHES_PATH="`read_config_setting "caches_path" "${MULLE_BOOTSTRAP_CACHES_PATH}"`"
 
    # stuff clones get intermediate saved too, default empty
    CLONE_CACHE="`read_config_setting "clone_cache"`"
    CACHES_PATH="`add_path "${CACHES_PATH}" "${CLONE_CACHE}"`"
 
8f951e19
    :
8f77be37
 }
ec2b9bc2
 
 scm_initialize