buildDebianPackage.sh 13.5 KB
Newer Older
1 2 3 4
#!/bin/bash
# --------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 2 of the License, or
6 7 8 9 10 11 12 13 14 15 16
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------

Claudio Valerio's avatar
Claudio Valerio committed
17

18 19 20 21
#**********************
#     functions
#**********************

22 23 24 25 26 27 28 29 30
checkUser()
{
  if [ `id -u` -ne 0 ]; then
    echo "Please run the script as root, may be using fakeroot command as follow"
    echo "fakeroot ./buildDebianPackage.sh [options]"
    exit 1
  fi
}

31 32
initializeVariables()
{
33
  APPLICATION_NAME="OpenBoard"
34
  MAKE_TAG=true
35
  STANDARD_QT_USED=false
36 37 38 39 40 41 42

  PRODUCT_PATH="build/linux/release/product"
  QT_PATH="/usr/local/Trolltech/Qt-4.8.0"
  PLUGINS_PATH="$QT_PATH/plugins"
  GUI_TRANSLATIONS_DIRECTORY_PATH="../Qt-4.8/translations"
  QT_LIBRARY_DEST_PATH="$PRODUCT_PATH/qtlib"
  QT_LIBRARY_SOURCE_PATH="$QT_PATH/lib"
root's avatar
root committed
43 44 45
  if [ -z $ARCHITECTURE ]; then
    ARCHITECTURE=`uname -m`
    if [ "$ARCHITECTURE" == "x86_64" ]; then
46
      ARCHITECTURE="amd64"
root's avatar
root committed
47 48
    fi
    if [ "$ARCHITECTURE" == "i686" ]; then
49
      ARCHITECTURE="i386"
root's avatar
root committed
50
    fi
51 52 53 54 55
  fi
  NOTIFY_CMD=`which notify-send`
  QMAKE_PATH="$QT_PATH/bin/qmake"
  LRELEASES="$QT_PATH/bin/lrelease"
  ZIP_PATH=`which zip`
56

57
}
58

Claudio Valerio's avatar
Claudio Valerio committed
59

60
notifyError(){
Claudio Valerio's avatar
Claudio Valerio committed
61 62 63
    if [ -e "$NOTIFY_CMD" ]; then
        $NOTIFY_CMD -t 0 -i "/usr/share/icons/oxygen/64x64/status/dialog-error.png" "$1"
    fi
-f's avatar
-f committed
64
    printf "\033[31merror:\033[0m $1\n"
65 66 67
    exit 1
}

Claudio Valerio's avatar
Claudio Valerio committed
68 69 70 71
notifyProgress(){
    if [ -e "$NOTIFY_CMD" ]; then
        $NOTIFY_CMD "$1" "$2"
    fi
72
    printf "\033[32m--> Achieved task:\033[0m $1:\n\t$2\n"
Claudio Valerio's avatar
Claudio Valerio committed
73 74
}

75 76 77 78 79
alertIfPreviousVersionInstalled(){
    APT_CACHE=`which apt-cache`
    if [ ! -e "$APT_CACHE" ]; then
        notifyError "apt-cache command not found"
    else
80 81 82
        SEARCH_RESULT=`$APT_CACHE search ${APPLICATION_NAME}`
        if [ `echo $SEARCH_RESULT | grep -c ${APPLICATION_NAME}` -ge 1 ]; then
            notifyError "Found a previous version of ${APPLICATION_NAME}. Remove it to avoid to put it as dependency"
83 84 85 86
        fi
    fi
}

87
checkDir(){
88
    if [ ! -d "$1" ]; then
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
        notifyError "Directory not found : $1"
    fi
}

checkExecutable(){
    if [ ! -e "$1" ]; then
        notifyError "$1 command not found"
    fi
}

copyQtLibrary(){
    if ls "$QT_LIBRARY_SOURCE_PATH/$1.so" &> /dev/null; then
        cp $QT_LIBRARY_SOURCE_PATH/$1.so.? "$QT_LIBRARY_DEST_PATH/"
        cp $QT_LIBRARY_SOURCE_PATH/$1.so.?.?.? "$QT_LIBRARY_DEST_PATH/"
    else
        notifyError "$1 library not found in path: $QT_LIBRARY_SOURCE_PATH"
    fi
}

108 109 110 111 112 113 114 115 116 117

