summaryrefslogtreecommitdiffstats
path: root/php-guzzlehttp-guzzle-get-source.sh
blob: 4ad10514e709014539d1604ee51cd0a47348afc7 (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
#/bin/sh

GIT=`which git`
RPM=`which rpm`

if [ -z "$GIT" ]
then
    echo "ERROR: 'git' command not found" 1>&2
    exit 1
elif [ -z "$RPM" ]
then
    echo "ERROR: 'rpm' command not found" 1>&2
    exit 1
fi

function print {
    echo -e "\e[0;33m>>>>> ${1}\e[0m"
}

if [ -x "$1" ]
then
    SPEC=$1
else
    SPEC=`ls *.spec | head -1`
fi

NAME=`echo $SPEC | sed 's#\.spec##'`
VERSION=`egrep '%global\s*github_version' $SPEC | awk '{print $3}'`

print "SPEC = $SPEC"
print "NAME = $NAME"

GIT_OWNER=`egrep '%global\s*github_owner' $SPEC | awk '{print $3}'`
GIT_NAME=`egrep '%global\s*github_name' $SPEC | awk '{print $3}'`
GIT_COMMIT=`egrep '%global\s*github_commit' $SPEC | awk '{print $3}'`
GIT_REPO=https://github.com/${GIT_OWNER}/${GIT_NAME}
GIT_DIR=`echo $GIT_REPO | sed 's#.*/##'`

print "GIT_OWNER = $GIT_OWNER"
print "GIT_NAME = $GIT_NAME"
print "GIT_COMMIT = $GIT_COMMIT"
print "GIT_REPO = $GIT_REPO"
print "GIT_DIR = $GIT_DIR"

TEMP_DIR=$(mktemp --dir)
TAR_FILE=$PWD/${NAME}-${VERSION}-${GIT_COMMIT}.tar.gz
CMP_FILE=$PWD/composer.json

pushd $TEMP_DIR
    print "Cloning git repo..."
    $GIT clone $GIT_REPO

    pushd $GIT_DIR
        print "Checking out commit..."
        $GIT checkout $GIT_COMMIT
        cp composer.json $CMP_FILE
    popd

    TAR_DIR=${GIT_NAME}-${GIT_COMMIT}
    print "TAR_DIR = $TAR_DIR"

    mv $GIT_DIR $TAR_DIR

    print "TAR_FILE = $TAR_FILE"

    [ -e $TAR_FILE ] && rm -f $TAR_FILE
    tar --exclude-vcs -czf $TAR_FILE $TAR_DIR
    chmod 0644 $TAR_FILE
popd

rm -rf $TEMP_DIR