# Build recipe for dragora-installer.
#
# Copyright (c) 2019 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=dragora-installer
version=20191012
release=1

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/tools"

description="
Installer of Dragora GNU/Linux-Libre.

It contains the installer, help files and parts to perform
a complete installation of Dragora GNU/Linux-Libre.
"

homepage=http://www.dragora.org
license=GPLv3+

build()
{
    set -e

    # Define package location according to supported architectures
    case $arch in
    x86_64)
        installer_arch=x86_64
        ;;
    i?86)
        installer_arch=i586
        ;;
    armv7a)
        installer_arch=armv7a
        ;;
    *)
        echo ""
        echo "The Dragora installer will not be available for the architecture in"
        echo "which it is being compiled.  This package will not be produced."
        echo "Please contact the developers at <dragora-users@nongnu.org>."
        echo ""
        sleep 7
        return 0
    esac

    mkdir -p "${destdir}"/usr/sbin \
             "${destdir}"/usr/libexec/dragora-installer

    cp -p "${worktree}"/archive/dragora-installer/dragora-installer \
          "${destdir}"/usr/sbin/

    cp -p "${worktree}"/archive/dragora-installer/parts/* \
          "${destdir}"/usr/libexec/dragora-installer/

    for file in "${destdir}"/usr/sbin/* \
                "${destdir}"/usr/libexec/dragora-installer/*
    do
        sed -e "s|@PARTS@|/usr/libexec/dragora-installer/|g" \
            -e "s|@ARCH@|${installer_arch}|g" \
            -i "$file"
    done
    unset file

    chmod 755 "${destdir}"/usr/sbin/dragora-installer
    chmod 644 "${destdir}"/usr/libexec/dragora-installer/*

    unset installer_arch
}