buildWithStandardQt(){
  STANDARD_QT=`which qmake-qt4`
  if [ $? == "0" ]; then
    QT_VERSION=`$STANDARD_QT --version | grep -i "Using Qt version" | sed -e "s/Using Qt version \(.*\) in.*/\1/"`
    if [ `echo $QT_VERSION | sed -e "s/\.//g"` -gt 480 ]; then
        notifyProgress "Standard QT" "A recent enough qmake has been found. Using this one instead of custom one"
        STANDARD_QT_USED=true
        QMAKE_PATH=$STANDARD_QT
        LRELEASES=`which lrelease`
root's avatar
root committed
118
        if [ "`arch`" == "i686" ] || [ "$ARCHITECTURE" == "i386" ]; then
119 120 121 122
            QT_PATH="/usr/lib/i386-linux-gnu"
        else
            QT_PATH="/usr/lib/`arch`-linux-gnu"
        fi
123 124 125 126 127
        PLUGINS_PATH="$QT_PATH/qt4/plugins"
    fi
  fi
}

Claudio Valerio's avatar
Claudio Valerio committed
128
buildImporter(){
Claudio Valerio's avatar
Claudio Valerio committed
129
    IMPORTER_DIR="../OpenBoard-Importer/"
Claudio Valerio's avatar
Claudio Valerio committed
130 131 132
    IMPORTER_NAME="OpenBoardImporter"
    checkDir $IMPORTER_DIR
    cd ${IMPORTER_DIR}
Claudio Valerio's avatar
Claudio Valerio committed
133

134 135 136 137 138 139 140
    rm moc_*
    rm -rf debug release
    rm *.o

    git reset --hard
    git pull

Claudio Valerio's avatar
Claudio Valerio committed
141
    $QMAKE_PATH ${IMPORTER_NAME}.pro
142
    make clean
Claudio Valerio's avatar
Claudio Valerio committed
143 144 145 146 147
    make -j4
    checkExecutable $IMPORTER_NAME
    cd -
}

148 149 150
#**********************
#     script
#**********************
151
checkUser
152 153 154 155

for var in "$@"
do
   if [ $var == "notag" ]; then
156 157 158 159 160 161 162 163
     MAKE_TAG=false
   fi
# forcing a architecture because of cross compiling
   if [ $var == "i386" ]; then
      ARCHITECTURE="i386"
   fi
   if [ $var == "amd64" ]; then
      ARCHITECTURE="amd64"
164 165 166
   fi
done

root's avatar
root committed
167 168
initializeVariables
buildWithStandardQt
169

170 171
alertIfPreviousVersionInstalled

172
# check of directories and executables
173 174 175
checkDir $QT_PATH
checkDir $PLUGINS_PATH
checkDir $GUI_TRANSLATIONS_DIRECTORY_PATH
176

177 178 179 180
checkExecutable $QMAKE_PATH
checkExecutable $LRELEASES
checkExecutable $ZIP_PATH

Claudio Valerio's avatar
Claudio Valerio committed
181
#build third party application
Claudio Valerio's avatar
Claudio Valerio committed
182
buildImporter
Claudio Valerio's avatar
Claudio Valerio committed
183 184
notifyProgress "OpenBoardImporter" "Built Importer"

185
# cleaning the build directory
186 187 188
rm -rf "build/linux/release"
rm -rf install

189
notifyProgress "QT" "Internalization"
190
$LRELEASES ${APPLICATION_NAME}.pro
191 192 193
cd $GUI_TRANSLATIONS_DIRECTORY_PATH
$LRELEASES translations.pro
cd -
194

195
notifyProgress "${APPLICATION_NAME}" "Building ${APPLICATION_NAME}"
196

197
if [ "$ARCHITECTURE" == "amd64" ]; then
198
    $QMAKE_PATH ${APPLICATION_NAME}.pro -spec linux-g++-64
199
else
200
    $QMAKE_PATH ${APPLICATION_NAME}.pro -spec linux-g++
201
fi
202

203
make -j 4 release-install
204

205 206
if [ ! -e "$PRODUCT_PATH/${APPLICATION_NAME}" ]; then
    notifyError "${APPLICATION_NAME} build failed"
Claudio Valerio's avatar
Claudio Valerio committed
207 208 209 210
fi

notifyProgress "Git Hub" "Make a tag of the delivered version"

211
VERSION=`cat build/linux/release/version`
Claudio Valerio's avatar
Claudio Valerio committed
212

213 214 215 216 217
if [ ! -f build/linux/release/version ]; then
    notifyError "version not found"
else
    LAST_COMMITED_VERSION="`git describe $(git rev-list --tags --max-count=1)`"
    if [ "v$VERSION" != "$LAST_COMMITED_VERSION" ]; then
218
        if [ $MAKE_TAG == true ]; then
219
            git tag -a "OBv$VERSION" -m "OpenBoard setup for v$VERSION"
Claudio Valerio's avatar
Claudio Valerio committed
220
            git push origin --tags
Claudio Valerio's avatar
Claudio Valerio committed
221
        fi
222 223 224
    fi
fi

225 226
cp resources/linux/run.sh $PRODUCT_PATH
chmod a+x $PRODUCT_PATH/run.sh
227

