-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkpkg
executable file
·165 lines (140 loc) · 5.53 KB
/
mkpkg
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
#!/bin/bash
PKG="DriveCommandLine"
SRC_NAME="DriveCommandLine"
PKG_NAME="DriveCommandLine"
TOP="usr"
DESTDIR="${TOP}/local"
LBIN="${DESTDIR}/bin"
SRC=${HOME}/src
SUDO=sudo
GCI=
dpkg=`type -p dpkg-deb`
[ "${dpkg}" ] || {
echo "Debian packaging tools do not appear to be installed on this system"
echo "Are you on the appropriate Linux system with packaging requirements ?"
echo "Exiting"
exit 1
}
[ -f "${SRC}/${SRC_NAME}/VERSION" ] || {
[ -f "/builds/doctorfree/${SRC_NAME}/VERSION" ] || {
echo "$SRC/$SRC_NAME/VERSION does not exist. Exiting."
exit 1
}
SRC="/builds/doctorfree"
SUDO=
GCI=1
}
. "${SRC}/${SRC_NAME}/VERSION"
PKG_VER=${VERSION}
PKG_REL=${RELEASE}
# Subdirectory in which to create the distribution files
OUT_DIR="dist/${PKG_NAME}_${PKG_VER}"
[ -d "${SRC}/${SRC_NAME}" ] || {
echo "$SRC/$SRC_NAME does not exist or is not a directory. Exiting."
exit 1
}
cd "${SRC}/${SRC_NAME}"
${SUDO} rm -rf dist
mkdir dist
[ -d ${OUT_DIR} ] && rm -rf ${OUT_DIR}
mkdir ${OUT_DIR}
mkdir ${OUT_DIR}/DEBIAN
chmod 755 ${OUT_DIR} ${OUT_DIR}/DEBIAN
for dir in "${TOP}" "${DESTDIR}" "${LBIN}" "${DESTDIR}/share" \
"${DESTDIR}/share/doc" "${DESTDIR}/share/doc/${PKG}"
do
[ -d ${OUT_DIR}/${dir} ] || ${SUDO} mkdir ${OUT_DIR}/${dir}
done
# Copy in the DriveCommandLine scripts
${SUDO} cp bin/* ${OUT_DIR}/${LBIN}
# Build all the gdrive binaries
[ -d releases ] || mkdir releases
[ -x scripts/build-all.sh ] || chmod 755 scripts/build-all.sh
scripts/build-all.sh "${SRC}/${SRC_NAME}"
${SUDO} cp AUTHORS ${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/AUTHORS
${SUDO} cp LICENSE ${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/copyright
${SUDO} cp CHANGELOG.md ${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/changelog
${SUDO} cp README.md ${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/README
${SUDO} gzip -9 ${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/changelog
${SUDO} cp -a markdown "${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/markdown"
${SUDO} cp -a man "${OUT_DIR}/${DESTDIR}/share/doc/${PKG}/man"
${SUDO} cp -a man "${OUT_DIR}/${DESTDIR}/share/man"
${SUDO} chmod 755 ${OUT_DIR}/${LBIN}/*
# Set ownership of distribution hierarchy to root:root
${SUDO} chown -R root:root ${OUT_DIR}
for platforms in releases/bin/*
do
platform=`basename ${platforms}`
OPSM=`echo ${platform} | awk -F '_' ' { print $1 } '`
ARCH=`echo ${platform} | awk -F '_' ' { print $2 } '`
echo "Creating ${platform} distribution"
# Remove any os/architecture specific gdrive binary from the dist tree
${SUDO} rm -f ${OUT_DIR}/${LBIN}/gdrive*
# Copy the os/architecture specific gdrive binary into place
${SUDO} cp ${platforms}/gdrive* ${OUT_DIR}/${LBIN}
${SUDO} chown root:root ${OUT_DIR}/${LBIN}/gdrive*
[ "${OPSM}" == "linux" ] && {
echo "Building Debian and RPM packages for ${platform}"
# If Linux then build Debian and RPM packages
# Need to use a pipe to tee to use sudo with this
# echo "bla bla" | sudo tee /path/to/control > /dev/null
echo "Package: ${PKG}
Version: ${PKG_VER}-${PKG_REL}
Section: misc
Priority: optional
Architecture: ${ARCH}
Depends:
Suggests:
Maintainer: ${DEBFULLNAME} <${DEBEMAIL}>
Build-Depends: debhelper (>= 11)
Standards-Version: 4.1.3
Homepage: https://gitlab.com/doctorfree/DriveCommandLine
Description: Google Drive Command Line Tools
Manage your Google Drive from the command line" | \
${SUDO} tee ${OUT_DIR}/DEBIAN/control > /dev/null
${SUDO} chmod 644 ${OUT_DIR}/DEBIAN/control
cd dist
echo "Building ${PKG_NAME}_${PKG_VER}-${PKG_REL}.${platform} package"
${SUDO} dpkg --build ${PKG_NAME}_${PKG_VER} ${PKG_NAME}_${PKG_VER}-${PKG_REL}.${platform}.deb
[ "${GCI}" ] || {
[ -d ../releases ] || mkdir ../releases
[ -d ../releases/${PKG_VER} ] || mkdir ../releases/${PKG_VER}
${SUDO} cp *.deb *.tgz *.zip ../releases/${PKG_VER}
}
# Experimental RPM distribution build
cd "${SRC}/${SRC_NAME}"
[ -d pkg/rpm ] && ${SUDO} cp -a pkg/rpm ${OUT_DIR}/rpm
[ -d ${OUT_DIR}/rpm ] || ${SUDO} mkdir ${OUT_DIR}/rpm
have_rpm=`type -p rpmbuild`
[ "${have_rpm}" ] || {
${SUDO} apt-get update
${SUDO} apt-get install rpm -y
}
[ -d ${OUT_DIR}/BUILDROOT ] || ${SUDO} mkdir -p ${OUT_DIR}/BUILDROOT
[ -d ${OUT_DIR}/BUILDROOT/usr ] && ${SUDO} rm -rf ${OUT_DIR}/BUILDROOT/usr
${SUDO} cp -a ${OUT_DIR}/usr ${OUT_DIR}/BUILDROOT/usr
[ "${ARCH}" == "amd64" ] && ARCH=x86_64
${SUDO} rpmbuild -ba --build-in-place --target "${ARCH}-unknown-${OPSM}" \
--define "_topdir ${OUT_DIR}" \
--define "_version ${PKG_VER}" \
--define "_release ${PKG_REL}" \
--define "_sourcedir ${OUT_DIR}" \
--define "_rpmfilename %%{ARCH}/%%{NAME}_%%{VERSION}-%%{RELEASE}.${OPSM}_%%{ARCH}.rpm" \
--buildroot ${SRC}/${SRC_NAME}/${OUT_DIR}/BUILDROOT \
${OUT_DIR}/rpm/${PKG_NAME}.spec
${SUDO} cp dist/${PKG_NAME}_${PKG_VER}/RPMS/*/*.rpm dist
[ "${GCI}" ] || {
[ -d releases ] || mkdir releases
[ -d releases/${PKG_VER} ] || mkdir releases/${PKG_VER}
${SUDO} cp ${OUT_DIR}/RPMS/*/*.rpm releases/${PKG_VER}
}
}
cd "${SRC}/${SRC_NAME}/dist/${PKG_NAME}_${PKG_VER}"
echo "Creating compressed tar archive of ${PKG_NAME} ${PKG_VER}-${PKG_REL}.${platform} distribution"
${SUDO} tar --format=pax --no-xattrs -cf - usr | gzip -9 > ../${PKG_NAME}_${PKG_VER}-${PKG_REL}.${platform}.tgz
have_zip=`type -p zip`
[ "${have_zip}" ] || ${SUDO} apt-get install zip -y
echo "Creating zip archive of ${PKG_NAME} ${PKG_VER}-${PKG_REL}.${platform} distribution"
${SUDO} zip -q -r ../${PKG_NAME}_${PKG_VER}-${PKG_REL}.${platform}.zip usr
cd "${SRC}/${SRC_NAME}"
done