1#! /bin/bash 2# This file is part of the LibreOffice project. 3# 4# This Source Code Form is subject to the terms of the Mozilla Public 5# License, v. 2.0. If a copy of the MPL was not distributed with this 6# file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 8# -- Available env vars -- 9# * DOCKER_HUB_REPO - which Docker Hub repo to use 10# * DOCKER_HUB_TAG - which Docker Hub tag to create 11# * LIBREOFFICE_BRANCH - which branch to build in core 12# * LIBREOFFICE_ONLINE_REPO - which git repo to clone online from 13# * LIBREOFFICE_ONLINE_BRANCH - which branch to build in online 14# * LIBREOFFICE_BUILD_TARGET - which make target to run (in core repo) 15# * ONLINE_EXTRA_BUILD_OPTIONS - extra build options for online 16# * NO_DOCKER_IMAGE - if set, don't build the docker image itself, just do all the preps 17# * NO_DOCKER_PUSH - don't push to docker hub 18 19# check we can sudo without asking a pwd 20echo "Trying if sudo works without a password" 21echo 22echo "If you get a password prompt now, break, and fix your setup using 'sudo visudo'; add something like:" 23echo "yourusername ALL=(ALL) NOPASSWD: /sbin/setcap" 24echo 25sudo echo "works" 26 27# Check env variables 28if [ -z "$DOCKER_HUB_REPO" ]; then 29 DOCKER_HUB_REPO="libreoffice/online" 30fi; 31if [ -z "$DOCKER_HUB_TAG" ]; then 32 DOCKER_HUB_TAG="master" 33fi; 34echo "Using Docker Hub Repository: '$DOCKER_HUB_REPO' with tag '$DOCKER_HUB_TAG'." 35 36if [ -z "$LIBREOFFICE_BRANCH" ]; then 37 LIBREOFFICE_BRANCH="master" 38fi; 39echo "Building core branch '$LIBREOFFICE_BRANCH'" 40 41if [ -z "$LIBREOFFICE_ONLINE_REPO" ]; then 42 LIBREOFFICE_ONLINE_REPO="https://git.libreoffice.org/online" 43fi; 44if [ -z "$LIBREOFFICE_ONLINE_BRANCH" ]; then 45 LIBREOFFICE_ONLINE_BRANCH="master" 46fi; 47echo "Building online branch '$LIBREOFFICE_ONLINE_BRANCH' from '$LIBREOFFICE_ONLINE_REPO'" 48 49if [ -z "$LIBREOFFICE_BUILD_TARGET" ]; then 50 LIBREOFFICE_BUILD_TARGET="" 51fi; 52echo "LibreOffice build target: '$LIBREOFFICE_BUILD_TARGET'" 53 54 55SRCDIR=$(realpath `dirname $0`) 56INSTDIR="$SRCDIR/instdir" 57 58if [ -z "$(lsb_release -si)" ]; then 59 echo "WARNING: Unable to determine your distribution" 60 echo "(Is lsb_release installed?)" 61 echo "Using Ubuntu Dockerfile." 62 HOST_OS="Ubuntu" 63else 64 HOST_OS=$(lsb_release -si) 65fi 66if ! [ -e "$SRCDIR/$HOST_OS" ]; then 67 echo "There is no suitable Dockerfile for your host system." 68 echo "Please fix this problem and re-run $0" 69 exit 1 70fi 71BUILDDIR="$SRCDIR/builddir" 72 73mkdir -p "$BUILDDIR" 74cd "$BUILDDIR" 75 76rm -rf "$INSTDIR" || true 77mkdir -p "$INSTDIR" 78 79##### cloning & updating ##### 80 81# libreoffice repo 82if test ! -d libreoffice ; then 83 git clone https://git.libreoffice.org/core libreoffice || exit 1 84fi 85 86( cd libreoffice && git fetch --all && git checkout $LIBREOFFICE_BRANCH && ./g pull -r ) || exit 1 87 88# online repo 89if test ! -d online ; then 90 git clone "$LIBREOFFICE_ONLINE_REPO" online || exit 1 91fi 92 93( cd online && git fetch --all && git checkout -f $LIBREOFFICE_ONLINE_BRANCH && git clean -f -d && git pull -r ) || exit 1 94 95##### LibreOffice ##### 96 97# build LibreOffice 98( cd libreoffice && ./autogen.sh --with-distro=LibreOfficeOnline) || exit 1 99( cd libreoffice && make $LIBREOFFICE_BUILD_TARGET ) || exit 1 100 101# copy stuff 102mkdir -p "$INSTDIR"/opt/ 103cp -a libreoffice/instdir "$INSTDIR"/opt/libreoffice 104 105##### loolwsd & loleaflet ##### 106 107# build 108( cd online && ./autogen.sh ) || exit 1 109( cd online && ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-silent-rules --with-lokit-path="$BUILDDIR"/libreoffice/include --with-lo-path=/opt/libreoffice $ONLINE_EXTRA_BUILD_OPTIONS) || exit 1 110( cd online && scripts/locorestrings.py "$BUILDDIR"/online "$BUILDDIR"/libreoffice/translations ) 111( cd online && scripts/unocommands.py --update "$BUILDDIR"/online "$BUILDDIR"/libreoffice ) 112( cd online && scripts/unocommands.py --translate "$BUILDDIR"/online "$BUILDDIR"/libreoffice/translations ) 113( cd online && make -j 8) || exit 1 114 115# copy stuff 116( cd online && DESTDIR="$INSTDIR" make install ) || exit 1 117 118# Create new docker image 119if [ -z "$NO_DOCKER_IMAGE" ]; then 120 cd "$SRCDIR" 121 122 # Pull the image first to be sure we're using the latest available 123 docker pull $(grep "FROM " $HOST_OS | cut -d ' ' -f 2) 124 125 docker build --no-cache -t $DOCKER_HUB_REPO:$DOCKER_HUB_TAG -f $HOST_OS . || exit 1 126 if [ -z "$NO_DOCKER_PUSH" ]; then 127 docker push $DOCKER_HUB_REPO:$DOCKER_HUB_TAG || exit 1 128 fi; 129else 130 echo "Skipping docker image build" 131fi; 132
