Michal Marek 0a417c
#############################################################################
Michal Marek 0a417c
# Copyright (c) 2008,2009 Novell, Inc.
Michal Marek 0a417c
# All Rights Reserved.
Michal Marek 0a417c
#
Michal Marek 0a417c
# This program is free software; you can redistribute it and/or
Michal Marek 0a417c
# modify it under the terms of version 2 of the GNU General Public License as
Michal Marek 0a417c
# published by the Free Software Foundation.
Michal Marek 0a417c
#
Michal Marek 0a417c
# This program is distributed in the hope that it will be useful,
Michal Marek 0a417c
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Michal Marek 0a417c
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
Michal Marek 0a417c
# GNU General Public License for more details.
Michal Marek 0a417c
#
Michal Marek 0a417c
# You should have received a copy of the GNU General Public License
Michal Marek 0a417c
# along with this program; if not, contact Novell, Inc.
Michal Marek 0a417c
#
Michal Marek 0a417c
# To contact Novell about this file by physical or electronic mail,
Michal Marek 0a417c
# you may find current contact information at www.novell.com
Michal Marek 0a417c
#############################################################################
Michal Marek 0a417c
Michal Marek 9bee79
# to be sourced by scripts that need a GIT working directory
Michal Marek 9bee79
Michal Marek 9bee79
if git rev-parse HEAD >/dev/null 2>&1; then
Michal Marek 9bee79
    using_git=true
Michal Marek 9bee79
else
Michal Marek 9bee79
    using_git=false
Michal Marek 9bee79
    echo "WARNING: not in a GIT working directory, things might break." >&2
Michal Marek 9bee79
    echo >&2
Michal Marek 9bee79
fi
Michal Marek 9bee79
scripts_dir=$(dirname "$0")
Michal Marek 9bee79
Michal Marek 9bee79
get_branch_name()
Michal Marek 9bee79
{
Michal Marek 9bee79
    if $using_git; then
Michal Marek 9bee79
        # FIXME: guess a branch name when a non-branch revision is checked
Michal Marek 9bee79
        # out
Michal Marek 9bee79
        local res=$(sed -ne 's|^ref: refs/heads/||p' "$scripts_dir"/../.git/HEAD 2>/dev/null)
Michal Marek 9bee79
        echo "$res"
Michal Marek 9bee79
    fi
Michal Marek 9bee79
}
Michal Marek 9bee79
Michal Marek 28d204
_find_tarball()
Michal Marek 28d204
{
Michal Marek bd3ab7
    local version=$1 dir subdir major
Michal Marek 28d204
Michal Marek bd3ab7
    set -- ${version//[.-]/ }
Michal Marek bd3ab7
    major=$1.$2
Michal Marek 6478ac
    case "$major" in
Michal Marek 6478ac
    3.*)
Michal Marek 6478ac
        major=3.x
Michal Marek 6478ac
    esac
Michal Marek 6478ac
    for dir in . $MIRROR {/mounts,/labs,}/mirror/kernel; do
Michal Marek bd3ab7
        for subdir in "" "/v$major" "/testing" "/v$major/testing"; do
Michal Marek bd3ab7
            if test -r "$dir$subdir/linux-$version.tar.bz2"; then
Michal Marek bd3ab7
                echo "$dir$subdir/linux-$version.tar.bz2"
Michal Marek bd3ab7
                return
Michal Marek bd3ab7
            fi
Michal Marek bd3ab7
        done
Michal Marek 28d204
    done
Michal Marek 28d204
}
Michal Marek 28d204
Michal Marek 28d204
_get_tarball_from_git()
Michal Marek 28d204
{
Michal Marek 3a5770
    local version=$1 tag url
Michal Marek 28d204
Michal Marek 28d204
    git=${LINUX_GIT:-$HOME/linux-2.6}
Michal Marek 28d204
    if test ! -d "$git/.git"; then
Michal Marek 28d204
        echo "No linux-2.6 git tree found (try setting the LINUX_GIT variable)" >&2
Michal Marek 28d204
        exit 1
Michal Marek 28d204
    fi
Michal Marek f27800
    case "$version" in
Michal Marek 048a91
    *next-*)
Michal Marek 3a5770
        tag=refs/tags/next-${version##*next-}
Michal Marek 3a5770
        url=git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
Michal Marek f27800
        ;;
Michal Marek f9dafd
    [0-9]*-g???????)
Michal Marek f27800
        tag="v$version"
Michal Marek 3a5770
        url=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Michal Marek 3a5770
        ;;
Michal Marek 3a5770
    *)
Michal Marek 3a5770
        tag=refs/tags/"v$version"
Michal Marek 3a5770
        url=git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Michal Marek f27800
    esac
Michal Marek 3a5770
    if ! git --git-dir="$git/.git" cat-file -e "$tag" 2>/dev/null; then
Michal Marek 3a5770
        case "$tag" in
