-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhist-pkg
executable file
·154 lines (125 loc) · 3.81 KB
/
hist-pkg
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
#!/bin/bash
# Include the bash library functions
. $(dirname $0)/xorg-pkg-tools.lib
usage() {
write_msg "Usage: $0 <commits-file> <debian-dir>"
exit 1
}
# Constructs a version string for a given version control system commit
vcs_snapshot_version_string() {
VCS_TYPE=$1
COMMIT=$2
DATE_PREFIX="+"
# Get the released package version for this branch
if [ -z "$PACKAGE_VERSION" ]; then
eval `grep PACKAGE_VERSION= configure`
fi
[ -z "$PACKAGE_VERSION" ] && die "No PACKAGE_VERSION in configure"
# Get the date for the most recent git commit
DATE=$(git_last_commit_date)
echo "${PACKAGE_VERSION}${DATE_PREFIX}${VCS_TYPE}${DATE}.${COMMIT}"
}
# Generate a package from an upstream commit, for a given
# distro version and a given debian directory
git_pkg() {
COMMIT=$1
DEBIAN=$2
DISTRO="UNRELEASED"
ORIGDIR=${REPO}.orig
echo "BASEDIR: "$BASEDIR
echo "COMMIT: "$COMMIT
echo "DISTRO: "$DISTRO
echo "DEBIAN: "${DEBIAN%/}
echo "REPO: "${REPO/$BASEDIR/[BASEDIR]/}
echo "ORIGDIR: "${ORIGDIR/$BASEDIR/[BASEDIR]/}
echo "----------"
# Update the git repository to the commit id
cd ${REPO}
msg "Resetting to $COMMIT"
git reset --hard $COMMIT || return $?
# Copy to new working directory
copy_dir ${REPO} ${ORIGDIR} || return $?
cd ${ORIGDIR}
# Update autoconfage if desired
if [ ${UPDATE_AUTOCONF} ] ; then
./autogen.sh || return $?
fi
rm -rf autom4te/ .git
# TODO: Remove autom4te, cache, .git, etc.
# Set the version string
GITVER=$(vcs_snapshot_version_string "git" $COMMIT)
VERSION=${EPOCH}${GITVER}${ADDVERSION}
# Create the source dir
SOURCE=${BASEDIR%/}/${PKG}-${GITVER}.orig
copy_dir ${ORIGDIR} ${SOURCE} || return $?
rm -rf ${ORIGDIR} || return $?
# TODO: Above this line should be one function, below another
# Create the target dir
TARGET=${BASEDIR%/}/${PKG}-${GITVER}
copy_dir ${SOURCE} ${TARGET} || return $?
cd ${TARGET}
# Copy in the given debian/ directory
copy_dir ${BASEDIR%/}/${DEBIAN%/}/ ${TARGET}/debian || return $?
# Add changelog entry
msg "Adding changelog entry via dch..."
dch -b --distribution ${DISTRO} --newversion ${VERSION} \
"Checkout from git up to $COMMIT ($date)"
if [ ! $? ] ; then
warn "dch: Failed to add changelog entry"
return $?
fi
# Create package
msg "debuild -sa -S ${AUTOSIGN:+-k$AUTOSIGN}"
debuild -sa -S ${AUTOSIGN:+-k$AUTOSIGN} || warn "debuild: $?"
# Generate JSON output file
cat > ${TARGET}.json <<EOF
{
"pkg": "${PKG}",
"version": "${VERSION}",
"commit": "${COMMIT}",
"debian": "${DEBIAN%/}",
"target": "${TARGET/$BASEDIR/}",
"pubkey": "${AUTOSIGN}",
"dependencies": ""
}
EOF
echo "VERSION: $VERSION"
return 0
}
# Handle command-line parameters
COMMITS_FILE=$1
DEBIAN_DIR=$2
[ -z "${COMMITS_FILE}" ] && usage
[ -z "${DEBIAN_DIR}" ] && usage
PKG=${COMMITS_FILE%.commits}
if [ ! -e "${PKG}.config" ] ; then
echo "Error: Cannot find ${PKG}.config."
exit 1
fi
. ${PKG}.config
BASEDIR=$(abspath "${COMMITS_FILE}")
if [ ! -d ${BASEDIR} ]; then
die "directory ${BASEDIR} not found"
fi
REPO="${BASEDIR%/}/${GIT_DIR}"
exec < ${COMMITS_FILE}
while read line ; do
commit=${line%% *}
name=${line/$commit/}
name=${name/ /}
[ -z "${commit}" ] && continue
case $commit in
\#* ) continue ;;
esac
LOGFILE=${PKG}-${commit}.log
git_pkg ${commit} ${DEBIAN_DIR} | tee ${BASEDIR}/$LOGFILE 2>&1
if [ ! $? ] ; then
msg "FAILED"
else
msg "DONE"
fi
msg ""
done
# TODO: Print a summary of success/failures
# TODO: Running ./autogen.sh requires newer dependency versions than may
# be installed on the host