summaryrefslogtreecommitdiffstats
path: root/create_tarball
blob: 62abb6d72ed122238322b188d198cea0fd2f42d0 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash

# Set the current target version
# The default is the version detected from TDE core header.
TARGET=${TARGET:-}

# When $SUFFIX = true then the package tarball name will be $package-trinity.
# When $SUFFIX != true then the package tarball name will be trinity-$package.
# Choose the option that satisfies any distro package name rules.
SUFFIX=${SUFFIX:-"true"}

# Setting where the tarball will be created.
# The default is the parent directory (..).
TARBALL_DIR=${TARBALL_DIR:-".."}

# Set compression method
case ${COMPRESS:="xz"} in
  "gzip"*|"pigz"*) TAR_SUFFIX=".gz";;
  "bzip2"|"pbzip2") TAR_SUFFIX=".bz2";;
  "xz"|"pxz") TAR_SUFFIX=".xz";;
esac

# Check git-dir
if [[ ! -e .git ]] ||
   [[ -z "`git rev-parse --git-dir 2>/dev/null`" ]]; then
        echo "This script can only be run from a top level git directory.  Exiting..."
        exit 1
fi

# Check remote branch
branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"`
if [[ -z "$branch" ]]; then
    branch=`git branch --contains HEAD | egrep -v "no branch|detached" | head -n1 | cut -c 3-`
fi
if [[ -z "$branch" ]] ||
   [[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
        echo "There is not active upstream branch.  Exiting..."
        exit 1
fi

# Get submodule name
REMOTE_URL=$(git config --get remote.origin.url)
if [ "$REMOTE_URL" = "${REMOTE_URL%/tde}" ]; then
    TDEROOT=$( cd `git rev-parse --show-toplevel` &&
               cd .. &&
               cd `git rev-parse --show-toplevel` &&
               pwd )
    SUBROOT=$( cd `git rev-parse --show-toplevel` &&
               pwd )
elif [ -f .gitignore ]; then
    TDEROOT=$( cd `git rev-parse --show-toplevel` &&
               pwd )
    SUBROOT=$PWD
    METAPACKAGE=true
fi
MODULE=${SUBROOT#$TDEROOT/main/}

# Set target version
if [ -z "$TARGET" ]; then
    if [ -f $TDEROOT/main/core/tdelibs/tdecore/tdeversion.h ]; then
        tdeversionHeader=$TDEROOT/main/core/tdelibs/tdecore/tdeversion.h
    elif [ -f $TDEROOT/main/core/tdelibs/kdecore/kdeversion.h ]; then
        tdeversionHeader=$TDEROOT/main/core/tdelibs/kdecore/kdeversion.h
    elif [ -f $TDEROOT/main/tdelibs/tdecore/tdeversion.h ]; then
        tdeversionHeader=$TDEROOT/main/tdelibs/tdecore/tdeversion.h
    elif [ -f $TDEROOT/main/tdelibs/kdecore/kdeversion.h ]; then
        tdeversionHeader=$TDEROOT/main/tdelibs/kdecore/kdeversion.h
    fi
    if [ -z "$tdeversionHeader" ]; then
        echo "Cannot find TDE core headers. Exiting."
        exit 1
    fi
    TARGET=`sed -n 's|#define [KT]DE_VERSION_STRING "[^0-9]\?\([^ "]*\).*|\1|p' $tdeversionHeader`
fi

# Check branch by target
if [ "$TARGET" != "${TARGET#3.5.}" ]; then
    if [ "$TARGET" != "${TARGET#3.5.13.}" ]; then
        targetBranch=v3.5.13-sru
    else
        targetBranch=master
    fi
else
    if [ "$TARGET" != "${TARGET%.0}" ]; then
        targetBranch=master
    else
        targetBranch=r${TARGET%.*}.x
    fi
fi
if [ "$branch" != "$targetBranch" ]; then
    echo "Target $TARGET is not valid on $branch branch. Exiting."
    exit 1
fi

# Check submodules
if [[ -e .gitmodules ]]; then
    sed -n "s|^\[submodule \"\([^\"]*\)\"\]$|\1|p" <.gitmodules | \
    while read submodule; do
        if [[ ! -e "$submodule/.git" ]]; then
            git submodule init -- "$submodule"
            git submodule update -- "$submodule"
        fi
    done
fi

# Check status
if [[ ! -z "`git status --porcelain`" ]]; then
        echo "Current tree contains changes that have not been committed.  Exiting..."
        exit 1
fi
if [[ -z "`git branch -r --contains HEAD`" ]]; then
        echo "Current tree contains commits not pushed to the server.  Exiting..."
        exit 1
fi

target_tag=`git tag | grep -F "$TARGET" | head -n1`
if [[ -n "$target_tag" ]] && \
   [[ `git log $target_tag..HEAD | wc -l` -gt 0 ]]; then
        echo "Current tree contains commits beyond target release tag $target_tag.  Exiting..."
        exit 1
fi
if [[ -n "$target_tag" ]] && \
   [[ `git log HEAD..$target_tag | wc -l` -gt 0 ]]; then
        echo "Current tree is behind target release tag $target_tag.  Exiting..."
        exit 1
fi

# Calculate version
tag=`git tag | \
     sed "s|^\([^0-9]\)|\1.|" | sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr -k 5,5nr | sed "s|^\([^0-9]\)\.|\1|" | \
     while read t; do \
     git branch --contains $t | cut -c 3- | grep -x "$branch" >/dev/null && \
     echo "$t..HEAD" && break; done`

count=`git log $tag --pretty=oneline | wc -l`

if [ "$SUFFIX" = "true" ]; then
    package=$(basename $PWD)-trinity-$TARGET
else
    package=trinity-$(basename $PWD)-$TARGET
fi
if [[ "$count" -gt 0 ]] || [[ -z "$target_tag" ]]; then
    package=$package~pre$count+$(git rev-parse HEAD | cut -c 1-8)
fi

# Create tarball
echo "Package name: $package"
if [ ! -e $TARBALL_DIR/$package.tar$TAR_SUFFIX ]; then
  echo "Creating tarball in $TARBALL_DIR."
  echo "# TDE SCM module information" > .tdescminfo
  echo "Name: $MODULE" >> .tdescminfo
  echo "Revision: $branch-$(git rev-parse HEAD)" >> .tdescminfo
  date +"DateTime: %m/%d/%Y %H:%M" -u -d "@$(git log -1 --pretty=format:"%ct")" >> .tdescminfo
  trap "rm $TARBALL_DIR/tar-$$; rm .tdescminfo; exit 1" INT
  find ./ -print0 | LC_ALL=C sort -z | \
  tar c --no-recursion --null -T - \
    --mode=u+rw,go=rX,a-s \
    --mtime "@$(git log -1 --pretty=format:"%ct")" \
    --owner=root --group=users --exclude .git --exclude .gitmodules \
    --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
    --transform "s|^\.\(/\|$\)|$package\1|" ./ | \
  $COMPRESS -9 >$TARBALL_DIR/tar-$$ && \
  mv $TARBALL_DIR/tar-$$ $TARBALL_DIR/$package.tar$TAR_SUFFIX || \
  rm $TARBALL_DIR/tar-$$
  rm .tdescminfo
  [ -f $TARBALL_DIR/$package.tar$TAR_SUFFIX ] && \
  touch -d "@$(git log -1 --pretty=format:"%ct")" $TARBALL_DIR/$package.tar$TAR_SUFFIX
else
  echo "Unchanged tarball in $TARBALL_DIR."
  exit 2
fi