#!/bin/sh
#----------------------------------------------------------------------------
# /var/install/bin/pre-setup-packages-install-from-url-menu
#
# Creation:     2016-08-15 hbfl
# Last Update:  $Id$
#
# Copyright (c) 2016-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org
#
# 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 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------

# set package name
package_name='url'

# include config
. /etc/config.d/${package_name}

#debug=true

if ${debug:-false}
then
    exec 2>/tmp/$(basename ${0})-trace$$.log
    set -x
    ask_debug=true
    export ask_debug
fi

> /tmp/install-url.txt
chmod 0640 "/tmp/install-url.txt"

menu_file="${4}"

{
    echo "<title>Install package from URL</title>"
    echo "<package>url</package>"
    echo "<!-- /var/install/menu/setup.packages.install.from.url.menu -->"
    echo "<!-- Creation: $(/bin/date +%Y-%m-%d) by /var/install/bin/pre-setup-packages-install-from-url-menu -->"

    idx=1
    while [ ${idx} -le ${URL_N} ]
    do
        eval url_path='${URL_'${idx}'_PATH}'
        echo "URL_PATH_${idx}=\"${url_path}\"" >> /tmp/install-url.txt
        eval url_name='${URL_'${idx}'_NAME}'
        eval url_section='${URL_'${idx}'_SECTION}'

        if [ -z "${url_name}" ]
        then
            url_name="${url_path}"
        fi

        if [ "${url_section}" = "yes" ]
        then
            echo "<menu pre=\"pre-setup-packages-install-from-url-section-menu\" file=\"setup.packages.install.from.url.section.menu\">${idx} - ${url_name}</menu>"
        else
            echo "<script pre=\"pre-setup-packages-install-from-url-section-menu\" file=\"list-packages-eisman-url all ${url_path}\">${idx} - ${url_name}</script>"
        fi
        idx=$((${idx} + 1))
    done

} > "${menu_file}"

chmod 0640 "${menu_file}"

exit 0

# ---------------------------------------------------------------------------
# end
# ---------------------------------------------------------------------------