228
cp -R resources/linux/qtlinux/* $PRODUCT_PATH/
229

Claudio Valerio's avatar
Claudio Valerio committed
230
notifyProgress "QT" "Copying plugins and library ..."
231
cp -R $PLUGINS_PATH $PRODUCT_PATH/
232

233 234 235
# copying customization
cp -R resources/customizations $PRODUCT_PATH/

Claudio Valerio's avatar
Claudio Valerio committed
236 237
# copying importer
mkdir -p $PRODUCT_PATH/Importer
238
cp -R ${IMPORTER_DIR}/${IMPORTER_NAME} $PRODUCT_PATH/Importer
Claudio Valerio's avatar
Claudio Valerio committed
239

Claudio Valerio's avatar
Claudio Valerio committed
240
if [ $STANDARD_QT_USED == false ]; then
241
#copying custom qt library
242 243 244 245 246 247 248 249 250 251 252 253
  mkdir -p $QT_LIBRARY_DEST_PATH
  copyQtLibrary libQtDBus
  copyQtLibrary libQtScript
  copyQtLibrary libQtSvg
  copyQtLibrary libQtXmlPatterns
  copyQtLibrary libQtNetwork
  copyQtLibrary libQtXml
  copyQtLibrary libQtGui
  copyQtLibrary libQtCore
  copyQtLibrary libphonon
  copyQtLibrary libQtWebKit
fi
254

255 256 257
notifyProgress "QT" "Internalization"
if [ ! -e $PRODUCT_PATH/i18n ]; then
    mkdir $PRODUCT_PATH/i18n
258
fi
Claudio Valerio's avatar
Claudio Valerio committed
259
#copying qt gui translation
260
cp $GUI_TRANSLATIONS_DIRECTORY_PATH/qt_??.qm $PRODUCT_PATH/i18n/
261

262 263 264 265
rm -rf install/linux
mkdir -p install/linux

#Removing .svn directories ...
266
cd $PRODUCT_PATH
267 268 269
find . -name .svn -exec rm -rf {} \; 2> /dev/null
cd -

270
notifyProgress "Building ${APPLICATION_NAME}" "Finished to build ${APPLICATION_NAME} building the package"
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

BASE_WORKING_DIR="packageBuildDir"

#creating package directory
mkdir $BASE_WORKING_DIR
mkdir "$BASE_WORKING_DIR/DEBIAN"
mkdir -p "$BASE_WORKING_DIR/usr/share/applications"
mkdir -p "$BASE_WORKING_DIR/usr/local"


cat > "$BASE_WORKING_DIR/DEBIAN/prerm" << EOF
#!/bin/bash
# --------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------

298
xdg-desktop-menu uninstall /usr/share/applications/${APPLICATION_NAME}.desktop
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
exit 0
#DEBHELPER#
EOF

cat > "$BASE_WORKING_DIR/DEBIAN/postint" << EOF
#!/bin/bash
# --------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------

320
xdg-desktop-menu install --novendor /usr/share/applications/${APPLICATION_NAME}.desktop
321 322 323 324 325
exit 0
#DEBHELPER#
EOF


326
APPLICATION_DIRECTORY_NAME="${APPLICATION_NAME}-$VERSION"
327 328
PACKAGE_DIRECTORY="$BASE_WORKING_DIR/usr/local/$APPLICATION_DIRECTORY_NAME"
#move build directory to packages directory
Claudio Valerio's avatar
Claudio Valerio committed
329
cp -R $PRODUCT_PATH $PACKAGE_DIRECTORY
330 331


332
cat > $BASE_WORKING_DIR/usr/local/$APPLICATION_DIRECTORY_NAME/run.sh << EOF
Claudio Valerio's avatar
Claudio Valerio committed
333
#!/bin/bash
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
# --------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------

349
env LD_LIBRARY_PATH=/usr/local/$APPLICATION_DIRECTORY_NAME/qtlib:$LD_LIBRARY_PATH /usr/local/$APPLICATION_DIRECTORY_NAME/${APPLICATION_NAME}
350 351 352
EOF


353
CHANGE_LOG_FILE="$BASE_WORKING_DIR/DEBIAN/changelog-${APPLICATION_NAME}-$VERSION.txt"
354 355 356
CONTROL_FILE="$BASE_WORKING_DIR/DEBIAN/control"
CHANGE_LOG_TEXT="changelog.txt"

357
echo "${APPLICATION_NAME} ($VERSION) $ARCHITECTURE; urgency=low" > "$CHANGE_LOG_FILE"
358 359 360
echo >> "$CHANGE_LOG_FILE"
cat $CHANGE_LOG_TEXT >> "$CHANGE_LOG_FILE"
echo >> "$CHANGE_LOG_FILE"
361
echo "-- Claudio Valerio <claudio.valerio@oe-f.org>  `date`" >> "$CHANGE_LOG_FILE"
362

363
echo "Package: ${APPLICATION_NAME}" > "$CONTROL_FILE"
364 365 366 367 368
echo "Version: $VERSION" >> "$CONTROL_FILE"
echo "Section: education" >> "$CONTROL_FILE"
echo "Priority: optional" >> "$CONTROL_FILE"
echo "Architecture: $ARCHITECTURE" >> "$CONTROL_FILE"
echo "Essential: no" >> "$CONTROL_FILE"
369
echo "Installed-Size: `du -s $PACKAGE_DIRECTORY | awk '{ print $1 }'`" >> "$CONTROL_FILE"
370
echo "Maintainer: ${APPLICATION_NAME} Developers team <dev@oe-f.org>" >> "$CONTROL_FILE"
371
echo "Homepage: http://www.openboard.org" >> "$CONTROL_FILE"
372 373 374 375
echo -n "Depends: " >> "$CONTROL_FILE"
unset tab
declare -a tab
let count=0
-f's avatar
-f committed
376
for l in `objdump -p $PACKAGE_DIRECTORY/${APPLICATION_NAME} | grep NEEDED | awk '{ print $2 }'`; do
377 378
    for lib in `dpkg -S  $l | awk -F":" '{ print $1 }'`; do
        #echo $lib
-f's avatar
-f committed
379 380
        presence=`echo ${tab[*]} | grep -c "$lib"`;
        if [ "$presence" == "0" ]; then
381 382
            tab[$count]=$lib;
            ((count++));
-f's avatar
-f committed
383 384 385
        fi;
    done;
done;
386 387 388 389 390

for ((i=0;i<${#tab[@]};i++)); do
    if [ $i -ne "0" ]; then
        echo -n ",    " >> "$CONTROL_FILE"
    fi
391
    echo -n "${tab[$i]} (>= "`dpkg -p ${tab[$i]} | grep "Version: " | awk '{      print $2 }' | sed -e 's/\([:. 0-9?]*\).*/\1/g' | sed -e 's/\.$//'`") " >> "$CONTROL_FILE"
