Skip to content
Snippets Groups Projects
build.sh 4.04 KiB
Newer Older
#!/bin/bash
################################################################################
akiraohgaki's avatar
akiraohgaki committed
# This is utility script to build distribution packages
################################################################################

akiraohgaki's avatar
akiraohgaki committed
PKGNAME='ocs-url'

BUILDTYPE=''
if [ "${1}" ]; then
    BUILDTYPE="${1}"
fi

akiraohgaki's avatar
akiraohgaki committed
PROJDIR="$(cd "$(dirname "${0}")/../" && pwd)"

BUILDVER="$(cd "${PROJDIR}" && git describe --always)"

BUILDDIR="${PROJDIR}/build_${PKGNAME}_${BUILDVER}_${BUILDTYPE}"

SRCARCHIVE="${BUILDDIR}/${PKGNAME}.tar.gz"

export_srcarchive() {
    filepath="${1}"
akiraohgaki's avatar
akiraohgaki committed
    $(cd "${PROJDIR}" && git archive --prefix="${PKGNAME}/" --output="${filepath}" HEAD)
akiraohgaki's avatar
akiraohgaki committed
build_ubuntu() {
akiraohgaki's avatar
akiraohgaki committed
    cd "${PROJDIR}"
    mkdir -p "${BUILDDIR}"
    export_srcarchive "${SRCARCHIVE}"
akiraohgaki's avatar
akiraohgaki committed

    tar -xzvf "${SRCARCHIVE}" -C "${BUILDDIR}"
    cp -r "${PROJDIR}/pkg/ubuntu/debian" "${BUILDDIR}/${PKGNAME}"
    cd "${BUILDDIR}/${PKGNAME}"
    debuild -uc -us -b
akiraohgaki's avatar
akiraohgaki committed

akiraohgaki's avatar
akiraohgaki committed
build_fedora() {
akiraohgaki's avatar
akiraohgaki committed
    cd "${PROJDIR}"
    mkdir -p "${BUILDDIR}"
    export_srcarchive "${SRCARCHIVE}"

    mkdir "${BUILDDIR}/SOURCES"
    mkdir "${BUILDDIR}/SPECS"
    mv "${SRCARCHIVE}" "${BUILDDIR}/SOURCES"
    cp "${PROJDIR}/pkg/fedora/${PKGNAME}.spec" "${BUILDDIR}/SPECS"
    rpmbuild --define "_topdir ${BUILDDIR}" -bb "${BUILDDIR}/SPECS/${PKGNAME}.spec"
}
akiraohgaki's avatar
akiraohgaki committed
build_archlinux() {
akiraohgaki's avatar
akiraohgaki committed
    cd "${PROJDIR}"
    mkdir -p "${BUILDDIR}"
    export_srcarchive "${SRCARCHIVE}"
akiraohgaki's avatar
akiraohgaki committed

    cp "${PROJDIR}/pkg/archlinux/PKGBUILD" "${BUILDDIR}"
    cd "${BUILDDIR}"
    updpkgsums
    makepkg -s
akiraohgaki's avatar
akiraohgaki committed
build_snap() {
akiraohgaki's avatar
akiraohgaki committed
    cd "${PROJDIR}"
akiraohgaki's avatar
akiraohgaki committed
    mkdir -p "${BUILDDIR}"
    export_srcarchive "${SRCARCHIVE}"
    tar -xzvf "${SRCARCHIVE}" -C "${BUILDDIR}"
    cp "${PROJDIR}/pkg/snap/snapcraft.yaml" "${BUILDDIR}/${PKGNAME}"
    cp -r "${PROJDIR}/pkg/snap/setup" "${BUILDDIR}/${PKGNAME}"
    cd "${BUILDDIR}/${PKGNAME}"
akiraohgaki's avatar
akiraohgaki committed
    snapcraft
akiraohgaki's avatar
akiraohgaki committed
build_appimage() {
    cd "${PROJDIR}"
akiraohgaki's avatar
akiraohgaki committed
    mkdir -p "${BUILDDIR}"
    export_srcarchive "${SRCARCHIVE}"

    tar -xzvf "${SRCARCHIVE}" -C "${BUILDDIR}"
    cd "${BUILDDIR}/${PKGNAME}"
akiraohgaki's avatar
akiraohgaki committed
    sh scripts/import.sh
akiraohgaki's avatar
akiraohgaki committed
    qmake
    strip "${PKGNAME}"

    cd "${BUILDDIR}"
akiraohgaki's avatar
akiraohgaki committed

    # Replace linuxdeployqt download URL to official download URL when the stable version released
    curl -L -o linuxdeployqt https://dl.dropboxusercontent.com/u/150776/temp/linuxdeployqt-799f704-x86-64.appimage
    chmod 755 linuxdeployqt

    mkdir -p "${BUILDDIR}/${PKGNAME}.AppDir/usr/bin"
    install -m 755 -p "${BUILDDIR}/${PKGNAME}/${PKGNAME}" "${BUILDDIR}/${PKGNAME}.AppDir/${PKGNAME}"
    install -m 644 -p "${BUILDDIR}/${PKGNAME}/desktop/${PKGNAME}.desktop" "${BUILDDIR}/${PKGNAME}.AppDir/${PKGNAME}.desktop"
    install -m 644 -p "${BUILDDIR}/${PKGNAME}/desktop/${PKGNAME}.svg" "${BUILDDIR}/${PKGNAME}.AppDir/${PKGNAME}.svg"
    install -m 755 -p /usr/bin/update-desktop-database "${BUILDDIR}/${PKGNAME}.AppDir/usr/bin/update-desktop-database"
    install -m 755 -p /usr/bin/desktop-file-validate "${BUILDDIR}/${PKGNAME}.AppDir/usr/bin/desktop-file-validate"
    install -m 755 -p /usr/bin/desktop-file-install "${BUILDDIR}/${PKGNAME}.AppDir/usr/bin/desktop-file-install"
akiraohgaki's avatar
akiraohgaki committed
    ./linuxdeployqt "${BUILDDIR}/${PKGNAME}.AppDir/${PKGNAME}" -qmldir="${BUILDDIR}/${PKGNAME}/app/qml" -verbose=2 -bundle-non-qt-libs # https://github.com/probonopd/linuxdeployqt/issues/25
    ./linuxdeployqt "${BUILDDIR}/${PKGNAME}.AppDir/${PKGNAME}" -qmldir="${BUILDDIR}/${PKGNAME}/app/qml" -verbose=2 -bundle-non-qt-libs # twice because of #25
    rm "${BUILDDIR}/${PKGNAME}.AppDir/AppRun"
akiraohgaki's avatar
akiraohgaki committed
    install -m 755 -p "${BUILDDIR}/${PKGNAME}/pkg/appimage/appimage-desktopintegration_${PKGNAME}" "${BUILDDIR}/${PKGNAME}.AppDir/AppRun"
akiraohgaki's avatar
akiraohgaki committed
    ./linuxdeployqt --appimage-extract
    ./squashfs-root/usr/bin/appimagetool "${BUILDDIR}/${PKGNAME}.AppDir"
if [ "${BUILDTYPE}" = 'ubuntu' ]; then
akiraohgaki's avatar
akiraohgaki committed
    build_ubuntu
elif [ "${BUILDTYPE}" = 'fedora' ]; then
akiraohgaki's avatar
akiraohgaki committed
    build_fedora
elif [ "${BUILDTYPE}" = 'archlinux' ]; then
akiraohgaki's avatar
akiraohgaki committed
    build_archlinux
akiraohgaki's avatar
akiraohgaki committed
elif [ "${BUILDTYPE}" = 'snap' ]; then
akiraohgaki's avatar
akiraohgaki committed
    build_snap
elif [ "${BUILDTYPE}" = 'appimage' ]; then
akiraohgaki's avatar
akiraohgaki committed
    build_appimage
akiraohgaki's avatar
akiraohgaki committed
    echo "sh $(basename "${0}") [ubuntu|fedora|archlinux|snap|appimage]"
    exit 1