buildDebianPackage 11.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/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/>.
# ---------------------------------------------------------------------

Claudio Valerio's avatar
Claudio Valerio committed
17 18 19 20 21 22 23
MAKE_TAG=true

if [ $# == "1" ]; then
   if [ $1 == "notag" ]; then
      MAKE_TAG=false;
   fi
fi
24 25 26 27 28 29 30 31 32

notifyError(){
    notify-send -t 0 "Error occoured" "An error occours during the sankore build:\n\t$1" -i /usr/share/icons/oxygen/64x64/status/dialog-error.png
    exit 1
}

rm -rf "build/linux/release"
rm -rf install

Claudio Valerio's avatar
Claudio Valerio committed
33
QT_PATH="/usr/local/Trolltech/Qt-4.8.0"
34 35
PLUGINS_PATH="$QT_PATH/plugins"
QMAKE_PATH="$QT_PATH/bin/qmake"
Claudio Valerio's avatar
Claudio Valerio committed
36 37
LRELEASES="$QT_PATH/bin/lrelease"
GUI_TRANSLATIONS_DIRECTORY_PATH="../Qt-4.8/translations"
38
ARCHITECTURE=`uname -m`
39 40 41 42 43 44 45 46 47 48 49

if [ ! -e "$QMAKE_PATH" ]; then
    notifyError "qmake command not found at $QMAKE_PATH"
fi

if [ ! -e "$PLUGINS_PATH" ]; then
    notifyError "plugins path not found at $PLUGINS_PATH"
fi

notify-send "Open-Sankore" "Building Open-Sankore ..."

50
if [ "$ARCHITECTURE" == "x86_64" ]; then
Claudio Valerio's avatar
Claudio Valerio committed
51
    $QMAKE_PATH Sankore_3.1.pro -spec linux-g++-64
52
else
Claudio Valerio's avatar
Claudio Valerio committed
53
    $QMAKE_PATH Sankore_3.1.pro -spec linux-g++
54
fi
55

56
make -j 4 release-install
57 58 59 60 61 62 63 64 65

notify-send "Git Hub" "Make a tag of the delivered version"
VERSION=`cat build/linux/release/version`
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
        echo creating a tag with the version $VERSION
Claudio Valerio's avatar
Claudio Valerio committed
66 67 68 69
	if [ $MAKE_TAG == true ]; then
            git tag -a "v$VERSION" -m "Generating setup for v$VERSION"
            git push origin --tags
        fi 
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    fi
fi

cp resources/linux/run.sh build/linux/release/product
chmod +x build/linux/release/product/run.sh

cp -R resources/linux/qtlinux/* build/linux/release/product/

notify-send "QT" "Coping plugins and library ..."
cp -R $PLUGINS_PATH build/linux/release/product/

#copying custom qt library
QT_LIBRARY_DEST_PATH="build/linux/release/product/qtlib"
mkdir $QT_LIBRARY_DEST_PATH
QT_LIBRARY_SOURCE_PATH="$QT_PATH/lib"

copyQtLibrary(){
Claudio Valerio's avatar
Claudio Valerio committed
87
    if [ ! -e "$QT_LIBRARY_SOURCE_PATH/$1.so.4.8.0" ]; then
88 89 90
        notifyError "$1 library not found in path: $QT_LIBRARY_SOURCE_PATH"
    fi
    cp "$QT_LIBRARY_SOURCE_PATH/$1.so.4" "$QT_LIBRARY_DEST_PATH/"
Claudio Valerio's avatar
Claudio Valerio committed
91
    cp "$QT_LIBRARY_SOURCE_PATH/$1.so.4.8.0" "$QT_LIBRARY_DEST_PATH/"
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
}

copyQtLibrary libQtDBus
copyQtLibrary libQtScript
copyQtLibrary libQtSvg
copyQtLibrary libQtXmlPatterns
copyQtLibrary libQtNetwork
copyQtLibrary libQtXml
copyQtLibrary libQtGui
copyQtLibrary libQtCore

if [ ! -e "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4.4.0" ]; then
    notifyError "phonon library not found in path: $QT_LIBRARY_SOURCE_PATH"
else
    cp "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4" "$QT_LIBRARY_DEST_PATH/"
    cp "$QT_LIBRARY_SOURCE_PATH/libphonon.so.4.4.0" "$QT_LIBRARY_DEST_PATH/"
fi

Claudio Valerio's avatar
Claudio Valerio committed
110 111 112 113 114 115
if [ ! -e "$QT_LIBRARY_SOURCE_PATH/libQtWebKit.so.4.9.0" ]; then
    notifyError "webkit library not found in path: $QT_LIBRARY_SOURCE_PATH"
else
    cp "$QT_LIBRARY_SOURCE_PATH/libQtWebKit.so.4" "$QT_LIBRARY_DEST_PATH/"
    cp "$QT_LIBRARY_SOURCE_PATH/libQtWebKit.so.4.9.0" "$QT_LIBRARY_DEST_PATH/"
fi
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

notify-send "QT" "Internalization ..."
if [ ! -e $GUI_TRANSLATIONS_DIRECTORY_PATH ]; then
    notifyError "gui translations pro file not found at: $GUI_TRANSLATIONS_DIRECTORY_PATH"
else
    cd $GUI_TRANSLATIONS_DIRECTORY_PATH
    $LRELEASES translations.pro
    cd -
    if [ ! -e build/linux/release/product/i18n ]; then
        mkdir build/linux/release/product/i18n
    fi
    #copying qt gui translation    
    cp $GUI_TRANSLATIONS_DIRECTORY_PATH/qt_??.qm build/linux/release/product/i18n/
fi

$LRELEASES Sankore_3.1.pro
cp resources/i18n/*.qm build/linux/release/product/i18n/

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
rm -rf install/linux
mkdir -p install/linux

cd build/linux/release/product

#Removing .svn directories ...
find . -name .svn -exec rm -rf {} \; 2> /dev/null

cd -
notify-send "Building Sankore" "Finished to build Sankore building the package"


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/>.
# ---------------------------------------------------------------------

xdg-desktop-menu uninstall /usr/share/applications/Open-Sankore.desktop
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/>.
# ---------------------------------------------------------------------

xdg-desktop-menu install --novendor /usr/share/applications/Open-Sankore.desktop
exit 0
#DEBHELPER#
EOF


SANKORE_DIRECTORY_NAME="Open-Sankore-$VERSION"
SANKORE_PACKAGE_DIRECTORY="$BASE_WORKING_DIR/usr/local/$SANKORE_DIRECTORY_NAME"
#move sankore build directory to packages directory
cp -R build/linux/release/product $SANKORE_PACKAGE_DIRECTORY 


cat > $BASE_WORKING_DIR/usr/local/$SANKORE_DIRECTORY_NAME/run.sh << 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/>.
# ---------------------------------------------------------------------

env LD_LIBRARY_PATH=/usr/local/$SANKORE_DIRECTORY_NAME/qtlib:$LD_LIBRARY_PATH /usr/local/$SANKORE_DIRECTORY_NAME/Open-Sankore
EOF


CHANGE_LOG_FILE="$BASE_WORKING_DIR/DEBIAN/changelog-sankore-$VERSION.txt"
CONTROL_FILE="$BASE_WORKING_DIR/DEBIAN/control"
CHANGE_LOG_TEXT="changelog.txt"

231 232 233
if [ "$ARCHITECTURE" == "x86_64" ]; then
    ARCHITECTURE="amd64"
fi
234

Claudio Valerio's avatar
Claudio Valerio committed
235 236 237 238
if [ "$ARCHITECTURE" == "i686" ]; then
    ARCHITECTURE="i386"
fi

239 240 241 242 243 244 245 246 247 248 249 250 251
echo "Open-Sankore ($VERSION) $ARCHITECTURE; urgency=low" > "$CHANGE_LOG_FILE"
echo >> "$CHANGE_LOG_FILE"
cat $CHANGE_LOG_TEXT >> "$CHANGE_LOG_FILE"
echo >> "$CHANGE_LOG_FILE"
echo "-- Claudio Valerio <claudio@open-sankore.org>  `date`" >> "$CHANGE_LOG_FILE"

echo "Package: open-sankore" > "$CONTROL_FILE"
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"
echo "Installed-Size: `du -s $SANKORE_PACKAGE_DIRECTORY | awk '{ print $1 }'`" >> "$CONTROL_FILE"
252 253
echo "Maintainer: Open-Sankoré Developers team <dev@open-sankore.org>" >> "$CONTROL_FILE"
echo "Homepage: http://dev.open-sankore.org" >> "$CONTROL_FILE"
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
echo -n "Depends: " >> "$CONTROL_FILE"
unset tab
declare -a tab
let count=0
for l in `objdump -p $SANKORE_PACKAGE_DIRECTORY/Open-Sankore | grep NEEDED | awk '{ print $2 }'`; do 
    for lib in `dpkg -S  $l | awk -F":" '{ print $1 }'`; do
        #echo $lib
        presence=`echo ${tab[*]} | grep -c "$lib"`; 
        if [ "$presence" == "0" ]; then   
            tab[$count]=$lib;
            ((count++));
        fi; 
    done; 
done; 

269
#additional dependencies
270 271 272 273
#tab[$count]="gtk2-engines-pixbuf"
#((count++))
#tab[$count]="ttf-mscorefonts-installer"
#((count++))
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
for ((i=0;i<${#tab[@]};i++)); do
    if [ $i -ne "0" ]; then
        echo -n ",    " >> "$CONTROL_FILE"
    fi
    echo -n "${tab[$i]} (>= "`dpkg -p ${tab[$i]} | grep "Version: " | awk '{      print $2 }'`") " >> "$CONTROL_FILE"
done
echo "" >> "$CONTROL_FILE"
echo "Description: This a interactive white board that uses a free standard format." >> "$CONTROL_FILE"

find $BASE_WORKING_DIR/usr/ -exec md5sum {} > $BASE_WORKING_DIR/DEBIAN/md5sums 2>/dev/null \; 
SANKORE_SHORTCUT="$BASE_WORKING_DIR/usr/share/applications/Open-Sankore.desktop"
echo "[Desktop Entry]" > $SANKORE_SHORTCUT
echo "Version=$VERSION" >> $SANKORE_SHORTCUT
echo "Encoding=UTF-8" >> $SANKORE_SHORTCUT
echo "Name=Open-Sankore ($VERSION)" >> $SANKORE_SHORTCUT
echo "GenericName=Open-Sankore" >> $SANKORE_SHORTCUT
echo "Comment=Logiciel de création de présentations pour tableau numérique interactif (TNI)" >> $SANKORE_SHORTCUT 
echo "Exec=/usr/local/$SANKORE_DIRECTORY_NAME/run.sh" >> $SANKORE_SHORTCUT
echo "Icon=/usr/local/$SANKORE_DIRECTORY_NAME/sankore.png" >> $SANKORE_SHORTCUT
echo "StartupNotify=true" >> $SANKORE_SHORTCUT
echo "Terminal=false" >> $SANKORE_SHORTCUT
echo "Type=Application" >> $SANKORE_SHORTCUT
echo "Categories=Education" >> $SANKORE_SHORTCUT
echo "Name[fr_FR]=Open-Sankore ($VERSION)" >> $SANKORE_SHORTCUT
cp "resources/images/uniboard.png" "$SANKORE_PACKAGE_DIRECTORY/sankore.png"
chmod 755 "$BASE_WORKING_DIR/DEBIAN"
chmod 755 "$BASE_WORKING_DIR/DEBIAN/prerm"
chmod 755 "$BASE_WORKING_DIR/DEBIAN/postint"

mkdir -p "install/linux"

306
fakeroot  chown -R root:root $BASE_WORKING_DIR 
307 308 309 310
dpkg -b "$BASE_WORKING_DIR" install/linux/Open-Sankore_${VERSION}_$ARCHITECTURE.deb
notify-send "Open-Sankore" "Package built"

#clean up mess
311
fakeroot rm -rf $BASE_WORKING_DIR
312