Michal Marek 3a5770
        refs/tags/*)
Michal Marek 3a5770
            git --git-dir="$git/.git" fetch "$url" "$tag:$tag"
Michal Marek 3a5770
            ;;
Michal Marek 3a5770
        *)
Michal Marek 3a5770
            # v2.6.X.Y-rcZ-gabcdef1, not a real tag
Michal Marek 3a5770
            git --git-dir="$git/.git" fetch --tags "$url" \
Michal Marek 3a5770
                refs/heads/master:refs/tags/latest
Michal Marek 3a5770
        esac
Michal Marek 3a5770
    fi
Michal Marek f27800
    git --git-dir="$git/.git" archive --prefix="linux-$version/" "$tag"
Michal Marek 28d204
}
Michal Marek 28d204
Michal Marek 28d204
get_tarball()
Michal Marek 28d204
{
Michal Marek 28d204
    local version=$1 dest=$2 tarball
Michal Marek 28d204
Michal Marek 28d204
    tarball=$(_find_tarball "$version")
Michal Marek 28d204
    if test -n "$tarball"; then
Michal Marek df83e3
        cp "$tarball" "$dest/linux-$version.tar.bz2.part" || exit
Michal Marek df83e3
        mv "$dest/linux-$version.tar.bz2.part" "$dest/linux-$version.tar.bz2"
Michal Marek 28d204
        return
Michal Marek 28d204
    fi
Michal Marek 28d204
    echo "Warning: could not find linux-$version.tar.bz2, trying to create it from git" >&2
Michal Marek 28d204
    set -o pipefail
Michal Marek df83e3
    _get_tarball_from_git "$version" | bzip2 -9 \
Michal Marek df83e3
        >"$dest/linux-$version.tar.bz2.part"
Michal Marek 28d204
    if test $? -ne 0; then
Michal Marek 28d204
        exit 1
Michal Marek 28d204
    fi
Michal Marek df83e3
    mv "$dest/linux-$version.tar.bz2.part" "$dest/linux-$version.tar.bz2"
Michal Marek 28d204
    set +o pipefail
Michal Marek 28d204
}
Michal Marek 28d204
Michal Marek 6616f5
unpack_tarball()
Michal Marek 6616f5
{
Michal Marek 6616f5
    local version=$1 dest=$2 tarball
Michal Marek 6616f5
Michal Marek 6616f5
    tarball=$(_find_tarball "$version")
Michal Marek 6616f5
    mkdir -p "$dest"
Michal Marek 6616f5
    if test -n "$tarball"; then
Michal Marek 6616f5
        echo "Extracting $tarball"
Michal Marek 6616f5
        tar -xjf "$tarball" -C "$dest" --strip-components=1
Michal Marek 6616f5
        return
Michal Marek 6616f5
    fi
Michal Marek 6616f5
    echo "Warning: could not find linux-$version.tar.bz2, trying to create it from git" >&2
Michal Marek 6616f5
    echo "alternatively you can put an unpatched kernel tree to $dest" >&2
Michal Marek 6616f5
    set -o pipefail
Michal Marek 6616f5
    _get_tarball_from_git "$version" | tar -xf - -C "$dest" --strip-components=1
Michal Marek 6616f5
    if test $? -ne 0; then
Michal Marek 6616f5
        rm -rf "$dest"
Michal Marek 6616f5
        exit 1
Michal Marek 6616f5
    fi
Michal Marek 6616f5
    set +o pipefail
Michal Marek 6616f5
}
Michal Marek 6616f5
Michal Marek 9bee79
if $using_git && test -z "$CHECKED_GIT_HOOKS"; then
Michal Marek 9bee79
    export CHECKED_GIT_HOOKS=1
Michal Marek 9bee79
    if ! "$scripts_dir"/install-git-hooks --check; then
Michal Marek 9bee79
        echo "WARNING: You should run $scripts_dir/install-git-hooks to enable pre-commit checks." >&2
Michal Marek 9bee79
    fi
Michal Marek 4046ce
    suse_domains_re='(suse\.(de|com|cz)|novell\.com)'
Michal Marek 4046ce
    kerncvs_re='(kerncvs(\.suse\.de)?|10\.10\.1\.75)'
Michal Marek 4046ce
    if (echo $EMAIL; hostname -f) | grep -Eiq "aaa[@.]$suse_domains_re\\>" || \
Michal Marek 4046ce
        git config remote.origin.url | grep -Eiq "\\<$kerncvs_re:"; then
Michal Marek 4046ce
        # only warn when used in suse
Michal Marek 4046ce
        if ! git var GIT_COMMITTER_IDENT | grep -Eiq "@$suse_domains_re>"; then
Michal Marek 4046ce
            echo "WARNING: You should set your suse email address in git"  >&2
Michal Marek 4046ce
            echo "WARNING: E.g. by running 'git config --global user.email <your login>@suse.de'" >&2
Michal Marek 4046ce
        fi
Michal Marek 9bee79
    fi
Michal Marek 9bee79
fi
Michal Marek 9bee79
Michal Marek 9bee79
# vim: sw=4:sts=4:et