summaryrefslogtreecommitdiffstats
path: root/php-JMSParser-get-source.sh
blob: 5c15702b0b063581d15375324d385b8cf695dd0e (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
#/bin/sh

RPM=$(which rpm)

if [ -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

print "SPEC = $SPEC"

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

print "NAME = $NAME"
print "VERSION = $VERSION"

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}
SOURCE_FILENAME=${NAME}-${VERSION}-${GIT_COMMIT}.tar.gz
RPM_SOURCE_DIR=$(rpm --eval "%{_sourcedir}")

print "GIT_OWNER = $GIT_OWNER"
print "GIT_NAME = $GIT_NAME"
print "GIT_COMMIT = $GIT_COMMIT"
print "GIT_REPO = $GIT_REPO"
print "SOURCE_FILENAME = $SOURCE_FILENAME"
print "RPM_SOURCE_DIR = $RPM_SOURCE_DIR"

pushd /tmp
    print "Getting full source..."
    rm -f ${SOURCE_FILENAME}
    wget https://github.com/${GIT_OWNER}/${GIT_NAME}/archive/${GIT_COMMIT}/${SOURCE_FILENAME}

    print "Uncompressing full source..."
    tar -xvzf ${SOURCE_FILENAME}
    rm -f ${SOURCE_FILENAME}

    print "Removing non-allowable licened content..."
    rm -rf ${GIT_NAME}-${GIT_COMMIT}/doc

    print "Re-compressing allowable source..."
    rm -f ${RPM_SOURCE_DIR}/${SOURCE_FILENAME}
    tar -cvzf ${RPM_SOURCE_DIR}/${SOURCE_FILENAME} ${GIT_NAME}-${GIT_COMMIT}
    rm -rf ${GIT_NAME}-${GIT_COMMIT}

    print "Source = \"${RPM_SOURCE_DIR}/${SOURCE_FILENAME}\""
popd