392 393 394 395
done
echo "" >> "$CONTROL_FILE"
echo "Description: This a interactive white board that uses a free standard format." >> "$CONTROL_FILE"

-f's avatar
-f committed
396
find $BASE_WORKING_DIR/usr/ -exec md5sum {} > $BASE_WORKING_DIR/DEBIAN/md5sums 2>/dev/null \;
397
APPLICATION_SHORTCUT="$BASE_WORKING_DIR/usr/share/applications/${APPLICATION_NAME}.desktop"
398 399 400
echo "[Desktop Entry]" > $APPLICATION_SHORTCUT
echo "Version=$VERSION" >> $APPLICATION_SHORTCUT
echo "Encoding=UTF-8" >> $APPLICATION_SHORTCUT
401 402
echo "Name=${APPLICATION_NAME} ($VERSION)" >> $APPLICATION_SHORTCUT
echo "GenericName=${APPLICATION_NAME}" >> $APPLICATION_SHORTCUT
-f's avatar
-f committed
403
echo "Comment=Logiciel de création de présentations pour tableau numérique interactif (TNI)" >> $APPLICATION_SHORTCUT
404
echo "Exec=/usr/local/$APPLICATION_DIRECTORY_NAME/run.sh" >> $APPLICATION_SHORTCUT
405
echo "Icon=/usr/local/$APPLICATION_DIRECTORY_NAME/${APPLICATION_NAME}.png" >> $APPLICATION_SHORTCUT
406 407 408 409
echo "StartupNotify=true" >> $APPLICATION_SHORTCUT
echo "Terminal=false" >> $APPLICATION_SHORTCUT
echo "Type=Application" >> $APPLICATION_SHORTCUT
echo "Categories=Education" >> $APPLICATION_SHORTCUT
410
cp "resources/images/${APPLICATION_NAME}.png" "$PACKAGE_DIRECTORY/${APPLICATION_NAME}.png"
411 412 413 414 415
chmod 755 "$BASE_WORKING_DIR/DEBIAN"
chmod 755 "$BASE_WORKING_DIR/DEBIAN/prerm"
chmod 755 "$BASE_WORKING_DIR/DEBIAN/postint"

mkdir -p "install/linux"
416
DEBIAN_PACKAGE_NAME="${APPLICATION_NAME}_`lsb_release -is`_`lsb_release -rs`_${VERSION}_$ARCHITECTURE.deb"
417

-f's avatar
-f committed
418
chown -R root:root $BASE_WORKING_DIR
419
dpkg -b "$BASE_WORKING_DIR" "install/linux/$DEBIAN_PACKAGE_NAME"
420 421

#clean up mess
422 423
rm -rf $BASE_WORKING_DIR

424
notifyProgress "${APPLICATION_NAME}" "Package built"
425

426

427
exit 0