-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-LsCs-deb.sh
executable file
·321 lines (269 loc) · 10.2 KB
/
build-LsCs-deb.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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/bin/bash
#
# Script to build a debian package for LsCs
#
set -e
if [ ! -f "/etc/debian_version" ]; then
if [ ! "$(grep -i 'ID_LIKE=debian' /etc/*release)" ]; then
echo "This script can only be run on a Debian based distribution"
exit 1
fi
fi
echo "MUST BE RUN FROM ROOT OF PROJECT DIRECTORY TREE"
echo ""
echo "MUST have fakeroot, hashdeep, and dpkg-deb installed!"
echo ""
echo "This script ASSUMES it can create or use lscs_debian_build and lscs_debian_release"
echo "directories one level up from where this script is being run. If they"
echo "exist they will be deleted and recreated."
echo ""
echo "Script also ASSUMES you are running from the root of the Git directory"
echo "where all source is in a directory named src at the same level as this file."
echo ""
echo "You must have ninja, cmake, and a valid build environment. LsCs will be built"
echo "from source and installed in lscs_debian_release. We will then create a"
echo "DEBIAN directory to assemble all files needed for creation of a .deb."
echo ""
echo ""
TIME_STARTED=$( date '+%F_%H:%M:%S' )
# Step 1 : Establish fresh clean directories
#
echo "*** Establishing fresh directories"
SCRIPT_DIR="$PWD"
BUILD_DIR="$SCRIPT_DIR/../lscs_debian_build"
RELEASE_DIR="$SCRIPT_DIR/../lscs_debian_release"
DEBIAN_DIR="$SCRIPT_DIR/../lscs_debian"
DEBIAN_WORK_DIR="$SCRIPT_DIR/../lscs_debian_work"
#
# Placed here so it can be hacked for those unfortunate distros that default to lib
# containing 32-bit libraries and lib64 for 64-bit even though they are 64-bit platforms
# themselves.
#
LIB_DIR="lib"
echo "SCRIPT_DIR $SCRIPT_DIR"
echo "BUILD_DIR $BUILD_DIR"
echo "RELEASE_DIR $RELEASE_DIR"
echo "DEBIAN_DIR $DEBIAN_DIR"
echo "LIB_DIR $LIB_DIR"
function create_debian_tree()
{
if [ -d "$DEBIAN_DIR" ]; then
rm -rf "$DEBIAN_DIR"
fi
mkdir -p "$DEBIAN_DIR"/DEBIAN
mkdir -p "$DEBIAN_DIR"/usr/include/LsCs
mkdir -p "$DEBIAN_DIR"/usr/bin
#
# The plugins should always be here, not copied into the binary install dir
#
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/platforms
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/printerdrivers
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/xcbglintegrations
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/mediaservices
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/playlistformats
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/iconengines
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/imageformats
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/pictureformats
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/plugins/sqldrivers
mkdir -p "$DEBIAN_DIR"/usr/"${LIB_DIR}"/LsCs/cmake
mkdir -p "$DEBIAN_DIR"/usr/share/pkgconfig
mkdir -p "$DEBIAN_DIR"/usr/share/doc/LsCs/license
mkdir -p "$DEBIAN_DIR"/usr/share/LsCs
mkdir -p "$DEBIAN_DIR"/etc/ld.so.conf.d
}
function build_from_source()
{
BUILD_FROM_SOURCE_STARTED=$( date '+%F_%H:%M:%S' )
# nuke the directories we will use if they already exist
#
if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
fi
if [ -d "$RELEASE_DIR" ]; then
rm -rf "$RELEASE_DIR"
fi
# create the directories we will use so they are fresh and clean
#
mkdir -p "$BUILD_DIR"
mkdir -p "$RELEASE_DIR"
# Step 2 : Prepare build directory
#
echo "*** Prepping build directory"
cd "$BUILD_DIR"
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Debug \
-DBUILDING_DEBIAN=ON \
-DCMAKE_INSTALL_PREFIX="$RELEASE_DIR" \
"$SCRIPT_DIR"
# Step 4: Actually build LsCs
#
echo "*** Building LsCs"
ninja install
# Step 5: Sweep up what CopperSpice project gets wrong in their
# default build. TODO:: see if this is still needed
cd "$RELEASE_DIR/${LIB_DIR}/LsCs/cmake"
if [ -f "LsCsLibraryTargets.cmake" ]; then
echo "*** "
echo "*** Fixing where cmake looks for Qt and other headers"
echo "*** "
sed -i 's#${_IMPORT_PREFIX}/include;#${_IMPORT_PREFIX}/include/LsCs;#g' LsCsLibraryTargets.cmake
sed -i 's#${_IMPORT_PREFIX}/include/Qt#${_IMPORT_PREFIX}/include/LsCs/Qt#g' LsCsLibraryTargets.cmake
fi
BUILD_FROM_SOURCE_COMPLETED=$( date '+%F_%H:%M:%S' )
}
function dev_deb()
{
DEV_PACKAGE_STARTED=$( date '+%F_%H:%M:%S' )
create_debian_tree
# Step 5 : Move files to the debian tree
#
echo "*** Copying files to Debian tree"
# deb_build.etc/preinst deb_build.etc/postinst deb_build.etc/prerm
cp -f "$BUILD_DIR"/deb_build.etc/control "$BUILD_DIR"/deb_build.etc/postrm "$BUILD_DIR"/deb_build.etc/postinst "$DEBIAN_DIR"/DEBIAN
#
# Files in this directory need to be marked executable.
#
chmod 0664 "$DEBIAN_DIR"/DEBIAN/*
chmod +x "$DEBIAN_DIR"/DEBIAN/postrm
chmod +x "$DEBIAN_DIR"/DEBIAN/postinst
#
# This file creates library search paths at install time
#
cp -f "$BUILD_DIR"/LsCs-library.conf "${DEBIAN_DIR}"/etc/ld.so.conf.d/
chmod 0664 "${DEBIAN_DIR}"/etc/ld.so.conf.d/*
# Note: If you want changelog to actually have anything in it, you need to create one
# I put a placeholder in the project for now because I didn't want to
# saddle this build script with git-buildpackage dependencies
#
cp "$SCRIPT_DIR"/changelog "$DEBIAN_DIR"/usr/share/doc/LsCs/changelog.Debian
cp -Prv "$SCRIPT_DIR"/license/* "$DEBIAN_DIR"/usr/share/doc/LsCs/license/
cp -Prv "$BUILD_DIR"/lscs.conf "$DEBIAN_DIR"/usr/share/LsCs/
echo "*** rsync release_dir with debian"
rsync -av "$RELEASE_DIR"/ "$DEBIAN_DIR"/usr/
echo "*** chmod changelog"
chmod 0664 "$DEBIAN_DIR"/usr/share/doc/LsCs/changelog*
gzip --best --force "$DEBIAN_DIR"/usr/share/doc/LsCs/changelog*
# Step 6 : generate md5sum
#
echo "Generating md5sums - must have md5deep installed or will fail"
cd "$DEBIAN_DIR"
md5deep -r usr/share/doc/LsCs/* 2>/dev/null >DEBIAN/md5sums
# don't currently have any pre files
# DEBIAN/pre*
#
chmod go-w DEBIAN/md5sums DEBIAN/post* usr usr/share usr/share/LsCs usr/share/doc usr/share/doc/LsCs
# Step 7 : build .deb
#
cd ..
D_DIR="$PWD"
echo "Building .deb IN $D_DIR"
fakeroot dpkg-deb -Zgzip --build "$DEBIAN_DIR"
# Step 8 : rename .deb
# file will be named LsCs_debian.deb and should just be LsCs-version-architecture-dev.deb
#
D_VERSION=$(grep -i "Version:" "$DEBIAN_DIR"/DEBIAN/control | cut -d' ' -f2)
D_ARCH=$(grep -i "Architecture:" "$DEBIAN_DIR"/DEBIAN/control | cut -d' ' -f2)
DEB_NAME="LsCs-$D_VERSION-$D_ARCH-dev.deb"
echo "look for: $DEB_NAME"
mv lscs_debian.deb "$DEB_NAME"
DEV_PACKAGE_COMPLETED=$( date '+%F_%H:%M:%S' )
}
function runtime_deb()
{
RUNTIME_PACKAGE_STARTED=$( date '+%F_%H:%M:%S' )
create_debian_tree
# Step 5 : Move files to the debian tree
#
echo "*** Copying files to Debian tree"
# deb_build.etc/preinst deb_build.etc/postinst deb_build.etc/prerm
cp -f "$BUILD_DIR"/deb_build.etc/control "$BUILD_DIR"/deb_build.etc/postrm "$BUILD_DIR"/deb_build.etc/postinst "$DEBIAN_DIR"/DEBIAN
#
# Files in this directory need to be marked executable.
#
chmod 0664 "$DEBIAN_DIR"/DEBIAN/*
chmod +x "$DEBIAN_DIR"/DEBIAN/postrm
chmod +x "$DEBIAN_DIR"/DEBIAN/postinst
# Note: If you want changelog to actually have anything in it, you need to create one
# I put a placeholder in the project for now because I didn't want to
# saddle this build script with git-buildpackage dependencies
#
cp "$SCRIPT_DIR"/changelog "$DEBIAN_DIR"/usr/share/doc/LsCs/changelog.Debian
cp -Prv "$SCRIPT_DIR"/license/* "$DEBIAN_DIR"/usr/share/doc/LsCs/license/
cp -Prv "$BUILD_DIR"/lscs.conf "$DEBIAN_DIR"/usr/share/LsCs/
rsync -av --exclude cmake/ "$RELEASE_DIR"/lib/ "$DEBIAN_DIR"/usr/lib/
chmod 0664 "$DEBIAN_DIR"/usr/share/doc/LsCs/changelog*
gzip --best --force "$DEBIAN_DIR"/usr/share/doc/LsCs/changelog*
# Step 6 : generate md5sum
#
echo "Generating md5sums"
cd "$DEBIAN_DIR"
md5deep -r usr/share/doc/LsCs/* 2>/dev/null >DEBIAN/md5sums
# don't currently have any pre files
# DEBIAN/pre*
#
chmod go-w DEBIAN/md5sums DEBIAN/post* usr usr/share usr/share/LsCs usr/share/doc usr/share/doc/LsCs
# Step 7 : build .deb
#
cd ..
D_DIR="$PWD"
echo "Building .deb IN $D_DIR"
fakeroot dpkg-deb -Zgzip --build "$DEBIAN_DIR"
# Step 8 : rename .deb
# file will be named LsCs_debian.deb and should just be LsCs-version-architecture.deb
#
D_VERSION=$(grep -i "Version:" "$DEBIAN_DIR"/DEBIAN/control | cut -d' ' -f2)
D_ARCH=$(grep -i "Architecture:" "$DEBIAN_DIR"/DEBIAN/control | cut -d' ' -f2)
DEB_NAME="LsCs-$D_VERSION-$D_ARCH.deb"
echo "look for: $DEB_NAME"
mv lscs_debian.deb "$DEB_NAME"
RUNTIME_PACKAGE_COMPLETED=$( date '+%F_%H:%M:%S' )
}
# See if user wants to build everything from source through package
# build source only, or build package only from whatever got built already
#
BUILD_ALL="Y"
BUILD_SRC="N"
RUNTIME_PKG="N"
DEV_PKG="N"
SRC_BUILD_OPTION="src"
RUNTIME_OPTION="run"
DEV_OPTION="dev"
for option in "$@"
do
if [ "${option,,}" = "${SRC_BUILD_OPTION,,}" ]; then
BUILD_SRC="Y"
BUILD_ALL="N"
fi
if [ "${option,,}" = "${RUNTIME_OPTION,,}" ]; then
RUNTIME_PKG="Y"
BUILD_ALL="N"
fi
if [ "${option,,}" = "${DEV_OPTION,,}" ]; then
DEV_PKG="Y"
BUILD_ALL="N"
fi
done
if [ "$BUILD_ALL" = "Y" ]; then
build_from_source
runtime_deb
dev_deb
fi
if [ "$BUILD_SRC" = "Y" ]; then
build_from_source
fi
if [ "$RUNTIME_PKG" = "Y" ]; then
runtime_deb
fi
if [ "$DEV_PKG" = "Y" ]; then
dev_deb
fi
set -e
NOW=$( date '+%F_%H:%M:%S' )
echo "Script started: $TIME_STARTED"
echo " Source Build Started: $BUILD_FROM_SOURCE_STARTED"
echo " Source Build Completed: $BUILD_FROM_SOURCE_COMPLETED"
echo " Dev Package Started: $DEV_PACKAGE_STARTED"
echo " Dev Package Completed: $DEV_PACKAGE_COMPLETED"
echo " Runtime Package Started: $RUNTIME_PACKAGE_STARTED"
echo " Runtime Package Completed: $RUNTIME_PACKAGE_COMPLETED"
echo "Script completed: $NOW"
exit 0