-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
executable file
·84 lines (74 loc) · 2.64 KB
/
common.sh
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
#!/bin/bash
. ../setup.sh
# If no name is given for the downloaded file, use the filename as identified by the URL.
if [[ "${ARCHIVE}" == "" ]]; then
ARCHIVE=$(awk -F/ '{print $NF}' <<< ${URL} )
fi
if [[ "${VERSION}" == "svn" ]]; then
svn co ${URL} ${ARCHIVE} | tee svn.log
# Redefine version based on SVN commit.
VERSION=$(awk '/^Checked out revision/ {print $4}' svn.log | tr -d .)
# Redefine the name of the source directory based on new version info.
SOURCE=${PACKAGE}-${VERSION}
mv ${ARCHIVE} ${SOURCE}
# Redefine the name of the archive file based on new version info.
ARCHIVE=${PACKAGE}-${VERSION}.tar.gz
# Create an archive file from source code we pulled from SVN.
tar cf - ${SOURCE} | gzip > ${ARCHIVE}
rm -rf .svn svn.log
else
test -f ${ARCHIVE} || wget ${URL} -O ${ARCHIVE}
fi
# If no name has been given to the source directory yet, set it to default.
# This needs to be done after SVN mangling, as VERSION may have been redifined.
if [[ "${SOURCE}" == "" ]]; then
SOURCE=${PACKAGE}-${VERSION}
fi
case "${DISTRO}" in
arch)
makepkg -s --noconfirm
;;
redhat)
cp ${ARCHIVE} ~/rpmbuild/SOURCES
cp ${PACKAGE}.spec ~/rpmbuild/SPECS
cd ~/rpmbuild/SPECS && rpmbuild -bb ${PACKAGE}.spec
;;
debian)
# Untar or unzip if required, since Debian doesn't do this automatically.
FILETYPE=$(awk -F. '{print $NF}' <<< ${ARCHIVE} )
if [[ "${FILETYPE}" == "zip" ]]; then
test -d ${SOURCE} || unzip ${ARCHIVE}
# Create a backup file to match what dh_make is expecting.
tar cvf - ${SOURCE} | gzip > ${PACKAGE}_${VERSION}.orig.tar.gz
elif [[ "${FILETYPE}" == "bz2" ]]; then
test -d ${SOURCE} || tar xvf ${ARCHIVE}
# Create a backup file to match what dh_make is expecting.
cp ${ARCHIVE} ${PACKAGE}_${VERSION}.orig.tar.bz2
else
test -d ${SOURCE} || tar xvf ${ARCHIVE}
# Create a backup file to match what dh_make is expecting.
cp ${ARCHIVE} ${PACKAGE}_${VERSION}.orig.tar.gz
fi
# Does the extracted source tree match what Debian wants?
if [[ "${SOURCE}" != "${PACKAGE}-${VERSION}" ]]; then
mv ${SOURCE} ${PACKAGE}-${VERSION}
fi
cd ${PACKAGE}-${VERSION}
test -f ../pre_build && source ../pre_build
dh_make -s -y
test -f ../install && cat ../install > debian/install
test -f ../control && sed "s@_KERNEL_@$(uname -r)@g" ../control > debian/control
test -f ../rules && cat ../rules >> debian/rules
test -f ../links && cat ../links >> debian/${PACKAGE}.links
# Install dependencies.
DEPENDS=()
for n in $(grep "^Build-Depends:" debian/control | tr -d ","); do
if [[ ! $(egrep "Build-Depends:|\(.*|[0-9].*\)" <<< ${n}) ]]; then
DEPENDS+=(${n})
fi
done
sudo apt-get -y install ${DEPENDS[*]} || exit 1
echo "10" > debian/compat
dpkg-buildpackage -b
;;
esac