#!/usr/bin/bash

# Copyright 2019-2025 Mechtilde and Michael Stehmann <mechtilde@debian.org>
# version 0.9.9

# 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, write to the Free Software
# Foundation, Inc., 31 Milk Street, #960789 Boston,
# MA 02196, USA.

# Dependencies: git-buildpackage, build-essential, less, pbuilder,
# pristine-tar, sudo, unzip, cowbuilder, cowdancer, debmake, quilt,
# locate, jq, lintian, devscripts, debhelper,
# sbuild, schroot, debootstrap, apt-cacher-ng,
# gradle-debian-helper, maven-debian-helper, libmaven-bundle-plugin-java


set -e

##########################

# Definitions of functions

##########################

function DebugRP {
    # Function to show a path and give an opportunity to exit
    # It is for debugging
    descstr=${1}
    pathstr=${2}
    if ! whiptail --title "Shows the path" \
    --yesno "${descstr}= ${pathstr}?" --yes-button "Yes" \
    --no-button "No" 15 60
    then
        exit
    fi
}

function InsertConfigLine {
    # Called by ReplaceConfigLines 

    # This function needs two parameters:
    # First the name of the variable
    # and second it's value

    ConfProp=$1
    ConfVal=$2

    echo ${ConfProp}"="${ConfVal} >> ${ConfigPath}${OrigName}

}

function ReplaceConfigLines {
    # Called by BuildNewVersion PQMigration ChangeEntry OwnServer CurSuffix
    
    # This function needs two parameters:
    # First the name of the variable
    # and second it's new value
    ConfProp=$1
    ConfVal=$2

    set +e
    cprop=$(grep --count ${ConfProp} ${ConfigPath}${OrigName})
    set -e
    if [ ${cprop} -ge 1 ]
    then
        # Masquerade slasches
        ConfVal=$(echo ${ConfVal} | sed 's/\//\\\//g')

        sed --in-place --expression="s/${ConfProp}=.*/${ConfProp}=${ConfVal}/g" \
        ${ConfigPath}${OrigName}
    else
        # InsertConfigLine needs two parameters:
        # name of the variable and new value
        InsertConfigLine ${ConfProp} ${ConfVal}
    fi
}

function GpgKeyAvailable {
    # Called by BuildWithUscan Import2Git CreateSignature ImportDebianPackage
    # PrepareUploading

    if ! whiptail --title "GPG-Key available?" \
    --yesno "GPG-Key must be available for signing." \
    --yes-button "Yes, is available" --no-button "Exit" 15 60
    then
        exit
    fi
    GettingFingerprint
}

function DetectPlugins {
    # Not Used.
    # Funktion to find Plugins

    # This function needs two options: the name of the plugin
    # and the name of the plugin script file
    PluginName=$1
    PluginFile=$2

    # Determine path to the (needed) plugin script
    PluginPathL=$(locate ${PluginFile})
    PluginPathA=(${PluginPathL})

    # If there is only one result
    if [ ${#PluginPathA[@]} -eq 1 ]
    then
        PluginPath=${PluginPathA[0]}
    # If there are some results    
    elif [ ${#PluginPathA[@]} -gt 1 ]
    then            
        i=0; slct=''
        for element in ${PluginPathA[*]}
        do
            slct=$slct' '$i' '${element}' off '
            i=$(expr $i + 1)
        done

        PluginNr=$(whiptail --title "${PluginName} plugin found" \
        --radiolist "Select:" 15 60 5 $slct \
        --cancel-button "Cancel" 3>&2 2>&1 1>&3)

        if [  $? -eq 1 ]
        then
            return 24
        fi

        PluginPath=${PluginPathA[${PluginNr}]}
    # If there is no result
    else 
        PluginFlag=0
        whiptail --title "File not found" \
        --msgbox "'${PluginFile}' was not located!" \
        15 60
        return 24
    fi
}

function AskConfig {
    # Called by ConfigFileLEC

    if [ -z "${SourceName}" ]
    then
        SourceName=$(whiptail --title "Source Package Name" \
        --inputbox "Name of the source package:" \
        --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)

        if [ $? -ne 0 ] # Cancel-Button was pressed
        then
            exit
        else
            changeflag=1
        fi
    fi

    if ! whiptail --title "Source Package Name" \
    --yesno "The name of the source package is ${SourceName}" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        SourceName=$(whiptail --title "Name of the source package" \
        --inputbox "Real name of the source package:" \
        --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)

        if [ ${#SourceName} -eq 0 -o $? -ne 0 ]
        then
            exit
        else
            changeflag=1
        fi
    fi

    if [ -z "${PackName}" ]
    then
        PackName=${SourceName}
        tadd=", too?"
    else
        tadd="?"
    fi

    if ! whiptail --title "PackName" \
    --yesno "The name of the package is ${PackName}${tadd}" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        PackName=$(whiptail --title "Name of the Debian Package" \
        --inputbox "Real name of the package,\nwhich should be built from ${SourceName}:" \
        --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)

        if [ ${#PackName} -eq 0 -o $? -ne 0 ]
        then
            exit
        else
            changeflag=1
        fi
    fi

    if [ -z "${SalsaName}" ]
    then
        SalsaName=$(whiptail --title "Group at Salsa" \
        --inputbox "Group on salsa.debian.org:" \
        --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)
        if [ $? -ne 0 ] # Cancel-Button was pressed
        then
            exit
        else
            SalsaName=${SalsaName}"/"${SourceName}".git"
        fi
    fi

    if ! whiptail --title "Salsa Name" \
    --yesno "Group and project name of the repo on salsa.debian.org is $SalsaName" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        SalsaName=$(whiptail --title "Salsa Group and Project Name" \
        --inputbox "Real group and project name of the repo on salsa.debian.org:" \
        --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)

        if [ ${#SalsaName} -eq 0 -o $? -ne 0 ]
        then
            exit
        else
            changeflag=1
        fi
    fi

    if [ -f ${ConfigPath}/DefaultValues ]
    then
        . ${ConfigPath}/DefaultValues
    fi

    if [ -n "${DefaultProjectPath}" ]
    then
        ProjectPath=${DefaultProjectPath}
    fi

    if [ -z "${ProjectPath}" ]
    then
        ProjectPath=$(whiptail --title "Path to Project Directory" \
        --inputbox "Path to the project directory on your local machine\n \
        (without '/${OrigName}':)" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)

        if [ -z "${ProjectPath}" ]
        then
            echo -e "Path to the project directory on your local machine\n \
            (without '/${OrigName}':)"
            read ProjectPath
        fi
        changeflag=1
    fi

    if ! whiptail --title "ProjectPath" \
    --yesno "Path to the project directory on your local machine \
    is ${ProjectPath}/${OrigName}" \
    --yes-button "Yes" --no-button "No" 15 60

    then
        ProjectPath=$(whiptail --title "Path to Project Directory" \
        --inputbox "Real path to the project directory on your local machine\n \
        (without '/${OrigName}':" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        if [ -z "${ProjectPath}" ]
        then
            echo -e "Path to the project directory on your local machine\n \
            (without '/${OrigName}':)"
            read ProjectPath
        fi
        if [ -z "${ProjectPath}" ]
        then
            exit
        else
            changeflag=1
        fi
    fi

    # Java Flag
    # This is needed to trigger special entries
    # in debian/control and debian/rules
    if [ -z "${JavaFlag}" ]
    then
        if whiptail --title "Java" --defaultno \
        --yesno "Do you want to build a Java package?" \
        --yes-button "Yes" --no-button "No" --defaultno 15 60
        then
            JavaFlag=1
        else
            JavaFlag=0
        fi
        changeflag=1
    fi

    # Maven Plugin
    if [ ${JavaFlag} -eq 1 ]
    then
        if [ -z "${MavenPluginFlag}" ]
        then
            if whiptail --title "Maven" --defaultno \
            --yesno "Should the (Java) package be built with maven?" \
            --yes-button "Yes" --no-button "No" --defaultno 15 60

            then
                MavenPluginFlag=1
            else
                MavenPluginFlag=0
            fi
            changeflag=1
        fi
    fi

    # Webext Flag
    # This is needed to trigger special entries
    # in debian/control and debian/rules
    if [ -z "${WebextFlag}" ]
    then
        if whiptail --title "Mozilla AddOns" --defaultno \
        --yesno "Do you want to build a Mozilla AddOn package?" \
        --yes-button "Yes" --no-button "No" --defaultno 15 60
        then
            WebextFlag=1
        else
            WebextFlag=0
        fi
        changeflag=1
    fi

    # Python Flag
    # This is needed to trigger special entries
    # in debian/control and debian/rules
    if [ -z "${PythonFlag}" ]
    then
        if whiptail --title "Python3 programs" --defaultno \
        --yesno "Do you want to build a Python3 package?" \
        --yes-button "Yes" --no-button "No" --defaultno 15 60
        then
            PythonFlag=1
        else
            PythonFlag=0
        fi
        changeflag=1
    fi

    if [ $changeflag -eq 1 ]
    then
        if [ -f ${ConfigPath}${OrigName} ]
        then
            rm ${ConfigPath}${OrigName}
        fi
        touch ${ConfigPath}${OrigName}

        # Shebang of the config file 
        SB='#!/usr/bin/bash'

        # The config file is a shell script
        echo ${SB} >> ${ConfigPath}${OrigName}
        echo '# ConfigFile for '${OrigName} >> ${ConfigPath}${OrigName}
        echo '## General parameters' >> ${ConfigPath}${OrigName}
        echo 'SourceName='${SourceName} >> ${ConfigPath}${OrigName}
        echo 'PackName='${PackName} >> ${ConfigPath}${OrigName}
        echo 'ProjectPath='${ProjectPath} >> ${ConfigPath}${OrigName}
        echo 'SalsaName='${SalsaName} >> ${ConfigPath}${OrigName}
        echo '## Parameters for Java packages'>> ${ConfigPath}${OrigName}
        echo 'JavaFlag='${JavaFlag} >> ${ConfigPath}${OrigName}
        if [ ${JavaFlag} -eq 1 ]
        then
            echo 'MavenPluginFlag='${MavenPluginFlag} >> ${ConfigPath}${OrigName}
        fi

        echo '## Parameters for Webext packages'>> ${ConfigPath}${OrigName}
        echo 'WebextFlag='${WebextFlag} >> ${ConfigPath}${OrigName}

        echo '## Parameters for Python3 packages'>> ${ConfigPath}${OrigName}
        echo 'PythonFlag='${PythonFlag} >> ${ConfigPath}${OrigName}s
        changeflag=0
    fi
}

function ReplaceTilde {
    # Called by ConfigFileLEC GbpConfIntegration 
    RecentUser=$(whoami)
    set +e
    tp=$(echo ${SuspectPath} | grep --count '^~')
    if [ $tp -ge 1 ]
    then
        CleanPath=$(echo ${SuspectPath} | \
        sed --expression="s/^~/\/home\/${RecentUser}/g")
    else
        CleanPath=${SuspectPath}
    fi

    # Replace / at the end
    CleanPath=$(echo ${CleanPath} | sed --expression="s/\/$//")
    set -e
}

function SetDefaults {
    # Called by ConfigfileLEC

    if [ -z "${WebextFlag}" ]
    then
        WebextFlag=0
    fi

    if [ -z "${PythonFlag}" ]
    then
        PythonFlag=0
    fi

    if [ -z "${JavaFlag}" ]
    then
        JavaFlag=0
    fi

    if [ -z "${MavenPluginFlag}" ]
    then
        MavenPluginFlag=0
    fi
}

function ConfigFileLEC {
    # Called by AskOrigName CreateNewBranch TaskSelect OwnServer

    ## Load, edit or create config file - using AskConfig

    # Path to config files directory
    ConfigPath=~/.debian_project/
    changeflag=0

    set +e
    if [ -f ${ConfigPath}${OrigName} ]
    then
        . ${ConfigPath}${OrigName} # executes config script
        less --LINE-NUMBERS ${ConfigPath}${OrigName}
        if ! whiptail --title "Check config file" \
        --yesno "Is the config file OK?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            Edit=$(whiptail --title "Edit Config File" \
            --radiolist "How do you like to edit the config file?" \
            15 60 2 "0" "Using Nano" on \
            "1" "Answering questions" off \
            --cancel-button "Exit" 3>&2 2>&1 1>&3)

            if [ -z "${Edit}" ]
            then
                whiptail --title "Bye" --msgbox "Bye" 15 60
                exit
            fi
            if [ ${Edit} -eq 0 ]
            then
                nano --linenumbers --mouse \
                --softwrap ${ConfigPath}${OrigName}
                . ${ConfigPath}${OrigName}
            else
                AskConfig
            fi
        fi
        . ${ConfigPath}${OrigName} # executes config script (another time)
        SetDefaults
    else
        if whiptail --title "Config file not found" \
        --yesno "There is no config file for ${OrigName}\n \
        which you can edit.\n \
        Do you want to create a new project?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            changeflag=1
            mkdir --parents ${ConfigPath}
            AskConfig
        else
            AskOrigName
        fi
    fi
    set -e
}

function CreateDirsAndLogFile {
    # Called by BuildApp ConfigFileLEC

    # Replace tilde if necessary
    SuspectPath=${ProjectPath}
    ReplaceTilde
    ProjectPath=${CleanPath}

    # Set paths
    PrjPath=${ProjectPath}/${OrigName}
    GitPath=${PrjPath}/${SourceName}

    # Create directories if necessary
    mkdir --parents ${PrjPath} # redundantly?
    mkdir --parents ${GitPath}

    # Create Log-File
    cd ${PrjPath}
    log=${PrjPath}/${OrigName}.log.txt
    touch ${log}
    echo -e "\n\n===\n=== $(date) ===\n===\n">>${log}
    echo "ConfigFile OK!" >> ${log}
}

function InsertDebName {

    # Called by AddNameAndEmail and itself
    DEBFULLNAME=$(whiptail --title "Name of the maintainer" \
    --inputbox "Please insert full name of the maintainer" \
    --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)
    if [ $? -ne 0 ]
    then
        exit
    fi
    
    # Test Name
    if [ -z "${DEBFULLNAME}" ]
    then
        whiptail --title "Your Name" \
        --msgbox "Your name is necessary." 15 60
        InsertDebName
    fi
}
function InsertDebEmail {

    # Called by AddNameAndEmail and itself
    DEBEMAIL=$(whiptail --title "Email of the maintainer" \
    --inputbox "Please insert email address of the maintainer" \
    --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)
    if [ $? -ne 0 ]
    then
        exit
    fi    

    # Regex string
    EmailR="\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b"

    # Test email address
    set +e
    if ! echo ${DEBEMAIL} | grep -E ${EmailR} > /dev/null
    then
        whiptail --title "Bad!" --msgbox "That's no email address." 15 60
        InsertDebEmail
    fi
    set -e
}
function AddNameAndEmail {
    # Called by BuildNewPackage CloneFromSalsa 
    # ImportDebianPackage and itself

    DEBValues
    GCName=${DEBFULLNAME}
    GCEmail=${DEBEMAIL}

    if [ -z "${GCName}" ]
    then
        InsertDebName
    fi
    # if [ -n "${GCName}" ]
    # then
        git config user.name ${GCName}
    # fi
    if [ -z "${GCEmail}" ]
    then
        InsertDebEmail
    fi
    # if [ -n "${GCEmail}" ]
    # then
        git config user.email ${GCEmail}
    # fi

    set +e
    configStr=$(git config --list | grep 'user')
    set -e

    if ! whiptail --title "Result" \
    --yesno "${configStr}\nAllright?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        AddNameAndEmail
    fi
}

function AddHomeServer {
    # Called by BuildNewPackage AddGitServer ImportDebianPackage
    if [ -n "$ServerName" ]
    then
        git remote add home $(whoami)@${ServerName}:/srv/git/${SourceName}.git

        whiptail --title "Remoteserver" \
        --msgbox "New server added:\n$(git remote --verbose)" 15 60
        echo -e "New server added:\n $(git remote --verbose)" >> ${log}
    fi
}

function BuildNewPackage {
    # Called by TaskSelect
    cd ${GitPath}
    if [ -d .git ]
    then
        echo "There seems already to be a git repository in ${GitPath}." >> ${log}
        if ! whiptail --title "Warning" \
        --yesno "There seems already to be a git repository in ${GitPath}.\n \
        However continue?" --yes-button "Yes" --no-button "No" 15 60
        then
            echo "Exit" >> ${log}
            exit
        fi
    else
        echo "In ${GitPath} a new git repository will be created." >> ${log}
        git init
        git remote add salsa git@salsa.debian.org:${SalsaName}

        if whiptail --title "Name and email" \
        --yesno "Do you like to add your name and email address \n \
        to the local git config file?" --yes-button "Yes" \
        --no-button "No" 15 60
        then
            AddNameAndEmail
        fi
        AddHomeServer
    fi

    whiptail --title "If not happened yet:" \
    --msgbox "Please create a git repo ${SalsaName} \n \
    on salsa.debian.org!" 15 60
    NoPull=1 # Do not ask for pulling from salsa.debian.org
    Task=2 # Go to BuildNewVersion
}

function IdentifyBranches {
    # Called by DebianBranchName AskDist DebianBranches
    cd ${GitPath}
    # sed is used to kill the asterisk
    bl=$(git branch --all | sed --expression='s/* /x_/')
}

function CreateNewCow {
    # Called by Distro4Branch UsingPBuilder

    bDist="sid"
    set +e
    bDist=$(whiptail --title "Create new cow for ${RecentBranch}" \
    --inputbox  "Debian distribution\n \
    for this branch ${RecentBranch}:" \
    --cancel-button "Use Sid" 15 60 3>&2 2>&1 1>&3)
    if [ -z "${bDist}" ]
    then
        bDist="sid"
    fi
    # You must be root to create a cow
    echo -e "\nPlease enter Password for creating pbuilder cow.\n"
    sudo DIST=${bDist} git-pbuilder create
    echo "Cow for "${bDist}" created." >> ${log}
    set -e
}

function Distro4Branch {
    # Called by DebianBranchName CreateNewBranch AskDist BuildNewRevision

    set +e
    # Set Debian distribution for branch
    if [ ${RecentBranch} != "debian/sid" -o -z "${RecentBranchD}" ]
    then
        CowL=$(ls /var/cache/pbuilder/ | grep .cow | grep '-'| \
        sed 's/base-//' | sed 's/.cow//')
        CowA=($CowL)

        i=1; cowE="0 sid on "
        for element in ${CowA[*]}
        do
            cowE=$cowE' '$i' '${element}' off '
            i=$(expr $i + 1)
        done

        RecentBranchDNr=$(whiptail --title "Debian release" \
        --radiolist "Select pbuilder cow:" \
        --cancel-button "Other" 15 60 8 \
        $cowE 3>&2 2>&1 1>&3)
        if [ $? -eq 1 ]
        then
            CreateNewCow
        fi

        if [ ${RecentBranchDNr} -eq 0 ]
        then
            bDist="sid"
        else
            RecentBranchDNr=$(expr ${RecentBranchDNr} - 1)
            bDist=${CowA[${RecentBranchDNr}]}
        fi
        
        echo "# "${RecentBranch}"_Dist="${bDist} >> ${ConfigPath}${OrigName}
        RecentBranchD=${bDist}
        echo "Notice from Distro4Branch: The distribution is " \
        ${RecentBranchD} >> ${log}
    fi
    set -e
}

function DebianBranchName {
    # Called by CloneFromSalsa

    ## Identify and show branches
    IdentifyBranches
    ba=($bl)

    whiptail --title "Branches in repo ${OrigName}:" --msgbox "${bl}" 15 60

    set +e
    for element in ${ba[*]}
    do
        # Find the default branch
        if echo ${element} | grep --quiet '^x_'
        then
            DefaultBranch=$(echo ${element} | sed --expression='s/^x_//')
            whiptail --title "Recent branch found" \
            --msgbox "Found: ${DefaultBranch}" 15 60
        fi
        # Ignore HEAD
        if echo ${element} | grep --quiet 'HEAD'
        then continue
        fi
        # Checkout all branches
        if echo ${element} | grep --quiet '^remotes/salsa/'
        then
            NewBranchName=$(echo ${element} | \
            sed --expression='s/^remotes\/salsa\///')
            git checkout ${NewBranchName}
            whiptail --title "Checkout branch" \
            --msgbox "Checkout of ${NewBranchName}" 15 60
        fi
    done
    set -e

    # Finally checkout the default branch (again)
    git checkout ${DefaultBranch}
    whiptail --title "Checkout branch" \
    --msgbox "Checkout of ${DefaultBranch}" 15 60
    
    # Insert default branch into the config file and write into logfile   
    echo 'DefaultBranch='${DefaultBranch} >> ${ConfigPath}${OrigName}
    echo "Branches: "${bl} >> ${log}
    echo "DefaultBranch: "${DefaultBranch} >> ${log}
    RecentBranch=${DefaultBranch}
    whiptail --title "Please check! (1)" \
    --msgbox "The branch is ${RecentBranch}" 15 60
    echo 'RecentBranch='${RecentBranch} >> ${ConfigPath}${OrigName}
    echo "RecentBranch: "${RecentBranch} >> ${log}
    Distro4Branch
}

function FailureNotice {
    # Called by PQImport CheckGitStatus RebasePQBranch PQMigration
    # You can call this function with a text as parameter (optional)

    if [ ! "$1" ]
    then
        echo "Failure"
        echo "Something went wrong!"
    else
        for i in $*
        do
            String=${String}" "$i
        done

        echo -e ${String}
    fi
    echo
    echo "Break for fixing it in another terminal"
    echo "After fixing press RETURN to go on!"
    read a
}

function PQImport {
    # Called by PQMigration and itself
    # returnflag=$1
    # if [ ! ${returnflag} ]
    # then
    #     returnflag=1
    # fi
    cd ${GitPath}
    set +e
    if echo $(git branch) | grep --quiet 'patch-queue/'${RecentBranch}
    # patch-queue branch already exists
    then
        set -e
        return
    fi
    set -e

    if [ -f debian/patches/series ]
    # debian/patches/series exists   
    then
        if whiptail --title "There are patches" \
        --yesno "Do you like to import the current patches\n\
         onto the patch-queue branch? (recommended)" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            CheckGitStatus
            set +e
            echo "Notice from gbp pq import: " >> ${log}
            gbp pq --verbose import >> ${log} 2>&1
            if [ $? -eq 1 ]
            then
                Notice="\n\nAll patches listed in debian/patches/series\n\
                have to be applicable"'!'"\n\
                For Details, look into the log file of the project.\n"
                FailureNotice ${Notice}
                if whiptail --title "Fixed?" --yesno "Retry?" \
                --yes-button "Yes" --no-button "No import" 15 60
                then
                    PQImport ${returnflag}
                else
                    whiptail --title "No import onto a patch-queue branch" \
                    --msgbox "Let's go on without the import\n\
                    of the current patches onto a patch-queue branch" \
                    15 60
                fi
            fi
            set -e
        fi
    fi
}

function ClassicalOrUscan {
    # Called by PullFromSalsa

    if [ ! -f ${GitPath}/debian/watch ]
    then
        BuildNewVersion
        return

    else
        set +e
        # Download from Mozilla repos is not possible with uscan
        if grep --quiet "addons.thunderbird.net" ${GitPath}/debian/watch
        then
            whiptail --title "Thunderbird Repository" \
            --msgbox "From addons.thunderbird.net \nyou can't download with uscan" \
            15 60
            BuildNewVersion
            set -e
            return
        fi

        if grep --quiet "addons.mozilla.org" ${GitPath}/debian/watch
        then
            whiptail --title "Mozilla Repository" \
            --msgbox "From addons.mozilla.org \nyou can't download with uscan" \
            15 60
            BuildNewVersion
            set -e
            return
        fi
        set -e

        NVTask=$(whiptail --title "Classical download or uscan" \
        --radiolist "How do you want to download the new version? " 17 60 9 \
         "0" "using the classical way" on \
         "1" "using uscan" off --cancel-button "Exit" 3>&2 2>&1 1>&3)

        if [ -z "${NVTask}" ]
        then
            exit
        fi
        case "$NVTask" in
            0) BuildNewVersion;;
            1) BuildWithUscan;; 
        esac
    fi
}

function PullFromSalsa {
    # Called by TaskSelect
    
    cd ${GitPath}
    set +e
    if git remote --verbose | grep --quiet 'salsa'
    then
        if whiptail --title "Pull from Salsa?" \
        --yesno "Do you like to pull possible changes from salsa?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            echo "RecentBranch: "$(git branch) >> ${log}
            gbp pull --all salsa
            if [ $? -eq 0 ]
            then
                whiptail --title "Pulled successfully!" \
                --msgbox "'gbp pull --all salsa' successfully executed" 15 60
            else
                FailureNotice
            fi
        fi
    fi
    set -e
}

function CloneFromSalsa {
    # Called by TaskSelect
    echo "Clone an existing repo from salsa.debian.org" >> ${log}
    cd ${PrjPath}
    gbp clone git@salsa.debian.org:${SalsaName} --aliases ${SourceName}
    if [ $? -eq 0 ]
    then
        cd ${GitPath}
        git remote rename origin salsa
        echo "${SalsaName} was cloned" >> ${log}
    else
        echo "${SalsaName} could not be cloned"
        exit
    fi

    # Identify branches and choose one
    DebianBranchName

    if whiptail --title "Name and email" \
    --yesno "Do you like to add your name and email address \n \
    to the local git config file?" --yes-button "Yes" \
    --no-button "No" 15 60
    then
        AddNameAndEmail
    fi

    AddHomeServer
    CommonTasks
}

function CutSuffix {
    # Called by BuildNewVersion

    # List of reasonable suffixes
    typea=('.tar.gz' '.tar.xz' '.tgz' '.zip' '.oxt' '.xpi'\
     '.jar' '.tar.bz2' 'tar.lzma')

    KnownTyp=0
    set +e
    for element in ${typea[*]}
    do
        if echo ${UpstreamSourceName} | grep ${element} > /dev/null
        then
            echo "Notice from CutSuffix: The suffix of the upstream \
            file is "${element} >> ${log}
            UpstreamSuffix=${element}
            RecentUpstreamSuffix=$(echo ${UpstreamSuffix} | sed --expression s/^.//)
            ReplaceConfigLines 'RecentUpstreamSuffix' ${UpstreamSuffix}
            KnownTyp=1
        fi
    done
    set -e

    if [ ${KnownTyp} -ne 1 ]
    then
        echo "Notice from CutSuffix: Unknown suffix" >> ${log}
        if ! whiptail --title "Unknown suffix" \
        --yesno "The suffix of ${UpstreamSourceName} is not listed.\n \
        Continue anyway?" --defaultno --yes-button "Yes" \
        --no-button "No" 15 60
        then
            exit
        fi
    fi
}

function Name2Version {
    # Called by BuildNewVersion
    # Extracts version from uptream archive name
    Suffix=$(echo ${UpstreamSuffix} | sed --expression='s/\./\\\./g')
    Version1=$(echo ${UpstreamSourceName} | sed --expression="s/${Suffix}$//" | \
    sed --expression="s/.*${SourceName}//gI" | \
    sed --expression='s/-//' | sed --expression='s/v//')
    if [ -z ${Version1} ]
    then
        Version1="0.0.0" # Default value
    fi
}

function GbpConfIntegration {
    # Called by SearchGbpConf and itself
    GbpConfPath=$(whiptail --title "gbp.conf" \
    --inputbox "Please insert the path to the your special\n \
     gbp.conf for this project:" \
    --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
    if [ -z "${GbpConfPath}" ]
    then
        echo "Please insert the path to the your special gbp.conf for this project:"
        read GbpConfPath
    fi
    
    # Replace tilde if necessary
    SuspectPath=${GbpConfPath}
    ReplaceTilde
    GbpConfPath=${CleanPath}
    
    if [ -f ${GbpConfPath}/gbp.conf ]
    then
        cp -av ${GbpConfPath}/gbp.conf ${GitPath}/.git/
    else
        if whiptail --title "File not found!" \
        --yesno "There was no gbp.conf found at ${GbpConfPath}! Retry?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            GbpConfIntegration
        fi
    fi
}

function TwoConfFilesFound {
    # Called by SearchGbpConf MovingGbpConfFile

    whiptail --title "Information" \
    --msgbox "There are a gbp.conf in debian/ and a gbp.conf in .git/" 15 60
    # Are they different?
    GitConfFile=$(cat ${GitPath}/.git/gbp.conf)
    DebianConfFile=$(cat ${GitPath}/debian/gbp.conf)
    if [ "${GitConfFile}" != "${DebianConfFile}" ]
    then
        whiptail --title "Warning!" \
        --msgbox "There are a gbp.conf in debian/ and a gbp.conf in .git/\n \
        But they are different!\n\nThe left column is ${GitPath}/.git/gbp.conf\n \
        The right column is ${GitPath}/debian/gbp.conf\n \
        After studying the diff press RETURN!" 15 60

        diff --side-by-side ${GitPath}/.git/gbp.conf ${GitPath}/debian/gbp.conf
        read a
    fi
    # Editing
    if whiptail --title "debian/gbp.conf" \
    --yesno "Do you want to edit ${GitPath}/debian/gbp.conf?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        nano --linenumbers --mouse --softwrap ${GitPath}/debian/gbp.conf
    fi
    if whiptail --title ".git/gbp.conf" \
    --yesno "Do you want to edit  ${GitPath}/.git/gbp.conf (too)?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        nano --linenumbers --mouse --softwrap ${GitPath}/.git/gbp.conf
    fi
}

function SearchGbpConf {
    # Called by BuildNewVersion BuildWithUscan

    # Neither .git/gbp.conf nor debian/gbp.conf exist
    if [ ! -f ${GitPath}/.git/gbp.conf -a ! -f ${GitPath}/debian/gbp.conf ]
    then
        if whiptail --title "gbp.conf needed?" \
        --yesno "Do you want to integrate a special gbp.conf for this project?" \
        --defaultno --yes-button "Yes" --no-button "No" 15 60
        then
            GbpConfIntegration
        fi
    fi
    # debian/gbp.conf exists, but not .git/gbp.conf
    if [ ! -f ${GitPath}/.git/gbp.conf -a -f ${GitPath}/debian/gbp.conf ]
    then
        whiptail --title "Found gbp.conf" \
        --msgbox "Please check and edit your gbp.conf (if necessary)" 15 60


        nano --linenumbers --mouse --softwrap ${GitPath}/debian/gbp.conf
    fi
    # .git/gbp.conf exists, but not debian/gbp.conf
    if [ -f ${GitPath}/.git/gbp.conf -a ! -f ${GitPath}/debian/gbp.conf ]
    then
        whiptail --title "Found gbp.conf" \
        --msgbox "Please check and edit your gbp.conf (if necessary)" 15 60


        nano --linenumbers --mouse --softwrap ${GitPath}/.git/gbp.conf
    fi
    # There is a gbp.conf in both directories
    if [ -f ${GitPath}/.git/gbp.conf -a -f ${GitPath}/debian/gbp.conf ]
    then
        TwoConfFilesFound
    fi
}

function MovingGbpConfFile {
    # Called by BuildNewRevision

    # .git/gbp.conf exists, but not debian/gbp.conf
    # Move gbp.conf from .git/ to debian/
    if [ -f ${GitPath}/.git/gbp.conf -a ! -f ${GitPath}/debian/gbp.conf ]
    then
        mv -iv ${GitPath}/.git/gbp.conf ${GitPath}/debian
    fi
    # There is a gbp.conf in both directories
    if [ -f ${GitPath}/.git/gbp.conf -a -f ${GitPath}/debian/gbp.conf ]
    then
        TwoConfFilesFound
    fi
}

function DebianBranch4Import {
    # Called by BuildNewVersion # Makes sure RecentBranch contains value
    set +e
    RecentBranch=$(grep 'RecentBranch=' ${ConfigPath}${OrigName})
    RecentBranch=$(echo ${RecentBranch} | sed --expression='s/RecentBranch=//')
    set -e
    if [ -z "${RecentBranch}" ]
    then
        RecentBranch="debian/sid"
        changeflag=1
        whiptail --title "Set RecentBranch" \
        --msgbox "Set RecentBranch to ${RecentBranch}" 15 60
    fi

    if [ $changeflag -eq 1 ]
    then
        echo 'RecentBranch='${RecentBranch} >> ${ConfigPath}${OrigName}
    fi
    echo "Notice from DebianBranch4Import: \
    The branch is "${RecentBranch} >> ${log}
    changeflag=0
}

function SpecialExcludeFile {
    # Called by ExcludeFiles
    if [ -z "${ExcludeFile}" ]
    then
        ExcludeFile=$(whiptail --title "Name of exclude file" \
        --inputbox "Please insert name of the exclude file:" \
        --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)

        if [ -z "${ExcludeFile}" ]
        then
            exit
        fi
        echo 'ExcludeFile='${ExcludeFile} >> ${ConfigPath}${OrigName}
    else
        whiptail --title "Exclude file name" \
        --msgbox "The name of the exlude file is ${ExcludeFile}" \
        15 60
    fi
    AddOpt=" --copyright-file "${ExcludeFile}
}

function ExcludeFiles {
    # Called by BuildNewVersion

    # Checks whether debian/copyright contains a section Files-Excluded
    gitflag=0
    exflag=0
    crflag=0
    if [ -f ${GitPath}/debian/copyright ]
    then
        crflag=1
        set +e
        grep 'Files-Excluded' ${GitPath}/debian/copyright > /dev/null
        if [ $? -eq 0 ]
        then
            exflag=1
            whiptail --title "Copyright file contains Files-Excluded" \
            --msgbox "debian/copyright contains section Files-Excluded." 15 60
            less --LINE-NUMBERS ${GitPath}/debian/copyright
        fi
        set -e
    fi

    if whiptail --title "Exclude files from upstream source" \
    --yesno "Do you want to exclude files from upstream source?" \
    --defaultno --yes-button "Yes" --no-button "No" 15 60
    then
        if [ $crflag -eq 1 ]
        then
            if whiptail --title "Copyright file exitst" \
            --yesno "debian/copyright exists.\nDo you want to edit it?" \
            --yes-button "Yes" --no-button "No" 15 60

            then
                gitflag=1
                nano --linenumbers --mouse --softwrap ${GitPath}/debian/copyright
            fi
            AddOpt="  --copyright-file "${SourceName}"/debian/copyright"

        else
            SpecialExcludeFile
        fi

        ESuffixN=$(whiptail --title "Suffix:" \
        --radiolist "Please choose the suffix: " \
        --cancel-button "Cancel" 15 60 4 \
        "0" "+ds" off \
        "1" "+dfsg" on \
        "2" "other" off 3>&2 2>&1 1>&3)
        if [ ${ESuffixN} -eq 1 ]
        then
            ESuffix="+dfsg"
        elif [ ${ESuffixN} -eq 0 ]
        then
            ESuffix="+ds"
        else
            ESuffix=$(whiptail --title "Enter suffix" \
            --inputbox "Please insert the suffix:" \
            --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        fi
        if [ -z "${ESuffix}" ]
        then
            whiptail --title "Warning!" \
            --msgbox "You repacked the upstream source and\n\
            do not want to use a repack suffix." 15 60
            if [ -n "${RecentRepackSuffix}" ]
            then
                # Remove suffix from config file
                sed --in-place \
                --expression="s/RecentRepackSuffix=.*//g" \
                ${ConfigPath}${OrigName}
            fi    
        else
            # Insert suffix into config file
            if [ -z "${RecentRepackSuffix}" ]
            then
                echo "RecentRepackSuffix="${ESuffix} >> ${ConfigPath}${OrigName}
            else
                sed --in-place \
                --expression="s/RecentRepackSuffix=.*/RecentRepackSuffix=${ESuffix}/g" \
                ${ConfigPath}${OrigName}
            fi

            RecentRepackSuffix=${ESuffix}
            AddOpt=${AddOpt}" --repack-suffix "${ESuffix}
        fi    
        whiptail --title "Option(s) for mk-origtargz:" \
        --msgbox "\n${AddOpt}" 15 60
    else
        AddOpt=""
        ESuffix=""
        if [ $exflag -eq 1 ]
        then
            gitflag=1
            whiptail --title "Copyright file contains Files-Excluded" \
            --msgbox "debian/copyright contains Files-Excluded section.\n \
            Please delete it" 15 60
            nano --linenumbers --mouse \
            --softwrap ${GitPath}/debian/copyright
        fi
    fi

    if [ $gitflag -eq 1 ]
    then
        set +e
        git add debian/copyright
        git commit -am "Changed debian/copyright"
        set -e
    fi
}

function CheckSignature {
    # Called by DownloadAscFile
    gpg --verify ${UpstreamSourceName}.asc >> ${log}

    if [ $? -ne 0 ]
    then
        tail --lines=5 ${log}
        read x
    else
        whiptail --title "Check successfull!" --msgbox "gpg \
        --verify has been successfull" 15 60
    fi
}

function DownloadAscFile {
    # Called by BuildNewVersion and itself

    cd ${PrjPath}
    
    AscFileURL=$(whiptail --title "URL of .asc file" \
    --inputbox "URL and name (with suffix)\nof the .asc file:" \
    --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)

    if [ $? -eq 1 ]
    then
        return 1
    fi
    
    if [ -z "${AscFileURL}" ]
    then
        echo -e "URL and name (with suffix)\nof the .asc file:"
        read AscFileURL
    fi
    
    if [ -n  "${AscFileURL}" ]
    then    
        # getting -asc file using wget
        wget --version ${AscFileURL} &>> ${log}
        if [ $? -eq 0 ]
        then
            echo -e "The .asc file was pulled from\n${AscFileURL}\n \
            by wget." >> ${log}
            whiptail --title "Download successful" \
            --msgbox "${AscFileURL} was downloaded." 15 60
            if [ -r ${UpstreamSourceName}.asc ]
            then
                CheckSignature
            else
                whiptail --title "There is something wrong!" \
                --msgbox "Maybe you has downloaded the wrong .asc file." 15 60
                DownloadAscFile
            fi
        else
            DownloadAscFile
        fi
    fi
}

function Link2File {
    # Called by BuildNewVersion
    echo "Version: "${Version1} >> ${log}
    set +e
    OrigLinkNr=$(ls -la ${PrjPath} | grep ${Version1} | \
    grep --count -e '.orig.tar.[gx]z -> ')
    if [ $OrigLinkNr -ge 1 ]
    then
        OrigLink=$(ls -la ${PrjPath} | grep --regexp='.orig.tar.[gx]z -> ')
        OrigLink=$(echo ${OrigLink} | \
        sed --expression='s/^.*:.. //' | sed --expression='s/ //g')
        echo ${OrigLink}" will be transformed into a file" >> ${log}

        LinkTarget=$(echo $OrigLink | sed --expression='s/^.*->//')
        LinkName=$(echo $OrigLink | sed --expression='s/->.*$//')
        rm ${PrjPath}/${LinkName}
        cp -a ${PrjPath}/${LinkTarget} ${PrjPath}/${LinkName}
        whiptail --title "Result of transformation link to file:" \
        --msgbox "$(ls -la ${PrjPath})" --scrolltext 15 60
        echo "Result of transformation link to file: \
        "$(ls -la ${PrjPath}) >> ${log}
    fi
    set -e
}

function CheckGitStatus {
    # Called by Import2Git BuildWithUscan PQImport
    # PatchesTreatment SelectBranch and itself

    set +e
    # Checks git status
    echo "Notice from CheckGitStatus:" >> ${log}
    echo $(git status) >> ${log}

    if [ ! -z "$(git status --short)" ]
    then
        git status
        FailureNotice "'git status' shows problems\n\
        Please clean up 'git status'"
        if whiptail --title "Check another time?" \
        --yesno "Do you want to check the git status another time?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            CheckGitStatus
        fi
    fi
    set -e
}

function CheckTags {
    # Called by BuildWithUscan Import2Git and itself
    # checks git tags before executing gbp import-orig
    echo $(git tag) >> ${log}
    set +e
    cTags=$(git tag | grep --fixed-strings ${Version1})
    set -e
    if [ ${#cTags} -gt 0 ]
    then
        cTags1=$(echo ${cTags} | sed --expression='s/ /\\n/g')
        if ! whiptail --title "List of dubious tags:" \
        --yesno "${cTags1}\n\nDo you want to continue regardless?" --defaultno \
        --yes-button "Yes" --no-button "No" 15 60
        then
            whiptail --title "Delete tags!" \
            --msgbox "Please delete tags in another terminal\n \
            and then press ok" 15 60
            # git tag -d
            CheckTags
        fi
    fi
}

function Import2Git {
    # Called by BuildNewVersion and itself

    CheckGitStatus # to exercise caution
    CheckTags

    # Check branch for import
    bl=$(git branch --list | sed --expression='s/* /x_/')
    ba=($bl)
    set +e
    for element in ${ba[*]}
    do
        if echo ${element} | grep --quiet '^x_'
        then
            ActiveBranch=$(echo ${element} | sed --expression 's/\x_//')
        fi
    done
    set -e

    # After git init $ActiveBranch is always empty 
    if [ ${ActiveBranch} ] && [ "${ActiveBranch}" != "${RecentBranch}" ]
    then
        whiptail --title "Check Branch!" \
        --msgbox "The active branch is ${ActiveBranch}.\n\
        In ${ConfigPath}${OrigName} 'RecentBranch' is ${RecentBranch}." \
        15 60
        echo -e "The active branch is "${ActiveBranch}".\n"\
        "In "${ConfigPath}${OrigName}" 'RecentBranch' is "${RecentBranch}"."
        FailureNotice
    fi

    # Import to the git repo using gbp import

    echo "Notice from BuildNewVersion: The branch is \
    ${RecentBranch}" >> ${log}
    whiptail --title "Notice from BuildNewVersion:" \
    --msgbox "The branch is ${RecentBranch}" 15 60
    # The asterix (*) is for .bz2 and for lzma
    OrigFile=$(ls ${PrjPath}/${SourceName}_${Version1}.orig.tar.?z*)
    whiptail --title "Notice from BuildNewVersion:" \
    --msgbox "The orig file to be imported is ${OrigFile}" 15 60

    GpgKeyAvailable
    echo -e "\n Starting gbp import-orig - Please wait"'!'"\n"
    # Signing tags is default
    gbp import-orig --verbose --debian-branch=${RecentBranch} \
    --sign-tags ${OrigFile}

    if [ $? -eq 0 ]
    then
        echo ${OrigFile}" was imported by gbp import-orig"  >> ${log}
    else
        whiptail --title "Something went wrong!" \
        --msgbox "gbp import-orig -v --debian-branch=${RecentBranch} \
        --sign-tags ${OrigFile} failed!" 15 60
        echo "gbp import-orig -v --debian-branch="${RecentBranch}" \
        --sign-tags "${OrigFile}" failed!" >> ${log}
        FailureNotice
        Import2Git
    fi
}

function BuildNewVersion {
    # Called by ClassicalOrUscan

    echo "Building a new version" >> ${log}

    UpstreamSourceName=$(whiptail --title "Name of the source" \
    --inputbox "Please insert the file name of the upstream source version\n \
    to be downloaded or copied (including version and suffix):\n" \
    --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)

    if [ -z "${UpstreamSourceName}" ]
    then
        exit
    fi

    cd ${PrjPath}
    if whiptail --title "Should the source be downloaded?" \
    --yesno "Should $UpstreamSourceName\n \
    be downloaded from the upstream page?" \
    --defaultno --yes-button "Yes" --no-button "No" 15 60
    then
        if [ -z "${DownloadUrl}" ]
        then
            DownloadUrl=$(whiptail --title "Insert URL for download" \
            --inputbox "Please insert the complete\n \
            URL to download ${UpstreamSourceName}\n(with 'https://'\n \
            or so and the name of the archive):" \
            --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)
        fi

        if [ -z "${DownloadUrl}" ]
        then
            exit
        else
            changeflag=1
        fi

        if ! whiptail --title "DownloadUrl" \
        --yesno "The complete URL to download ${UpstreamSourceName} is\n \
        ${DownloadUrl}" --yes-button "Yes" --no-button "No" 15 60
        then
            DownloadUrl=$(whiptail --title "Complete URL" \
            --inputbox "Real complete URL to download ${UpstreamSourceName}\n \
            (with 'https://' or so and the name of the archive):" \
            --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)
        fi

        if [ -z "${DownloadUrl}" ]
        then
            exit
        else
            changeflag=1
        fi
        # Write download URL into config file
        if [ $changeflag -eq 1 ]
        then
            ReplaceConfigLines 'DownloadUrl' ${DownloadUrl} 
            changeflag=0
        fi

        # getting sources using wget
        wget --verbose $DownloadUrl &&
        echo -e "The sources were pulled from\n${DownloadUrl}\n \
        by wget." >> ${log}
        
        if whiptail --title ".asc file?" \
        --yesno "Do you want to download an .asc file, too?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            DownloadAscFile
        fi
    else
        whiptail --title "Please copy the source code now" \
        --msgbox "Please copy ${UpstreamSourceName} to ${PrjPath}!" 15 60
        if ! whiptail --title "Copy finished?" \
        --yesno "Was ${UpstreamSourceName} copied to ${PrjPath}?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            echo "Exit" >> ${log}
            whiptail --title "Bye" --msgbox "Bye" 15 60
            exit
        fi
    fi

    # Identify the type of the upstream archive by suffix
    CutSuffix

    # Identify the upstream version number
    Name2Version

    if ! whiptail --title "Version" \
    --yesno "You want to build version ${Version1}.\n\n \
    It must be a correct version number - not more!" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        Version1=$(whiptail --title "Version" \
        --inputbox "Name of the upstream version: ${UpstreamSourceName}\n \
        Which version (without repack identifiers and without revision)\n \
        of the package ${SourceName} should be built?" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)

        if ! whiptail --title "Version" \
        --yesno "Do you really want to build version ${Version1}." \
        --yes-button "Yes" --no-button "Exit" 15 60
        then
            echo "Exit" >> ${log}
            whiptail --title "Bye" --msgbox "Bye" 15 60
            exit
        fi
    fi

    ExcludeFiles

    echo "Version "${Version1}${ESuffix}" of the package "${PackName}" \
    should be built." >> ${log}

    # Creating orig file using mk-origtargz
    if [ -z ${Version1} ]
    then
        whiptail --title "No version number!" \
        --msgbox "No version - no *.orig.tar.gz! Bye!" \
        --ok-button "Exit" 15 60
        exit
    fi
    echo "mk-origtargz --package "${SourceName}" \
    --version "${Version1}${AddOpt}" "${UpstreamSourceName} >> ${log}
    mk-origtargz --package ${SourceName} \
    --version ${Version1}${AddOpt} ${UpstreamSourceName} 2>> ${log}
    if [ $? -eq 0 ]
    then
        echo "orig file was created by mk-origtargz" >> ${log}
        Version1=${Version1}${ESuffix}
    else
        echo "mk-origtargz failed" >> ${log}
        whiptail --title "Fatal error" \
        --msgbox "mk-origtargz failed" 15 60
        exit
    fi

    Link2File
    SearchGbpConf

    cd ${GitPath}
    
    DebianBranch4Import
    Import2Git # Contains import to the git repo using gbp import
    Task=3 # Go to BuildNewRevision
}

function DebianFormatTemplate { 
    # Called by DisplayDebianFiles

    if ! [ -f ${GitPath}/debian/source/format ]
    then
        # String for debian/source/format
        if whiptail --title "Kind of package" \
            --defaultno --yesno "Is it a native debian package?" \
            --yes-button "Yes" --no-button "No" 15 60

        then
            str4format="3.0 (native)"
        else
            str4format="3.0 (quilt)"
        fi

        touch ${GitPath}/debian/source/format
        echo ${str4format} >> ${GitPath}/debian/source/format
        echo "/debian/source/format was created." >> ${log}
    fi
    nano --linenumbers --mouse --softwrap ${GitPath}/debian/source/format
}

function DebianUpstreamMetadataTemplate {
    # Called by DisplayDebianFiles

    # Treatment for native packages
    set +e
    cat debian/source/format | grep "native" > /dev/null
    if [ $? -eq 0 ]
    then
        set -e
        return
    fi
    set -e

    # Strings for debian/upstream/metadata
    if ! [ -f ${GitPath}/debian/upstream/metadata ]
    then
        mkdir --parents debian/upstream
        # creating a template for debian/upstream/metadata
        echo -e "# You can find a description at\n#\
        https://wiki.debian.org/UpstreamMetadata" \
        >> debian/upstream/metadata
        echo "# Archive: " >> debian/upstream/metadata
        echo "# ASCL-id: " >> debian/upstream/metadata
        echo "Bug-Database: " >> debian/upstream/metadata
        echo "Bug-Submit: " >> debian/upstream/metadata
        echo "# Cite-As: " >> debian/upstream/metadata
        echo "Changelog: " >> debian/upstream/metadata
        echo "# CPE: " >> debian/upstream/metadata
        echo "Documentation: " >> debian/upstream/metadata
        echo "# Donation: " >> debian/upstream/metadata
        echo "# FAQ: " >> debian/upstream/metadata
        echo "# Funding: " >> debian/upstream/metadata
        echo "# Gallery: " >> debian/upstream/metadata
        echo "# Other-References: " >> debian/upstream/metadata
        echo "# Reference: " >> debian/upstream/metadata
        echo "#     Author: " >> debian/upstream/metadata
        echo "#     Booktitle: " >> debian/upstream/metadata
        echo "#     DOI: " >> debian/upstream/metadata
        echo "#     Editor: " >> debian/upstream/metadata
        echo "#     Eprint: " >> debian/upstream/metadata
        echo "#     ISBN: " >> debian/upstream/metadata
        echo "#     ISSN: " >> debian/upstream/metadata
        echo "#     Journal: " >> debian/upstream/metadata
        echo "#     Number: " >> debian/upstream/metadata
        echo "#     Pages: " >> debian/upstream/metadata
        echo "#     PMID: " >> debian/upstream/metadata
        echo "#     Publisher: " >> debian/upstream/metadata
        echo "#     Title: " >> debian/upstream/metadata
        echo "#     Type: " >> debian/upstream/metadata
        echo "#     URL: " >> debian/upstream/metadata
        echo "#     Volume: " >> debian/upstream/metadata
        echo "#     Year: " >> debian/upstream/metadata
        echo "#     Debian-package: " >> debian/upstream/metadata
        echo "# Registration: " >> debian/upstream/metadata
        echo "# Registry: " >> debian/upstream/metadata
        echo "Repository: " >> debian/upstream/metadata
        echo "Repository-Browse: " >> debian/upstream/metadata
        echo "# Screenshots: " >> debian/upstream/metadata
        echo "# Security-Contact: " >> debian/upstream/metadata
        echo "# Webservice: " >> debian/upstream/metadata
    fi
    nano --linenumbers --mouse --softwrap ${GitPath}/debian/upstream/metadata
}

function DebianCopyrightTemplate {
    # Called by DisplayDebianFiles

    if ! [ -f ${GitPath}/debian/copyright ]
    then
    # creating debian/copyright using debmake
        debmake -cc > debian/copyright
    fi
    nano --linenumbers --mouse --softwrap ${GitPath}/debian/copyright
}

function TeamMaintainer {
    # Called by DEBValues

    # Makes sure that variable exists
    if [ -z '${JavaFlag}' ]
    then
        JavaFlag = 0
    fi

    if [ ${JavaFlag} -eq 1 ]
    then
        Maintainer="Debian Java Maintainers \ 
        <pkg-java-maintainers@lists.alioth.debian.org>"
        MaintainerF=1
    fi

    if [ -z '${WebextFlag}' ]
    then
        WebextFlag = 0
    fi

    if [ ${WebextFlag} -eq 1 ]
    then
        Maintainer="Debian Mozilla Extension Maintainers \
        <pkg-mozext-maintainers@alioth-lists.debian.org>"
        MaintainerF=1
    fi

    if [ -z '${PythonFlag}' ]
    then
        PythonFlag = 0
    fi

    if [ ${PythonFlag} -eq 1 ]
    then
        Maintainer="Debian Python Team <team+python@tracker.debian.org>"
        MaintainerF=1
    fi
}

function DEBValues {
    # Called by DebianControlTemplate PatchHeader AddNameAndEmail
    MaintainerF=0
    set +e
    # if Maintainer is stored in config file
    if [ "${Maintainer}" ]
    then
        Maintainer=$(echo ${Maintainer} | sed --expression='s/_/ /g')
        Maintainer=$(echo ${Maintainer} | sed --expression='s/@lt@/</g')
        Maintainer=$(echo ${Maintainer} | sed --expression='s/@gt@/>/g')
        DEBFULLNAME=$(echo ${Maintainer} | sed --expression='s/<.*//')
        DEBEMAIL=$(echo ${Maintainer} | sed --expression='s/^.*<//' | sed 's/>//')
        MaintainerF=1
    fi

    # if Uploaders is stored in config file
    if [ "${Uploaders}" ]
    then
        Uploaders=$(echo ${Uploaders} | sed --expression='s/_/ /g')
        Uploaders=$(echo ${Uploaders} | sed --expression='s/@lt@/</g')
        Uploaders=$(echo ${Uploaders} | sed --expression='s/@gt@/>/g')
        DEBFULLNAME=$(echo ${Uploaders} | sed --expression='s/<.*//')
        DEBEMAIL=$(echo ${Uploaders} | sed --expression='s/^.*<//' | sed 's/>//')
    fi
    
    # Looking for a team as maintainer
    if [ ${MaintainerF} -eq 0 ]
    then
        TeamMaintainer
    fi

    # Extracts DEBFULLNAME and DEBEMAIL from ~/.bashrc (if exist)
    if [ ${MaintainerF} -eq 0 ]
    then
        if grep --quiet 'DEBFULLNAME' ~/.bashrc
        then
            dfnb=$(grep DEBFULLNAME ~/.bashrc)
            dfnb=$(echo ${dfnb} | sed --expression='s/export .*//')
            dfnb=$(echo ${dfnb} | sed --expression='s/DEBFULLNAME=//')
            dfnb=$(echo ${dfnb} | sed --expression='s/"//g')
            dfnb=$(echo ${dfnb} | sed --expression="s/'//g")
            DEBFULLNAME=${dfnb}
        fi
        if grep --quiet 'DEBEMAIL' ~/.bashrc
        then
            demb=$(grep 'DEBEMAIL' ~/.bashrc)
            demb=$(echo ${demb} | sed --expression='s/export .*//')
            demb=$(echo ${demb} | sed --expression='s/DEBEMAIL=//')
            demb=$(echo ${demb} | sed --expression='s/"//g')
            demb=$(echo ${demb} | sed --expression="s/'//g")
            DEBEMAIL=${demb}
        fi
        Maintainer=${DEBFULLNAME}" <"${DEBEMAIL}">"
        MaintainerF=1
    fi

    # Insert name and email address
    if [ ${MaintainerF} -eq 0 ]
    then
        DEBFULLNAME=$(whiptail --title "Name of the maintainer" \
        --inputbox "Please insert full name of the maintainer" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        DEBEMAIL=$(whiptail --title "Email of the maintainer" \
        --inputbox "Please insert email address of the maintainer" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        Maintainer=${DEBFULLNAME}" <"${DEBEMAIL}">"
        changeflag=1
        MaintainerF=1
    fi

    if ! whiptail --title "Maintainer" \
    --yesno "The full name and email address of the maintainer(s):\n \
    ${Maintainer}" --yes-button "OK" --no-button "Insert other" 15 60
    then
        DEBFULLNAME=$(whiptail --title "Name of the maintainer" \
        --inputbox "Please insert full name of the maintainer" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        DEBEMAIL=$(whiptail --title "Email of the maintainer"\
        --inputbox "Please insert email address of the maintainer" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        Maintainer=${DEBFULLNAME}" <"${DEBEMAIL}">"
        changeflag=1
        MaintainerF=1
    fi

    # Insert maintainer data into config file if necessary
    if [ $changeflag -eq 1 ]
    then
        # Because Maintainer contains blanks
        MaintainerCF=$(echo ${Maintainer} | sed --expression='s/ /_/g')
        # Remove < and >
        MaintainerCF=$(echo ${MaintainerCF} | sed --expression='s/</@lt@/g')
        MaintainerCF=$(echo ${MaintainerCF} | sed --expression='s/>/@gt@/g')
        echo '## Maintainer and Uploaders' >> ${ConfigPath}${OrigName}
        echo 'Maintainer='${MaintainerCF} >> ${ConfigPath}${OrigName}
        changeflag=0
    fi

     # Insert uploaders data into config file if necessary
    if [ ${JavaFlag} -eq 1 ]
    then
        if [ -z "${Uploaders}" ]
        then
            if grep --quiet 'DEBFULLNAME' ~/.bashrc
            then
                dfnb=$(grep DEBFULLNAME ~/.bashrc)
                dfnb=$(echo ${dfnb} | sed --expression='s/export .*//')
                dfnb=$(echo ${dfnb} | sed --expression='s/DEBFULLNAME=//')
                dfnb=$(echo ${dfnb} | sed --expression='s/"//g')
                dfnb=$(echo ${dfnb} | sed --expression="s/'//g")
                DEBFULLNAME=${dfnb}
            else
                DEBEMAIL=$(whiptail --title "Email of the uploader" \
                --inputbox "Please insert email address of the uploader" \
                --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
            fi
            if grep --quiet 'DEBEMAIL' ~/.bashrc
            then
                demb=$(grep 'DEBEMAIL' ~/.bashrc)
                demb=$(echo ${demb} | sed --expression='s/export .*//')
                demb=$(echo ${demb} | sed --expression='s/DEBEMAIL=//')
                demb=$(echo ${demb} | sed --expression='s/"//g')
                demb=$(echo ${demb} | sed --expression="s/'//g")
                DEBEMAIL=${demb}
            else
                DEBEMAIL=$(whiptail --title "Email of the uploader" \
                --inputbox "Please insert email address of the uploader" \
                --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
            fi
            Uploaders=${DEBFULLNAME}" <"${DEBEMAIL}">"        
            # Because Uploaders contains blanks
            UploadersCF=$(echo ${Uploaders} | sed --expression='s/ /_/g')
            # Remove < and >
            UploadersCF=$(echo ${UploadersCF} | sed --expression='s/</@lt@/g')
            UploadersCF=$(echo ${UploadersCF} | sed --expression='s/>/@gt@/g')
            echo 'Uploaders='${UploadersCF} >> ${ConfigPath}${OrigName}
            changeflag=0
        fi
     fi
     set -e
}

function DebianControlTemplate {
    # Called by DisplayDebianFiles

    # Strings for debian/control
    str4versiondebhelpers="(=13)"
    str4standardsversion="4.7.2"

    if ! [ -f ${GitPath}/debian/control ]
    then
        # creating a template for debian/control
        echo -e "Source: "${SourceName} > debian/control
        echo -e "Priority: optional" >> debian/control

        if [ ${JavaFlag} -eq 1 ]
        then
            echo -e "Section: java" >> debian/control
        else
            echo -e "Section:" >> debian/control
        fi
        DEBValues

        if [ -n "${Maintainer}" ]
        then
            echo -e "Maintainer: "${Maintainer} >> debian/control
        else
            echo "Maintainer: " >> debian/control
        fi
        
        if [ -n "${Uploaders}" ]
        then
            echo -e "Uploaders: "${Uploaders} >> debian/control
        fi

        echo -e "Build-Depends: debhelper-compat" \
        ${str4versiondebhelpers} >> debian/control
        if [ ${JavaFlag} -eq 1 ]
        then
            echo " , default-jdk" >> debian/control

            if [ ${MavenPluginFlag} -eq 1 ]
            then
                echo " , maven-debian-helper" >> debian/control
            fi
        fi
        echo -e "Standards-Version: "${str4standardsversion} \
        >> debian/control
        echo -e "Rules-Requires-Root: no" >> debian/control
        echo -e "Vcs-Git: https://salsa.debian.org/"${SalsaName} \
        >> debian/control
        BrowserName=$(echo ${SalsaName} | sed --expression='s/.git$//g')
        echo -e "Vcs-Browser: https://salsa.debian.org/"${BrowserName} \
        >> debian/control
        echo -e "Homepage: \n" >> debian/control
        echo -e "Package: "${PackName} >> debian/control
        echo -e "Architecture: all" >> debian/control
        echo -e "Depends: \${misc:Depends}" >> debian/control
        echo -e "Description: " >> debian/control
        echo "A template for debian/control was created." >> ${log}
        if [ ${WebextFlag} -eq 1 ]
        then
            WebextControl
        fi
        if [ ${PythonFlag} -eq 1 ]
        then
            PythonControl
        fi
    fi
    nano --linenumbers --mouse --softwrap ${GitPath}/debian/control
}

function OptionsWatchFile {
    # Called by DebianWatchfile

    olf='\\\n'
    WOpt='opts='

    # Repacked <UpstreamPackage>.zip
    RepackFlag=0
    ZipSuffix=(.zip .oxt .xpi .jar)
    if [[ ${ZipSuffix} =~ ${RecentUpstreamSuffix} ]]
    then
        WOpt=${WOpt}${olf}'repack,compression=xz,'
        RepackFlag=1
    fi

    # Excluded files
    if [ -z ${RecentRepackSuffix} ]
    then
        if [ ${RepackFlag} -eq 1 ]
        then
            WOpt=${WOpt}${olf}'repacksuffix='${RecentRepackSuffix}',\\\n'
        else
            WOpt=${WOpt}${olf}'repack,compression=xz,\\\n\
            repacksuffix='${RecentRepackSuffix}',\\\n'
        fi

        WOpt=${WOpt}${olf}'dversionmangle=s/'${RecentRepackSuffix}'//,'
    fi
 

    # For beta-, rc- etc. releases

    WOpt=${WOpt}${olf}'uversionmangle=s/-?([^\d.]+)/~$1/;tr/A-Z/a-z/,'
    # For packages from Github
    set +e
    if echo ${DownloadUrl} | grep "github" > /dev/null
    then
        WOpt=${WOpt}${olf}'filenamemangle=s/.+\/v?(\d\S+)\.*/$1/,'
    fi
    set -e

    # If there are no options
    if [ ${#WOpt} -eq 6 ]
    then
        WOpt='# '${WOpt}
        WOpt=$(echo ${WOpt} | sed 's/\\/\"\" \\/')
    fi

    echo -e ${WOpt} >> debian/watch
}


function DebianWatchTemplate {
    # Called by DisplayDebianFiles

    # Treatment for native packages
    set +e
    cat debian/source/format | grep "native" > /dev/null
    if [ $? -eq 0 ]
    then
        set -e
        return
    fi
    set -e
    # String for debian/watch
    str4watch="version=4"

    if ! [ -f ${GitPath}/debian/watch ]
    then
    # creating a template for debian/watch
        echo ${str4watch} > debian/watch
        OptionsWatchFile
        set +e
        if echo ${DownloadUrl} | grep "github" > /dev/null
        then
            DownloadUrl=$(echo ${DownloadUrl} | \
            sed --expression 's/archive.*$/releases/')
            DownloadUrl=${DownloadUrl}' .*/v?(\d\S+)\.tar\.gz'
            echo -e ${DownloadUrl} >> debian/watch
        fi
        set -e
        echo "A template for debian/watch was created." >> ${log}
        whiptail --title "Edit debian/watch!" \
        --msgbox "Please insert reasonable regular expressions\n \
         into debian/watch!" 15 60
    fi
    nano --linenumbers --mouse --softwrap ${GitPath}/debian/watch
}

function DebianRulesTemplate {
    # Called by DisplayDebianFiles

    # Strings for debian/rules
    str4rules="#!/usr/bin/make -f\n# -*- makefile -*-\n"\
    str4rulesdh="%:\n\tdh \$@\n\n"

    if ! [ -f ${GitPath}/debian/rules ]
    then
        touch ${GitPath}/debian/rules
        echo -e ${str4rules} >> ${GitPath}/debian/rules
        echo -e "# Uncomment this to turn on verbose mode.\n" \
        >> ${GitPath}/debian/rules        
        echo -e "export DH_VERBOSE=1\nexport DH_OPTIONS=-v\n" \
        >> ${GitPath}/debian/rules

        if [ ${JavaFlag} -eq 1 ]
        then
            . build-gbp-java-plugin
            Rules4Java
        fi    

        if [ ${WebextFlag} -eq 1 ]
        then
            WebextRules
        fi

        if [ ${PythonFlag} -eq 1 ]
        then
            PythonRules
        fi

        echo -e ${str4rulesdh} >> ${GitPath}/debian/rules

        if [ ${MavenPluginFlag} -eq 1 ]
        then
            Rules4MavenDH
        fi

        if [ ${WebextFlag} -eq 1 ]
        then
            WebextRulesDH
        fi

        if [ ${PythonFlag} -eq 1 ]
        then
            PythonRulesDH
        fi

        echo "debian/rules was created " >${log}

    fi
    nano --linenumbers --mouse --softwrap ${GitPath}/debian/rules

    if ! [ -x ${GitPath}/debian/rules ]
    then
        chmod ugo+x ${GitPath}/debian/rules
        echo ${GitPath}"/debian/rules is now executable" >> ${log}
    fi
}

function DebianSalsaCiTemplate {
    # Called by DisplayDebianFiles

    # String for debian/salsa-ci.yml
    str4salsa="include:\n\
    - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml\n\
    - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml"

    if ! [ -f ${GitPath}/debian/salsa-ci.yml ]
    then
        touch ${GitPath}/debian/salsa-ci.yml
        echo -e ${str4salsa} >> ${GitPath}/debian/salsa-ci.yml
        echo "debian/salsa-ci.yml was created." >> ${log}
    fi
    nano --linenumbers --mouse --softwrap ${GitPath}/debian/salsa-ci.yml
}

function SelectChangesFile {
    # Called by RunningLintian SelectUploadTarget

    titlestr=${1}
    cd ${PrjPath}
    changesa=($(ls ${SourceName}_${Version1}*_*.changes))

    if [ -z "${changesa}" ]
    then
        echo "File *"${SourceName}"*_"${Version1}"*_*.changes not found!"
        exit
    fi

    i=0; slct=''
    for element in ${changesa[*]}
    do
        slct=$slct' '$i' '${element}' off '
        i=$(expr $i + 1)
    done

    paket=$(whiptail --title "${titlestr}" --radiolist "Select:" \
    --cancel-button "Exit" 15 60 8 $slct 3>&2 2>&1 1>&3)


    if [ -z "${paket}" ]
    then
        exit
    fi
}

function PatchHeader {
    # Called by CreateNewPatch EditPatch

    PatchDescription=$(whiptail --title "Describe patch!" \
    --inputbox "Description:\n\n" \
    --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
    if [ -z "${PatchDescription}" ]
    then
        echo "Please insert the description of the patch!"
        read PatchDescription
    fi
    if whiptail --title "Describe patch!" --yesno "Forwarded:?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        PatchForwarded="Yes"
    else
        PatchForwarded="No"
    fi

    DEBValues
    if [ -z ${Uploaders} ]
    then
        PatchAuthor=${Maintainer}
    else
        PatchAuthor=${Uploaders}
    fi

    PatchUpdate=$(date +%Y'-'%m'-'%d)

    touch ${PatchFileName}.header
    echo "Description: "${PatchDescription} >> ${PatchFileName}.header
    echo "Forwarded:   "${PatchForwarded} >> ${PatchFileName}.header
    echo "Author:      "${PatchAuthor} >> ${PatchFileName}.header
    echo "Last-Update: "${PatchUpdate} >> ${PatchFileName}.header
    
    $dquilt header -a < ${PatchFileName}.header
    rm ${PatchFileName}.header
}

function FileSelector {
    # Called by CreateNewPatch and itself
    # Dialog to select a file using whiptail
    
    StartPath=$1
    cd $StartPath
    txta=($(ls -a))

    i=0
    flist=''
    for element in ${txta[*]}
    do
        if [ $element == '.' ]
        then
            i=$(expr $i + 1)
            continue
        fi
        flist=$flist' '$i' '${element} 
        i=$(expr $i + 1)
    done

    sel=$(whiptail --title "Filepicker" \
    --menu "Select:" 15 60 6 $flist 3>&2 2>&1 1>&3)

    if [ $? -ne 0 ]
    then
        return
    fi

    # Go back
    if [ ${txta[$sel]} = '..' ]
    then
        cd ..
        StartPath=$(pwd)
        selected=${StartPath}
    else
        selected=${StartPath}"/"${txta[$sel]}
    fi

    # The order of the following if-clauses is important
    if [ -f ${selected} ]
    then    
        if ! whiptail --title "Your choice;" \
        --yesno "${selected}\nContinue?" --yes-button "Yes" \
        --no-button "No" 15 60
        then
            FileSelector ${StartPath}
        fi
    fi

    if [ -d ${selected} ]
    then
        FileSelector ${selected}
    fi
}

function FileToPatch {
    # Called by CreateNewPatch PatchTasks and itself

    FileSelector ${GitPath} # Select the file to be patched
    File2Patch=${selected}

    echo "Patch ${PatchFileName} because of ${File2Patch}" >> ${log}

    # quilt add must get only the filename without 
    # the path of the file to be patched
    File2pName=$(basename ${File2Patch})
    $dquilt add -P ${PatchFileName} ${File2pName}

    nano --linenumbers --mouse --softwrap ${File2Patch}

    $dquilt refresh ${PatchFileName}

    if whiptail --title "Patch another" \
    --yesno "Do you want to patch another file in ${PatchFileName}?" \
    --yes-button "Yes" --no-button "No" --defaultno 15 60
    then
        FileToPatch
    fi
}

function CreateNewPatch {
    # Called by MakePatches

    PatchFileName=$(whiptail --title "Patch name" \
    --inputbox "Name of the patchfile:" \
    --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
    if [ $? -ne 0 ]
    then
        cnpr=1
        return 1
    fi


    # Because a user might use blanks in a filename
    PatchFileName=$(echo ${PatchFileName} | sed --expression='s/ /-/g')
    if [ -z "${PatchFileName}" ]
    then
        cnpr=1
        return 1
    fi

    if [ -f debian/patches/${PatchFileName} ]
    then
        if ! whiptail --title "Patch exists" \
        --yesno "${PatchFileName} exists already.\nContinue?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            return 1
        fi
    fi

    # Create a new patch file
    $dquilt new ${PatchFileName}

    # Patch
    FileToPatch
    PatchHeader
}

function CreateDquilt {
    # Called by PatchTasks

    # Check whether quilt is available
    if [ ${PatchRunNr} -eq 0 ]
    then
        if [ ! -f ~/.quiltrc-dpkg ]
        then
            whiptail --title "No dquilt!" \
            --msgbox "Dquilt seems not to be configured.\n \
            See: https://www.debian.org/doc/manuals/maint-guide/modify.html" \
            15 62
            exit
        fi

    # Definition of dquilt
        dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"
    fi   
}

function MakePatches {
    # Called by PatchTasks and itself

    cd ${GitPath}
    cnpr=0
    CreateNewPatch
    if [ $cnpr -ne 0 ]
    then
        return
    fi

    PatchRunNr=1

    if whiptail --title "Another patch?" \
    --yesno "Do you want to apply another patch?" --yes-button "Yes" \
    --no-button "No" 15 60
    then
        MakePatches
    fi
}

function ShowPatches {
    # Called by EditPatch DeletePatch PQMigration and itself
    actionstr=${1}

    patchfilesa=$(ls debian/patches)
    i=0; slct=''
    for element in ${patchfilesa[*]}
    do
        if [ ${element} != 'series' ]
        then
            slct=$slct' '$i' '${element}' off '
            newPFA[$i]=${element}
            i=$(expr $i + 1)
        fi
    done

    set +e
    PatchFileNo=$(whiptail --title "Select patch" \
    --radiolist "Select one of these patches for editing.\
    In doubt press Cancel." \
    --cancel-button "Cancel" 15 80 8 \
    $slct 3>&2 2>&1 1>&3)

    if [ $? -eq 1 ]
    then
        return
    fi
    set -e

    if [ "${actionstr}" = "check" ]
    then
        # Code for PQMigation
        if [ -z "${PatchFileNo}" ]
        then
            return
        fi
        PatchFileName=${newPFA[$PatchFileNo]}
        nano --linenumbers --mouse --softwrap debian/patches/${PatchFileName}
        ShowPatches "check"
    else
        if [ -z "${PatchFileNo}" ]
        then
            PatchFileName=""
        else
            PatchFileName=${newPFA[$PatchFileNo]}
            if ! whiptail --title "${PatchFileNo}" \
            --yesno "Do you want to ${actionstr} ${PatchFileName}?" \
            --yes-button "Yes" --no-button "No" 15 60
            then
                ShowPatches
            fi
        fi
    fi
}

function EditPatch {
    # Called by ChangePatches

    ShowPatches "edit" # String will be found in ${1}
    
    if [ -z "${PatchFileName}" ]
    then
        return 1
    else
        PatchRunNr=1
    fi

    $dquilt pop ${PatchFileName}
    nano --linenumbers --mouse --softwrap debian/patches/${PatchFileName}
    $dquilt refresh
    
    if whiptail --title "New Patch Header" \
    --yesno "Do you want to create a new patch header?" --yes-button "Yes" \
    --no-button "No" 15 60
    then
        PatchHeader
    fi
    
    while $dquilt push
    do
       $dquilt refresh
    done
}

function ChangePatches {
    # Called by PatchTasks and itself

    cd ${GitPath}
    EditPatch

    if whiptail --title "Another patch?" \
    --yesno "Do you want to edit another patch?" --yes-button "Yes" \
    --no-button "No" 15 60
    then
        ChangePatches
    fi
}

function DeletePatch {
    # Called by DeletePatches

    ShowPatches "delete" # String will be found in ${1}

    if [ -z "${PatchFileName}" ]
    then
        PatchTasks
    fi

    less --LINE-NUMBERS ${GitPath}/debian/patches/${PatchFileName}
    
    if whiptail --title "Delete this patch?" \
    --yesno "Do you really want to delete ${PatchFileName}?" \
    --yes-button "Yes" --no-button "No" 15 60
    then    
        $dquilt delete -r --backup ${PatchFileName}

        if whiptail --title "Delete backup file?" \
        --yesno "Do you want to delete the backup file, too" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            rm ${GitPath}/debian/patches/${PatchFileName}~
        fi
    fi
}

function DeletePatches {
    # Called by PatchTasks and itself
    
    cd ${GitPath}
    DeletePatch
    PatchRunNr=1

    if whiptail --title "Another patch?" \
    --yesno "Do you want to delete another patch?" --yes-button "Yes" \
    --no-button "No" 15 60
    then
        DeletePatches
    fi
}

function ApplyCheck {
    # Called by PQMigration

    echo -e "\nResults will also be written in "${log}"\n"
    echo -e "\nResults of tests of applicability of patches\n" >> ${log}
    patchfilesa=$(ls debian/patches/)
    set +e
    for element in ${patchfilesa[*]}
    do
        if [ ${element} != 'series' ]
        then
            echo "Check "${element}
            echo "Check "${element} >> ${log}
            acmessage=$(patch --dry-run -p1 --verbose < debian/patches/${element})
            echo ${acmessage}
            echo -e "\n"
            echo ${acmessage} >> ${log}
        fi
    done
    set -e
    # For reading whether the patches are applicable
    echo
    echo "-- Look whether the patches are applicable --"
    echo
    echo "After reading press RETURN to go on!"
    read a
}

function RebasePQBranch {
    # Called by PQMigration and itself
    if [ ${RebaseCounter} == 0 ]
    then
        gbp pq rebase --verbose
    else
        git rebase --continue
    fi

    if [ $? -ne 0 ]
    then
        git rebase --show-current-patch | cat
        Notice="gbp pq rebase failed"'!'"\n\
        All changes must be committed"'!'"\n\
        All patches have to be applicable"'!'"\n"
        FailureNotice ${Notice}
        RebaseCounter=$(expr ${RebaseCounter} + 1)
        RebasePQBranch
    fi
}

function PQMigration {
    # Called by PatchesTreatment and itself
    # Transfers patches into patch-queue branch
    npqf=0
    cd ${GitPath}
    
    if [ ! -f debian/patches/series ] # debian/patches/series does not exists
    then
        # Case 2
        # Anything is easy
        npqf=1
        set +e
        if echo $(git branch) | grep --quiet 'patch-queue/'${RecentBranch}
        then
            whiptail --title "PQ-branch exists" \
            --msgbox "Branch 'patch-queue/${RecentBranch}' exists." 15 60
            git checkout patch-queue/${RecentBranch}
        # Case 1
        else # creating a new patch-queue branch
            git checkout -b patch-queue/${RecentBranch}
        fi
        set -e
    else # debian/patches/series exists
        Notice="All patches listed in 'debian/patches/series' \n\
        have to be applicable"'!'"\n\
        Otherwise you have to solve 'merge conflicts'"'!'
        if whiptail --title "Attention please"'!' \
        --yesno "${Notice} Do you want to check the situation?" \
        --yes-button "Yes" --no-button "No" 15 60

        then
            if whiptail --title "Applicability check"'!' \
            --yesno "Do you want to check the applicability of the patches\n\
            (another time)?" \
            --yes-button "Yes" --no-button "No" 15 60
            then
                ApplyCheck
            fi
            ShowPatches "check"
            if whiptail --title "Attention please"'!' \
            --yesno "Do you want to edit 'debian/patches/series'?" \
            --yes-button "Yes" --no-button "No" 15 60
            then
                nano --linenumbers --mouse --softwrap debian/patches/series
            fi
        fi

        echo -e ${Notice}
        CheckGitStatus
    fi

    if [ ${npqf} -eq 0 ]
    then
        set +e
        if echo $(git branch) | grep --quiet 'patch-queue/'${RecentBranch}
        # patch-queue  branch exists
        then
            # Case 4
            RebaseCounter=0
            RebasePQBranch
        else # patch-queue branch does not exist
            # Case 3
            if whiptail --title "Attention"'!' \
            --yesno "Do you really want to use 'gbp pq import'?" \
            --yes-button "Yes" --no-button "Working with Quilt" 15 60
            then
                PQImport 0
            else
                PatchTasks # Working with Quilt
            fi
        fi
        set -e
    fi

    # Starting the work in the patch-queue branch
    echo
    echo "\033[32m-- Starting the work in the patch-queue branch --/033[0m"
    echo
    echo "Break for patching in another terminal"
    echo "Do not forget to commit the changes!"
    echo
    echo "After finishing press RETURN to go on!"
    read a

    # Export
    if whiptail --title "Use gbp pq export?" \
    --yesno "Do you like to use 'gbp pq export --commit'?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        CheckGitStatus
        gbp pq export --commit --verbose >> ${log} 2>&1
        echo "Check branch."
        git branch --verbose
        echo "Press RETURN to continue!"
        read a
    else
        git log
        git checkout ${HistoricBranch}
        ReplaceConfigLines 'RecentBranch' ${HistoricBranch}
        git branch
        echo "-- You have cancelled the export from patch-queue branch --"
        echo
        echo "You are still in the patch-queue branch!"
        echo "Break for fixing in another terminal"
        echo "After finishing press RETURN to go on!"
        read a
    fi
}

function PatchTasks {
    # Called by PatchesTreatment and itself

    cd ${GitPath}
    if [ ! -d debian/patches ]
    then
        # Create patch
        if whiptail --title "Patches" --yesno "Is a patch necessary?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            CreateDquilt
            MakePatches
        else
            return
        fi

    else
        CreateDquilt
        PTask=$(whiptail --title "Tasks:" \
        --radiolist "What do you like to do? " 15 60 8 \
          "0" "Display patch files to check or edit them" off \
          "1" "Create additional patch" off \
          "2" "Add another patch to existing patch file" off \
          "3" "Show patch files for deleting" off \
          "4" "Edit debian/patches/series" off \
          "5" "Exit to go on" on --cancel-button "Cancel" 3>&2 2>&1 1>&3)

        if [ $? -eq 1 ]
        then
            PTask=5
        fi

        # Patches treatment
        case "$PTask" in
            0) ChangePatches;; # Edit patches
            1) MakePatches;; # If (more) patches are necessary
            2) FileToPatch # Add patch to patch file
               PatchRunNr=1
               $dquilt refresh;;
            3) DeletePatches;; # Delete patches
               # Edit series
            4) nano --linenumbers --mouse --softwrap debian/patches/series;;
            5) if [ ${PatchRunNr} -eq 1 ]
               then
                   # remove all patches and return the source
                   # to its original state
                   ${dquilt} pop -a
                   PatchRunNr=0
               fi
               # If debian/patches/series is empty,
               # delete directory debian/patches
               if ! [ -s debian/patches/series ]
               then
                   rm debian/patches/series
                   rmdir debian/patches
               fi
               return;;
        esac
    fi

    PatchTasks  
}

function GitBranch2RecentBranch {
    # Called by AskDist

    bName1=$(echo ${CurrentBranch} | sed --expression='s/\//\\\//g')
    sed --in-place --expression="s/RecentBranch=.*/RecentBranch=${bName1}/g" \
    ${ConfigPath}${OrigName}
    RecentBranch=${CurrentBranch}
}

function Search4Dist {
    # Called by AskDist ParseConfig
    set +e
    va=$(grep ${bName}_Dist ${ConfigPath}${OrigName})
    bName1=$(echo ${bName} | sed --expression='s/\//\\\//g')
    va=$(echo $va | sed --expression="s/# ${bName1}_Dist=//g")
    va=$(echo $va | sed --expression='s/"//g')
    set -e
}

function AskDist {
    # Called by BuildNewRevision PrepareUploading LastQuestionsBeforeBuild

    IdentifyBranches
    ba=($bl)
    set +e
    for element in ${ba[*]}
    do
        # rb=$(echo ${element} | grep --count '^x_')
        # if [ $rb -ge 1 ]
        if echo ${element} | grep --quiet '^x_'
        then
            CurrentBranch=$(echo ${element} | sed --expression='s/^x_//')
        fi
    done
    set -e

    if [ -z "${RecentBranch}" ]
    then
        GitBranch2RecentBranch
    else    
        if [ "${RecentBranch}" != "${CurrentBranch}" ]
        then
            Msg="Branch according to git: "${CurrentBranch}",\n \
            branch according to "${ConfigPath}${OrigName}": "${RecentBranch}
            whiptail --title "There is something wrong!" --msgbox "${Msg}" 15 60
            WishedBranch=$(whiptail --title "Choose branch:" \
            --radiolist "Which branch do you want to work with? " \
            --cancel-button "Cancel" 15 60 2 \
            "0" "${RecentBranch}" off \
            "1" "${CurrentBranch}" off 3>&2 2>&1 1>&3)
            if [ ${WishedBranch} -eq 0 ]
            then
                git checkout ${RecentBranch}
            else
                GitBranch2RecentBranch
            fi
        fi
    fi

    echo "Notice from AskDist: The branch is "${RecentBranch} >> ${log}
    set +e
    va=$(grep --count ${RecentBranch}_Dist ${ConfigPath}${OrigName})
    if [ $va -eq 1 ]
    then
        bName=${RecentBranch}
        set -e
        Search4Dist
        RecentBranchD=${va}
    elif [ $va -gt 1 ]
    then
        nano ${ConfigPath}${OrigName}
        AskDist

    else
        set -e
        Distro4Branch
    fi
    set -e

    if [ -z "${RecentBranchD}" ]
    then
        RecentBranchD="sid"
    fi
    echo "Notice from AskDist: The distribution is "${RecentBranchD} >> ${log}
}

function InsertIdentifier {
    # Called by AddVersionNumber Recentidentifier
    RIdentifier=${Version1}
    set +e
    cat debian/source/format | grep "native" > /dev/null
    if [ $? -eq 0 ]
    then
        Version1=$(whiptail --title "Identifier" \
        --inputbox "Recent identifier: ${RIdentifier}\n \
        Please insert the identifier of the package\n \
        (without revision version because it is a native package):" \
        --nocancel 15 60 3>&2 2>&1 1>&3)

    else
        Version1=$(whiptail --title "Identifier" \
        --inputbox "Recent identifier: ${RIdentifier}\n \
        Please insert the whole identifier of the package\n \
        (including revision version):" \
        --nocancel 15 60 3>&2 2>&1 1>&3)
    fi
    set -e
}

function RecentIdentifier {
    # Called by AddVersionNumber ForceOrig
    # Takes version number from debian/changelog, if it exists

    if [ -f ${GitPath}/debian/changelog ]
    then
        set +e
        firstLine=$(grep --line-number 'urgency=' ${GitPath}/debian/changelog | grep '^1:')
        set -e
        whiptail --title "First line:" \
        --msgbox "First line of debian/changelog;\n${firstLine}" 15 60
        recentId=$(echo ${firstLine} | sed --expression='s/^.*(//' | \
        sed --expression='s/).*//')
        whiptail --title "Recent identifier" \
        --msgbox "Recent identifier is ${recentId}" 15 60

        if [ -n "${recentId}" ]
        then
            Version1=${recentId}
        fi
    else
        InsertIdentifier
    fi
}

function AddVersionNumber {
    # Called by DisplayDebianChangelog
    if [ -z "${Version1}" ]
    then
        RecentIdentifier
    fi

    set +e
    revisionflag=$(echo ${Version1} | grep --count '\-[0-9]')
    set -e
    if [ ${revisionflag} -eq 0 ]
    then
        if ! whiptail --title "Identifier of the version:" \
        --defaultno --yesno "${Version1} contains no revision number.\n \
        Is it a native package?" --yes-button "Yes" --no-button "No" 15 60

        then
            InsertIdentifier
            if ! whiptail --title "Identifier of the version:" \
            --defaultno --yesno "Is ${Version1} the right identifier?" \
             --yes-button "Yes" --no-button "No" 15 60

            then
                InsertIdentifier
            fi
        fi
    else
        if ! whiptail --title "Identifier of the version:" \
        --defaultno --yesno "Is ${Version1} the right identifier?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            InsertIdentifier
        fi
    fi
    echo "Message from AddVersionNumber: identifier="${Version1} >> ${log}
}

function DebianJavabuildTemplate {
    # Called by DisplayDebianFiles
    # For building a java package without build system (like maven)
    if [ -f debian/javabuild ]
    then
        if whiptail --title "Creating debian/javabuild?" \
        --defaultno --yesno "Should debian/javabuild be created?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            echo "# NameOfJarFile SourceDirToPackage" >>debian/javabuild
            echo "debian/javabuild was created" >> ${log}
            nano --linenumbers --mouse --softwrap debian/javabuild
        fi
    fi
}

function DisplayDebianChangelog {
    # Called by BuildNewRevision

    newChangelog=0
    if [ -f debian/changelog ]
    then
        less --LINE-NUMBERS debian/changelog
        if ! whiptail --title "Changelog ok?" --defaultno \
        --yesno "Is debian/changelog ok?" --yes-button "Yes" \
        --no-button "No" 15 60
        then
            newChangelog=1
        fi
    else
        newChangelog=1
    fi

    # Check whether d/control exists without a comment in line 1
    if [ ${newChangelog} -eq 1 ]
    then
        if ! [ -f debian/control ]
        then
            DebianControlTemplate
        else
            set +e
            cat --number debian/control | grep '^1 ' | grep '#' > /dev/null
            if [ $? -eq 0 ]
            then
                set -e
                DebianControlTemplate
            fi
            set -e
        fi
        # creating changelog using gbp dch

        AddVersionNumber
        set +e
        SnapshotFlag=$(echo ${Version1} | grep --count '~')
        if [ ${SnapshotFlag} -eq 0 ]
        then
            DchAdd=''
        else
            DchAdd=' --dch-opt=--force-bad-version'
            whiptail --title "Additional option to gbp dch:" \
            --msgbox "Option: ${DchAdd}" 15 60
        fi
        gbp dch --verbose --debian-branch=${RecentBranch} \
        --new-version=${Version1}${DchAdd}
        if [ $? -ne 0 ]
        then
            set -e
            FailureNotice
        fi
        set -e
        nano --linenumbers --mouse --softwrap debian/changelog
    fi
}


function CmeFix {
    # Called by DisplayDebianFiles

    if whiptail --title "Check and fix with cme?" \
    --yesno "Should debian files be checked and fixed using 'cme fix'?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        set +e
        if whiptail --title "Backup?" \
        --yesno "Should the recent files be backuped (recommended)?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            cme fix --verbose --backup dpkg
        else
            cme fix --verbose dpkg
        fi
        set -e
        echo "Please check the result of cme fix!"
        echo "You can check and fix it in another terminal."
        echo "Please press RETURN to go on."
        read a
    fi
}

function DisplayDebianFiles {
    # Called by BuildNewRevision

    # Add Debian files

    # If the Debian files already exists, you can review and improve them now
    # If not, you have to write them

    ## There is default content for Debian files
    ## Change the default values, if you know, what you are doing

    # Loading Webext plugin or Python3 Plugin if needed

    if [ ${WebextFlag} -eq 1 ]
    then
        . build-gbp-webext-plugin
    fi

    if [ ${PythonFlag} -eq 1 ]
    then
        . build-gbp-python-plugin
    fi

    DebianFormatTemplate
    DebianUpstreamMetadataTemplate
    DebianCopyrightTemplate
    DebianControlTemplate
    DebianWatchTemplate
    DebianRulesTemplate
    DebianSalsaCiTemplate

    if [ ${WebextFlag} -eq 1 ] && [ ! -f ${GitPath}/debian/${PackName}.install ]
    then
        WebextInstall
    fi

    nano --linenumbers --mouse \
    --softwrap ${GitPath}/debian/${PackName}.install
    nano --linenumbers --mouse \
    --softwrap ${GitPath}/debian/${PackName}.dirs
    nano --linenumbers --mouse \
    --softwrap ${GitPath}/debian/${PackName}.docs
    if [ ${WebextFlag} -eq 1 ] && [ ! -f ${GitPath}/debian/${PackName}.links ]
    then
        WebextLinksTB
    fi

    nano --linenumbers --mouse \
    --softwrap ${GitPath}/debian/${PackName}.links
    nano --linenumbers --mouse \
    --softwrap ${GitPath}/debian/${PackName}.examples


    if [ ${JavaFlag} -eq 1 ]
    then
        if [ ${MavenPluginFlag} -eq 0 ]
        then
            DebianJavabuildTemplate
        else
            ls debian/ | grep 'maven'
            if [ $? -eq 0 ]
            then
                ShowMaven
            fi
        fi
    fi
    CmeFix
}

function ForceOrig {
    # Called by BuildNewRevision PrepareUploading
    OptFlag=1
    if [ -z "${Version1}" ]
    then
        RecentIdentifier
    fi
    whiptail --title "Version" --msgbox "Version: ${Version1}" 15 60

    set +e
    cat debian/source/format | grep "native" > /dev/null
    if [ $? -ne 0 ]
    then
        RevNr=$(echo ${Version1} | sed --expression='s/[^0-9]/#/g' | \
        sed --expression='s/^.*#//')
        whiptail --title "Revision number" \
        --msgbox "The number of the revision is ${RevNr}." 15 60
        pbuilderOpt=" --git-builder=git-pbuilder \
        --git-pbuilder-options='--source-only-changes'"

        if [ ${RevNr} -gt 1 ]
        then
            if whiptail --title "orig in changes file" \
            --yesno "Do you want to insert the orig archive into the changes file?\n \
            That makes sense, if the orig archive has not been uploaded before." \
            --defaultno --yes-button "Yes" --no-button "No" 15 60
            then
                pbuilderOpt=" --git-builder=git-pbuilder -sa"
            fi
        fi
    else
        pbuilderOpt=" --git-pbuilder"
    fi
    set -e
}

function MoreOptions {
    # Called by UsingPBuilder PrepareUploading
    # Adds options to specify pbuilder in gpb buildpackage
    moreOpts=''
    intText="The options for gbp buildpackage are:\n"
    intText=${intText}${normalOpts}
    if whiptail --title "Options for gbp buildpackage" \
    --yesno "${intText}\nDo you want to add some more?" --yes-button "Yes" \
    --no-button "No" --defaultno 15 60
    then
        moreOpts=$(whiptail --title "Options for gbp buildpackage" \
        --inputbox "${intText}\nPlease insert options to be added:" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        moreOpts=" "${moreOpts}
    fi
}

function PatchesTreatment {
    # Called by BuildNewRevision

    # Patches treatment
    cd ${GitPath}
    if [ ! -d debian/patches ]
    then
        whiptail --title "Info" \
        --msgbox "There is no directory debian/patches" 15 60
    else
        whiptail --title "Info" \
        --msgbox "There is a directory debian/patches" 15 60

        if whiptail --title "Applicability check"'!' \
        --yesno "Do you want to check the applicability of the patches?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            ApplyCheck
        fi
    fi

    PMTask=$(whiptail --title "Tasks:" \
    --radiolist "Do you want to create, edit or delete patches?" 15 60 4 \
    "0" "By using quilt" off \
    "1" "By using gbp pq" off \
    "2" "No" on --cancel-button "Exit" 3>&2 2>&1 1>&3)

    if [ -z "${PMTask}" ]
    then
        exit
    fi

    if [ ${PMTask} -eq 0 ]
    then
        PatchRunNr=0
        set +e
        PatchTasks
        set -e

    elif [ $PMTask -eq 1 ]
    then
        # Message in upper case and red
        echo -e "\n\n\033[31mEVERYTHING MUST BE COMMITTED! \033[0m \n"
        CheckGitStatus
        PQMigration
    fi
}

function LastQuestionsBeforeBuild {
    # Called by UsingSBuild UsingPBuilder

    if ! whiptail --title "Please check!" \
    --yesno "The release you want to build for in ${BuildEnv} is ${RecentBranchD}" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        AskDist
    fi

    whiptail --title "Last opportunity to exit before building" \
    --yesno "Do you want to start the build process?" --yes-button "Yes" \
    --no-button "Exit" 15 60
    if [ $? -ne 0 ]
    then
        whiptail --title "Bye" --msgbox "Exit" 15 60
        exit
    else
        if [ "${BuildEnv}" = "pbuilder" ]
        then
            whiptail --title "Start building" \
            --msgbox "${BuildEnv} will be updated first\n \
            This need sudo and/or root rights" 15 60
        fi
    fi
}

function UsingSBuild {
    # Called by BuildNewRevision

    BuildEnv="sbuild"
    LastQuestionsBeforeBuild

    if whiptail --title ".sbuildrc." \
    --yesno "Do you want to check (and edit) ~/.sbuildrc?" \
    --defaultno --yes-button "Yes" --no-button "No" 15 60
    then
        nano ~/.sbuildrc
    fi

    # Check whether chroot directory exits  

    if ! [ -d  ~/.cache/sbuild ]
    then
        mkdir -p ~/.cache/sbuild
    fi

    # Create/Update tarballed chroot

    if [ $tsf -eq 0 ]
    # Called by TaskSelect via SBuildOrPbuilder 0
    then
        ChrootName='UNRELEASED'
    else
        ChrootName=${RecentBranchD}
    fi

    mmdebstrap --variant=buildd ${RecentBranchD} \
    ~/.cache/sbuild/${ChrootName}-amd64.tar.xz
    
    set +e
    if [ $tsf -eq 0 ]
    # Called by TaskSelect via SBuildOrPbuilder 0
    then
        gbp buildpackage --git-builder=sbuild --no-clean-source \
        --dist=UNRELEASED --build-failed-commands=%SBUILD_SHELL \
        --git-debian-branch=${RecentBranch} \
        --git-dist=${RecentBranchD} --git-ignore-new
        # Setting flag for success
        gbpq=$?
    elif [ $tsf -eq 1 ]
    # Called by PrepareUploading via SBuildOrPBuilder 1
    then
        gbp buildpackage --git-builder=sbuild --no-clean-source \
        --dist=${RecantBranchD} --git-debian-branch=${RecentBranch} \
        --git-dist=${RecentBranchD} --git-verbose --git-tag \
        --git-sign-tags
        # Setting flag for success
        gbpq=$?
    else
        # Called by PrepareUploading via SBuildOrPBuilder 2
        gbp buildpackage --git-builder=sbuild --no-clean-source\
        --dist=${RecentBranchD} --git-debian-branch=${RecentBranch} \
        --git-dist=${RecentBranchD}
        # Setting flag for success
        gbpq=$?
    fi
    set -e
}
 
function UsingPBuilder {
    # Called by BuildNewRevision

    BuildEnv="pbuilder"
    LastQuestionsBeforeBuild

    # Building package using git-pbuilder and gbp buildpackage

    # check, whether cow exists
    # if exists update cow
    # else create cow
    if [ -d /var/cache/pbuilder/base-${RecentBranchD}.cow ]
    then
        echo -e "\nPlease enter Password for updating pbuilder cow.\n"
        DIST=${RecentBranchD} git-pbuilder update
        echo "Notice from BuildNewRevision: Pbuilder was updated." >> ${log}
    elif [ -d /var/cache/pbuilder/base.cow -a ${RecentBranchD} = "sid" ]
    then
        echo -e "\nPlease enter Password for updating pbuilder cow.\n"
        DIST=${RecentBranchD} git-pbuilder update
        echo "Notice from BuildNewRevision: Pbuilder was updated." >> ${log}
    else
        CreateNewCow
    fi
    
    if [ ${OptFlag} -ne 1 ]
    then
        ForceOrig

        if [ $tsf -eq 0 ]
        then
            normalOpts="--git-debian-branch="${RecentBranch}" \
            --git-dist="${RecentBranchD}" --git-verbose \
            --git-ignore-new"${pbuilderOpt}
        elif [ $tsf -eq 1 ]
        then
            normalOpts="--git-debian-branch="${RecentBranch}" \
            --git-dist="${RecentBranchD}" --git-verbose --git-tag \
            --git-sign-tags"${pbuilderOpt}
        else
            normalOpts="--git-debian-branch="${RecentBranch}" \
            --git-dist="${RecentBranchD}" --git-verbose"${pbuilderOpt}
        fi
        MoreOptions
    fi
    echo "== Options for gbp buildpackage ==" >> ${log}
    echo -e "RecentBranch contains ${RecentBranch}" >> ${log}
    echo -e "RecentBranchD contains ${RecentBranchD}" >> ${log}
    echo -e "PBuilderOpt contains ${pbuilderOpt}" >> ${log}
    echo -e "MoreOpts contains ${moreOpt} \n" >> ${log}    
    echo "Starting gbp buildpackage" >> ${log}
    set +e

    if [ $tsf -eq 0 ]
    then
        gbp buildpackage --git-debian-branch=${RecentBranch} \
        --git-dist=${RecentBranchD} --git-verbose \
        --git-ignore-new${pbuilderOpt}${moreOpts}
        # Setting flag for success
        gbpq=$?
    elif [ $tsf -eq 1 ]
    then
        gbp buildpackage --git-debian-branch=${RecentBranch} \
        --git-dist=${RecentBranchD} --git-verbose --git-tag \
        --git-sign-tags${pbuilderOpt}${moreOpts}
        # Setting flag for success
        gbpq=$?
    else
        gbp buildpackage --git-debian-branch=${RecentBranch} \
        --git-dist=${RecentBranchD} --git-verbose${pbuilderOpt}${moreOpts}
        # Setting flag for success
        gbpq=$?
    fi
    set -e
}

function SBuildOrPBuilder {
    # Called by BuildNewRevision TaskSelect PrepareUploading Import4Sponsoring 
    # Flag for tagging and signing
    tsf=$1
    
    Builder=$(whiptail --title "Which builder do you want to use?" \
    --radiolist "Which builder do you want to use? " 15 60 6 \
    "0" "PBuilder" off \
    "1" "SBuild" on \
    --cancel-button "Exit" 3>&2 2>&1 1>&3)
    if [ -z "${Builder}" ]
    then
        exit
    fi
    if [ ${Builder} -eq  1 ]
    then
        echo "Using SBuild." >>${log}
        UsingSBuild
    else
        echo "Using PBuilder." >>${log}
        UsingPBuilder
    fi
}
function BuildNewRevision {
    # Called by TaskSelect
    cd ${GitPath}

    ## Generate directory if necessary
    echo $(pwd) >> ${log}
    if [ -d debian/source ]
    then
        echo "The directory debian/source in ${GitPath} \
        already exists." >> ${log}
        dfe=1
    else
        mkdir --parents debian/source
        echo "Directory debian/source was created" >> ${log}
        dfe=0
    fi

    # Intro
    if ! whiptail --title "New Debian revision" \
    --yesno "A new Debian revision will be built." --yes-button "Yes" \
    --no-button "Exit" 15 60
    then
        exit
    fi

    echo "A new Debian revision will be built." >> ${log}

    # For building java packages with maven

    # To avoid an error, if 'MavenPluginFlag' is empty 
    if [ ! -z ${MavenPluginFlag} ] && [ ${MavenPluginFlag} -eq 1 ]
    then
        . build-gbp-maven-plugin
        if whiptail --title "Maven" \
        --yesno "Should mh_make create the ${PackName}.poms\n \
        file and some maven.* files?\n\n \
        Normally you only need it at the first run" --yes-button "Yes" \
        --no-button "No" --defaultno 15 60
        then
            MakeMaven
        fi
    fi

    # Displaying files in debian/ for editing
    if [ ${dfe} -ne 1 ]
    then
        DisplayDebianFiles
    else
        if whiptail --title "Showing debian files for editing" \
        --yesno "Should the files of debian/ be displayed\n \
        to check, edit or create them?" --yes-button "Yes" \
        --no-button "No" 15 60
        then
            DisplayDebianFiles
        fi
    fi
    dfe=0

    # Patches treatment
    PatchesTreatment

    # Check debian/changelog
    # - includes creating changelog using gbp dch
    DisplayDebianChangelog

    MovingGbpConfFile
    # Preparations for gbp buildpackage
    AskDist # Ensure that RecentBranch has a value
    echo "Notice from BuildNewRevision: Branch is "${RecentBranch} >> ${log}
    whiptail --title "Please check!" \
    --yesno "The git branch is ${RecentBranch}" --yes-button "Yes" \
    --no-button "No" 15 60
    rbq=$?
    if [ $rbq -ne 0 ]
    then
        SelectBranch
    fi
     if ! whiptail --title "Please check!" \
    --yesno "The distribution is ${RecentBranchD}" --yes-button "Yes" \
    --no-button "No" 15 60

    then
        RecentBranchD=""
        Distro4Branch
    fi

    echo "Notice from BuildNewRevision: Distribution is "${RecentBranchD} >> ${log}

    SBuildOrPBuilder 0

    if [ $gbpq -eq 0 ]
    then
        echo -e "The package ${SourceName} was built with gbp buildpackage\n \
        without creating and signing tags." >> ${log}
    else
        whiptail --title "Build failed!" \
        --msgbox "Gbp buildpackage failed!" 15 60
        echo
        echo "-- Gbp buildpackage failed! --"
        echo
        echo "Please fix the problem in another terminal!"
        echo "After fixing, press RETURN to continue."
        read a
        if [ "${BuildEnv}" = "sbuild" ]
        then
            UsingSBuild
        else
            UsingPBuilder
        fi        
    fi

    Task=5 # Go to RunningTests
}

function RunningLintian {
    # Called by RunningTests

    SelectChangesFile "lintian_check" # String will be found in ${1}
    linfile=${changesa[$paket]}

    set +e
    lininfo=$(lintian --check --display-experimental --display-info \
    --info --verbose --show-overrides --pedantic --tag-display-limit 0 \
    --color auto ${linfile})
    lx=$?


    if [ ${lx} -eq 0 ]
    then
        lininfo="Lintian does not find any Errors \
        \n\n Congratulations \n\n"${lininfo}
    fi

    # Make lininfo better readable
    lininfo=$(echo ${lininfo} | sed --expression='s/ [EWIPNX]:/\\n&/g')

    set -e
    echo -e "lintian("${lx}"): "${lininfo}
    whiptail --title "Lintian" --msgbox "${lininfo}" --scrolltext 15 60
    echo -e "Result of Lintian:\n"${lininfo} >> ${log}
        
    whiptail --title "All well?" \
    --yesno "All well? Continue?" --yes-button "Yes" \
    --no-button "Exit" 15 60
    linq=$?
}

function RunningUscan {
    # Called by RunningTests BuildWithUscan

    cd ${GitPath}

    # Check whether debian/watch exists
    if [ ! -e debian/watch ]
    then
        whiptail --title "No debian/watch file found" \
        --yesno "Is there a good reason for having no debian/watch file?" \
        --defaultno --yes-button "Yes" --no-button "No" 15 60
        if [ $? -eq 0 ]
        then
            usq=0
        else
            usq=1
        fi
        return
    fi

    set +e
    uscaninfo=$(uscan --no-download --verbose)
    if [ ${#uscaninfo} -gt 0 ]
    then
        whiptail --title "uscan" --msgbox "${uscaninfo}" --scrolltext 15 60
        echo -e "Result of uscan:\n"${uscaninfo} >> ${log}
        echo ${uscaninfo} | grep '=> Package is up to date' > /dev/null
        usc1=$?
        echo ${uscaninfo} | grep '=> Only older package available' > /dev/null
        usc2=$?
        if [ ${usc1} -eq 0 ]
        then 
            whiptail --title "uscan" --msgbox "Package seems to be up to date." 15 60
            usq=0
        elif [ ${usc2} -eq 0 ]
        then
            whiptail --title "uscan" --msgbox "Only older package available." 15 60
            usq=0
        else
            whiptail --title "No up to date message" \
            --yesno "No up to date message.\nRegardless all well? Continue?" \
            --defaultno --yes-button "Yes" --no-button "Exit" 15 60
            usq=$?
        fi
    else
        echo "uscan failed" >> ${log}
        whiptail --title "uscan failed" --msgbox "uscan failed" 15 60
        usq=1
    fi
    set -e
}

function RunningTests {
    # Called by TaskSelect BuildNewRevision

    # QA using lintian and uscan

    # lintian
    RunningLintian
    # uscan
    if [ $linq -eq 0 ]
    then
        RunningUscan
    else
        usq=1
    fi

    if [ $usq -ne 0 ] || [ $linq -ne 0 ]
    then
        echo "At least one test failed!" >> ${log}
        exit
    else
        if whiptail --title "Upload?" \
        --yesno "Should the package be prepared to be uploaded now?" \
        --yes-button "Yes" --no-button "Exit" 15 60
        then
            Task=6 # Go to PrepareUploading
        else
            exit
        fi
    fi
}

function CheckRepackSuffix {
    # Called by BuildWithUscan
    if [ -n "${RecentRepackSuffix}" ]
    then
        if ! cat ${GitPath}/debian/watch | grep "repacksuffix=" > /dev/null
        then
            whiptail --title "debian/watch!" \
            --msgbox "No repacksuffix in debian/watch." 15 60
            nano --linenumbers --mouse --softwrap ${GitPath}/debian/watch
        fi
    fi
}

function BuildWithUscan {
    # Called by ClassicalOrUscan

    cd ${GitPath}

    echo "Try gbp import-orig --uscan" >> ${log}
    set +e
    uscaninfo=$(uscan --no-download --verbose)
    if [ ${#uscaninfo} -gt 0 ]
    then
        SearchGbpConf
        whiptail --title "uscan" --msgbox "${uscaninfo}" \
        --scrolltext 15 60
        echo -e "Result of uscan:\n"${uscaninfo} >> ${log}
        set +e
        echo ${uscaninfo} | grep '=> Package is up to date' > /dev/null
        if [ $? -eq 0 ]
        then 
            whiptail --title "uscan" \
            --msgbox "Package seems to be up to date.\n \
            Nothing to do!" 15 60
            echo "Package seems to be up to date. Nothing to do!" \
            >> ${log}
        fi
        echo ${uscaninfo} | grep '=> Newer package available from' \
        > /dev/null
        if [ $? -eq 0 ]
        then
            if ! whiptail --title "Newer package available" \
            --yesno "All well? Continue?" --yes-button "Yes" \
            --no-button "Exit" 15 60
            then
                exit
            fi
            set -e
            CheckRepackSuffix
            set +e
            Version1=$(uscan --no-download --verbose | \
            grep newversion | sed --expression 's/    $newversion  = //')
            set -e
            CheckGitStatus
            GpgKeyAvailable
            CheckTags
            set +e
            # Downloads with uscan and imports with gbp import-orig
            gbp import-orig --uscan --verbose \
            --debian-branch=${RecentBranch} --sign-tags ${OrigFile}
            if [ $? -ne 0 ]
            then
                echo "Import with gbp import-orig --uscan failed!" \
                >> ${log}
                exit
            fi
            echo "Imported with gbp import-orig --uscan" >> ${log}
        else
            exit
        fi
        set -e
    else
        whiptail --title "Uscan failed!" \
        --msgbox "Please check the watch file with uscan." 15 60
        echo "Uscan failed! Please check the watch file with uscan." >> ${log}
        exit
    fi

    Task=3 # Go to BuildNewRevision
}

function PrepareUploading {
    # Called by TaskSelect

    cd ${GitPath}
    
    # Check debian/changelog
    if [ -f debian/changelog ]
    then
        less --LINE-NUMBERS debian/changelog
    else
        whiptail --title "This is the end" \
        --msgbox "No changelog - no upload!" 15 60
        exit
    fi

    if ! whiptail --title "Changelog fit for publishing?" --defaultno \
    --yesno "Is the changelog fit for publishing?" --yes-button "Yes" \
    --no-button "No" 15 60
    then
        AskDist
        echo -e "Notice from PrepareUploading: The branch is "${RecentBranch}"\n \
        The distribution is "${RecentBranchD} >> ${log}
        whiptail --title "Please check! (U)" \
        --msgbox "The branch is ${RecentBranch}" 15 60
        
        if [ "${RecentBranchD}" = "sid" ]
        then
            distName="unstable"
        elif [ "${RecentBranchD}" = "experimental" ]
        then
            distName="experimental"
        else
            distName=$(whiptail --title "Name of the distribution" \
            --inputbox "Please insert the name of the distribution\n \
            specified in the changelog" \
            --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        fi
        if [ -z "${distName}" ]
        then
            distName="unstable"
        fi
        
        echo -e "Another notice from PrepareUploading:\n \
        The distribution is now "${distName} >> ${log}
        whiptail --title "Please check! (U)" \
        --msgbox "The distribution is ${distName}" 15 60

        # making debian/changelog fit for publishing
        gbp dch --release --verbose --debian-branch=${RecentBranch} \
        --distribution=${distName} #--commit
        git add .
        git commit -a

        whiptail --title "Build again" \
        --msgbox "Now the release will be built another time." 15 60

        # Building revision
        GpgKeyAvailable
        SBuildOrPBuilder 1
        if [ $gbpq -eq 0 ]
        then
            echo "Package ${SourceName} was built using gbp buildpackage." >> ${log}
        fi
    else
        if whiptail --title "Building another time?" \
        --yesno "Should the release be built another time?\n(Without tagging)" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            # Building revision
            SBuildOrPBuilder 2
            if [ $gbpq -eq 0 ]
            then
                echo "Package ${SourceName} was built using gbp buildpackage." >> ${log}
            fi
        fi
    fi
}

function SelectUploadTarget {
    # Called by TaskSelect Upload2FtpMaster

    # Select upload target
    Upl=$(whiptail --title "Uploading?" \
    --radiolist "Should the package be uploaded to ftp-master,\n \
    people.d.o or mentors.debian.net?" 15 60 6\
      "0" "No" off \
      "1" "ftp-master" on \
      "2" "people.d.o" off \
      "3" "Mentors" off \
      "4" "Non-Maintainer-Upload" off \
      "5" "Local repository" off --cancel-button "Exit" 3>&2 2>&1 1>&3)

    # The order of the conditions is important!
    # 'Cancel' results an empty variable
    if [ -z ${Upl} ] || [ ${Upl} -eq 0 ]
    then
        exit
    fi

    case "${Upl}" in
     1) Upltext="ftp-master";;
     2) Upltext="people.d.o";;
     3) Upltext="Mentors";;
     4) Upltext="delayed";;
     5) Upltext="local repository";;
    esac


    cd ${PrjPath}

    # Select package
    SelectChangesFile "Upload" # String will be found in ${1}
    UplPaket=${changesa[$paket]}

    # Version2=$(echo ${UplPaket} | sed --expression="s/^[a-z\-]*_//" | \
    # sed --expression="s/-.*$//")
    # SourceName1=$(echo ${UplPaket} | sed --expression="s/_.*//1")
    # OrigPaket=${SourceName1}"_"${Version2}".orig"

    # Final question before uploading starts
    if [ ${Upl} -ne 4 ]
    then
        if ! whiptail --title "Upload to ${Upltext}?" \
        --yesno "Do you want to upload ${UplPaket} to ${Upltext}." \
        --yes-button "Yes" --no-button "Exit" 15 60
        then
            whiptail --title "Bye" --msgbox "Bye" 15 60
            exit
        fi
    fi

    echo "${UplPaket} should be uploaded to ${Upltext}." >> ${log}
}

function Upload2OwnServer {
    # Called by TaskSelect

    # Uploading to own git server
    if [ -n "$ServerName" ]
    then
        if whiptail --title "Upload to own git server?" \
        --yesno "Should ${SourceName} be uploaded to your own git server?" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            git push --set-upstream home --all >> ${log}
            git push --set-upstream home --tags >> ${log}

            echo ${SourceName}" was uploaded to your git server." >> ${log}
        fi
    fi
}

function Upload2Salsa {
    # Called by TaskSelect and itself

    # Uploading to Salsa

    if whiptail --title "Upload to salsa.debian.org?" \
    --yesno "Should ${SourceName} be uploaded to Salsa?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        BrowserName=$(echo ${SalsaName} | sed --expression='s/.git$//g')
        BrowserName="https://salsa.debian.org/"${BrowserName}
        wget --spider --verbose --max-redirect=0 \
        --append-output=${log} ${BrowserName}
        if [ $? -ne 0 ]
        then
             whiptail --title "No project found at salsa.debian.org" \
            --msgbox "Please create ${BrowserName} first" 15 60
            echo "No project "${BrowserName}" found at salsa.debian.org" \
            >> ${log}

            if whiptail --title "Done?" \
            --yesno "Created ${BrowserName} on salsa.debian.org?" \
            --yes-button "Yes" --no-button "No" 15 60
            then
                Upload2Salsa
            else
                exit
            fi
        else
            set +e
            if echo $(git branch) | grep --quiet 'patch-queue/'
            then
                if whiptail --title "Patch queue branches found:" \
                --yesno "$(git branch | grep 'patch-queue')\n \
                Delete all patch-queue branches?" \
                --yes-button "Yes" --no-button "No" 15 60
                then
                    git branch --delete --force \
                    $(git branch | grep 'patch-queue')
                fi
            fi
            set -e

            if ! whiptail --title "Last stop before upload!" \
            --yesno "Anything all right?" \
            --yes-button "Yes" --no-button "No" 15 60
            then
                exit
            fi
            set +e
            if git remote | grep 'salsa' > /dev/null
            then
                RepoName="salsa"
            else
                RepoA=($(git remote))

                i=0; slct=''
                for element in ${RepoA[*]}
                do
                    slct=$slct' '$i' '${element}' off '
                    i=$(expr $i + 1)
                done

                RepoNr=$(whiptail --title "Select repository" \
                --radiolist "Select one of these repositories" \
                --cancel-button "Exit" 15 60 8 \
                $slct 3>&2 2>&1 1>&3)

                if [ -z "${RepoNr}" ]
                then
                    exit
                else
                    RepoName=${RepoA[${RepoNr}]}
                fi
            fi

            git push --set-upstream ${RepoName} --all >> ${log}
            git push --set-upstream ${RepoName} --tags >> ${log}
            set -e

            echo ${SourceName}" was uploaded to salsa.debian.org." >> ${log}
        fi
    fi
}

function GettingFingerprint {
    # Called by GpgKeyAvailable

    finchflag=0

    # getting the fingerprint of the key to sign
    if [ -f ${ConfigPath}/fingerprint ]
    then
        . ${ConfigPath}/fingerprint
    else
        mkdir --parents ${ConfigPath}
        finchflag=1
    fi

    if [ -z "${fipr}" ]
    then
        fipr=$(whiptail --title "Your fingerprint" \
        --inputbox "Please insert fingerprint of your key for signing!" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        if [ -z "${fipr}" ]
        then
            echo "Please insert fingerprint of your key for signing!"
            read fipr
        fi
        finchflag=1
    fi

    if ! whiptail --title "Fingerprint" \
    --yesno "Is ${fipr} the right fingerprint of the key for signing?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        fipr=$(whiptail --title "Key for signing" \
        --inputbox "Real fingerprint of the key for signing:" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
        if [ -z "${fipr}" ]
        then
            echo "Please insert fingerprint of your key for signing!"
            read fipr
        fi
        finchflag=1
    fi

    if [ $finchflag -eq 1 ]
    then
        if [ -f ${ConfigPath}/fingerprint ]
        then
            mv ${ConfigPath}/fingerprint ${ConfigPath}/fingerprint.backup
            whiptail --title "Fingerprint file" \
            --msgbox "You can find the old fingerprint file as\n \
            ${ConfigPath}/fingerprint.backup" 15 60
        fi
        touch ${ConfigPath}/fingerprint
        echo "#!/usr/bin/bash" >> ${ConfigPath}/fingerprint
        echo "fipr="${fipr} >> ${ConfigPath}/fingerprint
        . ${ConfigPath}/fingerprint
    fi
}

function CreateSignature {
    # Called by TaskSelect Upload2FtpMaster and itself

    # Key available?
    GpgKeyAvailable

    # Signature using debsign
    set +e
    debsign -k${fipr} ${UplPaket}
    if [ $? -ne 0 ]
    then
        if whiptail --title "Signing failed!" \
        --yesno "Signature failed - Retry?" \
        --yes-button "Yes" --no-button "Exit" 15 60
        then
            CreateSignature
        else
            exit
        fi
    fi
        set -e
    echo "${UplPaket} was signed" >> ${log}
}

function Upload2Mentors {
    # Called by UploadUsingDput

    if whiptail --title "Simulate uploading?" \
    --yesno "Should the upload to Mentors be simulated?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        dput --simulate mentors ${UplPaket}
        echo
        echo "After reading press RETURN!"
        read x
    fi

    # repeat question 
    if whiptail --title "Uploading?" \
    --yesno "Should the package be uploaded to Mentors?" \
    --yes-button "Yes" --no-button "No" 15 60
    then
        dput mentors ${UplPaket}
        echo "${UplPaket} was uploade to ${Upltext}." >> ${log}
    fi
}

function Dput2NMU {
    # Called by Dput2FtpMaster

    DelayDays=$(whiptail --title "Non-Maintainer-Upload" \
    --radiolist "Days for delay?" 15 60 5 \
    "0" " 5 days of delay" off \
    "1" "10 days of delay" on \
    "2" "15 days of delay" off --cancel-button "Exit" 3>&2 2>&1 1>&3)

    if [ -z ${DelayDays} ]
    then
        exit
    fi
    
    case "${DelayDays}" in
        0) DelDays=5;;
        1) DelDays=10;;
        2) DelDays=15;;
    esac
    
    dput --delayed ${DelDays} ftp-master ${UplPaket}
}

function Dput2FtpMaster {
    # Called by Upload2FtpMaster

    if whiptail --title "Simulate uploading?" \
    --yesno "Should the upload to ftp-master be simulated?" \
    --yes-button "Yes" --no-button "No" 15 60

    then
        dput --simulate ftp-master ${UplPaket}
        echo
        echo "After reading press RETURN!"
        read x
    fi

    if whiptail --title "Uploading to FTP-Master?" \
    --yesno "Everything fine?\n\n \
    Should the package be uploaded to ftp-master now?" \
    --yes-button "Yes" --no-button "No" 15 60

    then
        if [ ${Upl} -eq 1 ]
        then
            dput ftp-master ${UplPaket}
            echo "${UplPaket} was uploaded to ${Upltext}." >> ${log}
        else
            Dput2NMU
        fi
    fi
}

function Upload2FtpMaster {
    # Called by UploadUsingDput

    # repeat question
    if whiptail --title "Last exit" \
    --yesno "Should the package be uploaded to ftp-master?" \
    --yes-button "Yes" --no-button "Exit" 15 60
    then
        set +e
        # Checking whether the .changes file is the right one for the upload target
        sourceFlag=$(echo ${UplPaket} | grep --count '_source.')
        expFlag=$(grep --line-number ') experimental; urgency=' ${GitPath}/debian/changelog \
        | grep '^1:')
        set -e
        echo -e "${UplPaket}:\n${expFlag}\nsourceFlag: ${sourceFlag}" >> ${log}
        # Strip line to isolate release
        expFlag=$(echo ${expFlag} | sed --expression='s/^.*) //' | \
        sed --expression='s/; .*$//')

        if [ -z "${expFlag}" ]
        then
            if [ ${sourceFlag} -eq 0 ]
            then
                if whiptail --title "Uploading?" \
                --yesno "Do you really want to upload a binary package\n \
                to ftp-master?" --yes-button "Yes" --no-button "No" 15 60
                
                then
                    Dput2FtpMaster
                else
                    echo "Next try to upload"  >> ${log}
                    SelectUploadTarget
                fi
            else
                Dput2FtpMaster
            fi
        else
            if [ $sourceFlag -ge 1 ]
            then
                if whiptail --title "Uploading?" \
                --yesno "Do you really want to upload a source package\n \
                to experimental?" --yes-button "Yes" --no-button "No" 15 60


                then
                    Dput2FtpMaster
                else
                    echo "Next try to upload"  >> ${log}
                    SelectUploadTarget
                    CreateSignature
                    UploadUsingDput
                fi
            else
                Dput2FtpMaster
            fi
        fi
    fi
}

function UploadUsingDput {
    # Called by TaskSelect Upload2FtpMaster

    # Uploading using dput

    cd ${PrjPath}/
    if [ ${Upl} -eq 3 ]
    then
        Upload2Mentors
    elif [ ${Upl} -eq 1 ] || [ ${Upl} -eq 4 ]
    then
        Upload2FtpMaster
    fi
}

function UploadFilesSelect {
    # Called by Upload2PeopleDO UploadLocal

    set +e
    UplFL=$(cat ${UplPaket} | grep --after-context=10 'Files: *')
    UplFL1=$(echo ${UplFL} | sed --expression='s/Files: //')
    i=1
    while [ $i -lt 6 ]
    do
        c=$(expr ${i} \* 5)
        UplFL2=${UplFL2}" "$(echo $UplFL1 | cut --delimiter=" " -f${c})
        i=$(expr ${i} + 1)
    done
    set -e
}

function Upload2PeopleDO {
    # Called by TaskSelect

    if [ ${Upl} -eq 2 ]
    then
        # For people.d.o you can not use dput
        if whiptail --title "Archive on people.d.o" \
        --yesno "Does the directory public_html/${OrigName} \
        already exsist at people.d.o?\n \
        If not you have to enter the following commands\n \
        in a separate terminal:\n\n \
        ssh <user>@people.debian.org\n \
        mkdir --parents public_html/${OrigName}" \
        --yes-button "Yes" --no-button "No" 15 60
        then
            UploadFilesSelect
            if whiptail --title "Upload file?" \
            --yesno "Should the following files\n${UplFL2}\n \
            have to be uploaded?" --yes-button "Yes" \
            --no-button "No" 15 60
            then
                if [ -z "${pdoaccount}" ]
                then
                    pdoaccount=$(whiptail --title "Account at people.debian.org" \
                    --inputbox "Please insert the name of your account on\n \
                     people.debian.org" \
                     --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
                    if [ -z "${pdoaccount}" ]
                    then
                        echo "Please insert the name of your account on\n \
                        people.debian.org"
                        read pdoaccount
                    fi
                    changeflag=1
                fi

                if ! whiptail --title "Account name" \
                --yesno "The name of your account on people.debian.org:\n \
                ${pdoaccount}" --yes-button "Yes" --no-button "No" 15 60
                then
                    pdoaccount=$(whiptail --title " Account name" \
                    --inputbox "Name of your account on people.debian.org:" \
                    --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
                    if [ -z "${pdoaccount}" ]
                    then
                        echo "Please insert the name of your account on\n \
                        people.debian.org"
                        read pdoaccount
                    fi
                    changeflag=1
                fi

                if [ $changeflag -eq 1 ]
                then
                    echo 'pdoaccount='${pdoaccount} >> ${ConfigPath}${OrigName}
                    changeflag=0
                fi

                cd ${ProjectPath}/${OrigName}
                if scp -p ${UplFL2} \
                ${pdoaccount}@people.debian.org:/home/${pdoaccount}/public_html/${OrigName}
                then
                    echo "${UplFL2} were uploaded to p.d.o." >> ${log}
                else
                    echo "Something went wrong while uploading to p.d.o." >> ${log}
                    echo "Tried to execute this command:" >> ${log}
                    echo  "scp -p "${UplFL2}" "${pdoaccount}"@people.debian.org:/home/"\
                    ${pdoaccount}"/public_html/"${OrigName} >> ${log}
                fi
                pdoarchivetext="If the archive on people.d.o should be\n \
                used too, you have to enter the following commands:\n \
                ssh <user>@people.debian.org\n \
                cd public_html/${OrigName}\n \
                apt-ftparchive packages . > Packages\n \
                apt-ftparchive sources . > Sources\n \
                cat Packages | gzip -c > Packages.gz\n \
                cat Sources | gzip -c > Sources.gz\n \
                apt-ftparchive release . > Release"

                if whiptail --title "Archive on people.d.o" \
                --yesno "${pdoarchivetext}\n\n \
                Do you like to copy and paste these commands?" \
                --yes-button "Yes" --no-button "No" 15 60
                then
                    echo -e $pdoarchivetext
                    echo -e "\nPlease press any key to continue!"
                    read x
                fi
            fi
        fi
    fi
}

function UpdateLocalRepo {
    # Called by UploadLocal
    cd /var/local/repository

    # Make package archives writable
    # (not only for root)
    sudo chmod o+w Packages
    sudo chmod o+w Sources
    sudo chmod o+w Packages.gz
    sudo chmod o+w Sources.gz
    sudo chmod o+w Release

    # Use apt-ftparchive to update package archives
    sudo apt-ftparchive packages . > Packages &&
    sudo apt-ftparchive sources . > Sources &&
    sudo cat Packages | gzip -c > Packages.gz &&
    sudo cat Sources | gzip -c > Sources.gz &&
    sudo apt-ftparchive release . > Release

    # Reset rights
    sudo chmod o-w Packages
    sudo chmod o-w Sources
    sudo chmod o-w Packages.gz
    sudo chmod o-w Sources.gz
    sudo chmod o-w Release
}

function UploadLocal {
    # Called by TaskSelect
    if [ ${Upl} -eq 5 ]
    then
        # Provide for local chroot
        UploadFilesSelect
        if whiptail --title " Files Uploaded?" \
        --yesno "Should the following files\n \
        ${UplFL2}\nhave to be uploaded?" 15 60
        then
            cd ${ProjectPath}/${OrigName}
            sudo cp ${UplFL2} /var/local/repository
            UpdateLocalRepo
        fi
    fi
}

function ChangeEntry {
    # Called by CreateNewBranch SelectBranch
    set +e
    RecentBranchEntry=$(grep --count 'RecentBranch=' ${ConfigPath}${OrigName})
    set -e

    ## Change RecentBranch entry in config file
    if [ ${RecentBranchEntry} -eq 0 ]
    then
        echo "RecentBranch="${bName} >> ${ConfigPath}${OrigName}
    else
        # ReplaceConfigLines needs two parameters:
        # name of the variable and new value
        ReplaceConfigLines 'RecentBranch' ${bName}
        # bName1=$(echo ${bName} | sed --expression='s/\//\\\//g')
        # sed --in-place --expression=\
        # "s/RecentBranch=.*/RecentBranch=${bName1}/g" \
        # ${ConfigPath}${OrigName}
    fi
    less --LINE-NUMBERS ${ConfigPath}${OrigName}

    ## Set variable
    RecentBranch=${bName}
    echo "Notice from ChangeEntry: The branch is "${RecentBranch} >> ${log}

}

function DebianBranches {
    # Called by CreateNewBranch SelectBranch
    # selects the Debian branches
    IdentifyBranches

    ## Trim branchlist
    bl=$(echo $bl | sed 's/pristine-tar/  /')
    bl=$(echo $bl | sed 's/upstream/  /')
    bl=$(echo $bl | sed 's/HEAD/  /')
    # bl=$(echo $bl | sed 's/remotes\/origin\/.*/  /g')
    # bl=$(echo $bl | sed 's/remotes\/salsa\/.*/  /g')
    # bl=$(echo $bl | sed 's/remotes\/home\/.*/  /g')
    bl=$(echo $bl | sed 's/remotes\/.*/  /g')
}

function CreateNewBranch {
    # Called by TaskSelect

    # Creates a new branch (for backports or proposed-updates)
    DebianBranches
    whiptail --title "Recent branches" \
    --msgbox "Recent branches:\n${bl}" 15 60
    bName=""
    bName=$(whiptail --inputbox "Name of the new branch:" \
    --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
    if [ ${bName} != "" ]
    then
        ## Create new branch in git
        git checkout -b ${bName}

        ## Change config file - make new branch to recent one
        ChangeEntry

        whiptail --title "New branch was created" \
        --msgbox "New branch ${bName} was created" 15 60
        echo "New branch ${bName} was created" >> ${log}
        Distro4Branch
    fi
}

function ParseConfig {
    # Called by SelectBranch TaskSelect

    # Parse config file for Debian distribution of branch 
    set +e
    vc=$(grep --count ${bName}_Dist ${ConfigPath}${OrigName})
    set -e
    if [ $vc -ge 1 ]
    then
        Search4Dist
    else
        va="sid"
    fi
    RecentBranchD=${va}
    echo "Notice from ParseConfig: The distribution is "${RecentBranchD} >> ${log}

}

function SelectBranch {
    # Called by BuildApp TaskSelect BuildNewRevision

    CheckGitStatus
    DebianBranches
    ## Create a radiolist with the branch names
    ba=($bl)
    i=1; slct=''
    set +e
    for element in ${ba[*]}
    do
        echo ${element} | grep 'x_' > /dev/null
        if [ $? -eq 0 ]
        then
            if [ "${element}" = "x_" ]
            then
                continue
            else
                ostr="on"
            fi
        else
            ostr="off"
        fi
        slct=${slct}' '"$i"' '"${element}"' '${ostr}' '
        i=$(expr $i + 1)
    done
    set -e

    if [ ${#ba[@]} -gt 1 ]
    then
        ## select branch
        branch=$(whiptail --title "Branch" --radiolist "Select:" \
        15 60 8 ${slct} --cancel-button "Task selection" 3>&2 2>&1 1>&3)
        if [ ! -z "${branch}" ]
        then
            set +e
            branch=$(expr ${branch} - 1)
            set -e
            bName=${ba[$branch]}
            bName=$(echo ${bName} | sed --expression='s/^x_//')
            ## checkout branch
            git checkout ${bName}
            ## Change config file - 
            ## make selected branch to recent one
            ChangeEntry
            whiptail --title "This branch was selected" \
            --msgbox "${bName} was selected" 15 60
            echo "${bName} was selected" >> ${log}
            ParseConfig
        fi
    elif [ ${#ba[@]} -eq 1 ]
    then
        whiptail --title "Only one branch" \
        --msgbox "There is only one Debian branch: ${ba[0]}" 15 60
    else
        whiptail --title "There is no branch" \
        --msgbox "There is no branch created.\nPlease build a new version." 15 60
    fi
}

function AddGitServer {
    # Called by OwnServer 
    serverlist=$(git remote -v)
    if whiptail --title "Recent remote servers" \
    --yesno "${serverlist}\nAdd git remote server 'home'?" \
    --yes-button "Yes" \
    --no-button "No" 15 60
    then
        AddHomeServer
    fi
}

function OwnServer {
    # Called by TaskSelect

    # Set name or IP of own git server
    ServerName=$(whiptail --inputbox "Name or IP-address of your git server:" \
    --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)
    if [ -z "${ServerName}" ]
    then
        echo "Name or IP of your git server:"
        read ServerName
    fi
    if [ -n "$ServerName" ]
    then
        # ReplaceConfigLines needs two parameters:
        # name of the variable and new value
        ReplaceConfigLines 'ServerName' ${ServerName}
        AddGitServer
    fi
}

function Ask4DebDiff {
    # Called by TaskSelect

    # Check whether branch is sid
    if [ ${RecentBranch} == "debian/sid" ] || [ ${RecentBranch} == "master" ] || \
       [ ${RecentBranch} == "main" ]
    then
        return
    fi

    # Creating a Debdiff?
    if whiptail --title "DebDiff needed?" \
        --yesno "Do you want to create a debdiff?" \
        --yes-button "Yes" --no-button "No" 15 60
    then
        DebDiff 1
    fi
}

function TaskSelect {
    # Called by StartTasks CommonTasks

    ## The lines below serve also the sequence control. A called function
    ## changes finally the variable 'Task', so one of the following 
    ## if-clauses matches. That is why the following lines can not be 
    ## replaced by a case statement.

    NoPull=0 # Flag for PullFromSalsa

    ## Start tasks

    # Building a new package from archive
    if [ $Task -eq 0 ]
    then
        BuildNewPackage
    fi

    # Clone an existing repo from Salsa
    if [ $Task -eq 11 ]
    then
        CloneFromSalsa
    fi

    # Importing already existing Debian package
    if [ $Task -eq 12 ]
    then
        ImportDebianPackage
    fi
    # Importing from mentors.debian.net for sponsoring
    if [ $Task -eq 13 ]
    then
        Import4Sponsoring
    fi


    ## Common tasks
    rcts=0 # ReCall TaskSelect flag

    # Building a new version
    if [ $Task -eq 2 ]
    then
        if [ ${NoPull} -eq 0 ]
        then
            PullFromSalsa
        fi
    ClassicalOrUscan # and then download new version
    fi

    # Building a new revision
    if [ $Task -eq 3 ]
    then
        BuildNewRevision
    fi

    # Rebuilding a revision
    if [ $Task -eq 4 ]
    then
        ParseConfig
        AskDist
        SBuildOrPBuilder 0
        Task=5 # Running Tests
    fi

    # Running lintian and uscan
    if [ $Task -eq 5 ]
    then
        RunningTests
    fi
    # Uploading the package
    if [ $Task -eq 6 ]
    then
        PrepareUploading
    fi

    # Create new branch
    # (e.g. for backports or proposed-updates)
    if [ $Task -eq 7 ]
    then
        CreateNewBranch
        rcts=1
    fi
    
    # Select branch
    if [ $Task -eq 8 ]
    then
        SelectBranch
        rcts=1
    fi

    # Set name or IP of own git server
    if [ $Task -eq 9 ]
    then
        OwnServer
        rcts=1
    fi

    # Create a debdiff
    if [ $Task -eq 10 ]
    then
        DebDiff 0
        rcts=1
    fi

    if [ ${rcts} -eq 0 ]
    then
        Ask4DebDiff
        ##############

        # Pushing git repo
    
        ##############

        Upload2OwnServer
        Upload2Salsa

        ##############

        # Uploading packages

        ##############

        SelectUploadTarget
        CreateSignature
        UploadUsingDput
        Upload2PeopleDO
        UploadLocal
    else
        ConfigFileLEC
        CommonTasks
    fi
}

function StartTasks {
    # Called by BuildApp

    Task=$(whiptail --title "Tasks for building a new package:" \
    --radiolist "What do you like to do to build a new package? " 17 60 9 \
      "0" "Create a git repo and download upstream code" on \
      "11" "Clone an existing repo from Salsa" off \
      "12" "Importing already existing Debian packages" off \
      "13" "Importing from mentors.debian.net for sponsoring" off \
    --cancel-button "Exit" 3>&2 2>&1 1>&3)


    if [ -z "${Task}" ]
    then
        exit
    fi
    TaskSelect
}

function DebDiffCheckList {
    # Called by DebDiff

    PackageNrL=$(whiptail --title "debdiff" \
    --checklist "Which two versions should be compared?" \
    15 60 8 \
    ${packageE} --cancel-button "Cancel" 3>&2 2>&1 1>&3)

    PackageNrA=(${PackageNrL})
}

function DebDiff {
    # Called by TaskSelect Ask4DebDiff
    debdiffFlag=$1

    if [ ${debdiffFlag} -gt 0 ]
    then
        whiptail --title "debdiff" \
        --msgbox "Now you can detect the differences between two Debian packages.\n" \
        15 60
    fi

    cd ${PrjPath}
    set +e
    PackageList=$(ls ${PrjPath} | grep \.dsc$ | sort --reverse --version-sort)
    set -e
    PackageArray=(${PackageList})

    i=0
    for element in ${PackageArray[*]}
    do
        packageE=${packageE}' '$i' '${element}' off '
        i=$(expr $i + 1)
    done

    DebDiffCheckList
    
    if [ ${#PackageNrA[@]} -gt 2 ]
    then
        whiptail --title "Too much selections" \
        --msgbox "Please select only two versions" 15 60
        DebDiffCheckList

    elif [ ${#PackageNrA[@]} -lt 2 ]
    then
        whiptail --title "Less selections" \
        --msgbox "Please select two versions" 15 60
        DebDiffCheckList
    fi

    if [ -z "${PackageNrL}" ]
    then
        cd ${GitPath}
        CommonTasks
    fi

    if whiptail --title "Reverse order?" \
        --yesno "Should the order of the packages be reversed?" \
        --yes-button "Yes" --no-button "No" --defaultno 15 60
    then
        sn=${PackageNrA[1]}
        fn=${PackageNrA[0]}
    else
        fn=${PackageNrA[1]}
        sn=${PackageNrA[0]}
    fi


    # Killing toxic quotationmarks
    fn=$(echo $fn | sed --expression="s/\"//g")
    sn=$(echo $sn | sed --expression="s/\"//g")

    echo -e "Compare with debdiff: \n" \
    ${PackageArray[fn]}" and "${PackageArray[sn]}"\n" >> \
    ${log}
    echo -e "The result can be found in\n" \
    debdiff_${PackageArray[fn]}-${PackageArray[sn]}.diff >> ${log}
    set +e
    debdiff --diffstat ${PackageArray[fn]} ${PackageArray[sn]} > \
    debdiff_${PackageArray[fn]}-${PackageArray[sn]}.diff
    set -e
    less debdiff_${PackageArray[fn]}-${PackageArray[sn]}.diff

    if [ ${debdiffFlag} -eq 0 ]
    then
        cd ${GitPath}
        CommonTasks
    fi
    cd ${GitPath}
}

function ImportDebianPackage {
    # Called by TaskSelect

    echo "Import an existing package without pristine-tar" >> ${log}
    cd ${PrjPath}
    echo "Download ${SourceName} with apt source" >> ${log}
    apt source --download-only ${SourceName} >> ${log}

    GpgKeyAvailable

    # GitPath has to be deleted because gbp import-dsc will create it.
    rmdir --verbose ${GitPath} >> ${log}

    echo "gbp import-dsc" >> ${log}
    gbp import-dsc --verbose ${SourceName}*.dsc >> ${log}

    cd ${GitPath}
    git remote add salsa git@salsa.debian.org:${SalsaName}
 # Identify branches and choose one
    DebianBranchName

    if whiptail --title "Name and email" \
    --yesno "Do you like to add your name and email address \n \
    to the local git config file?" --yes-button "Yes" \
    --no-button "No" 15 60
    then
        AddNameAndEmail
    fi

    AddHomeServer
    PQImport
    CommonTasks

}

function Import4Sponsoring {
    # Called by StartTasks

    cd ${PrjPath}
    
    if whiptail --title "Should the Debian sources be downloaded?" \
    --yesno "Should the Debian sources (*.orig.tar.g|xz, *.debian.tar.g|xz\n \
    and *.dsc) be downloaded?" \
    --defaultno --yes-button "Yes" --no-button "No" 15 60
    then
        DownloadUrl=$(whiptail --title "Insert URL for download" \
        --inputbox "Please insert the complete\n \
        URL to download ${UpstreamSourceName}\n(with ’https://’\n \
        e.g. from mentors.debian.net):" \
        --cancel-button "Cancel" 15 60 3>&2 2>&1 1>&3)

        dget --download-only ${DownloadUrl}
        ls -la
        echo -e "\n Press RETURN to continue!"
        read a
    fi

    # GitPath has to be deleted because gbp import-dsc will create it.
    echo $(pwd) >> ${log}
    rmdir ${GitPath}

    GpgKeyAvailable
    gbp import-dsc --verbose $(ls *.dsc) >> ${log} &&

    ParseConfig
    cd ${SourceName}
    echo $(pwd) >> ${log}
    SBuildOrPBuilder 0
    Task=5 # Go to RunningTests
}

function CommonTasks {
    # Called by BuildApp TaskSelect

   Task=$(whiptail --title "Tasks:" \
    --radiolist "What do you like to do? " 17 60 9 \
      "2" "Build a new version of a package" off \
      "3" "Build a new debian revision" on \
      "4" "Rebuilding a revision" off \
      "5" "Running lintian and uscan" off \
      "6" "Uploading only (build again if necessary)" off \
      "7" "Create new branch" off \
      "8" "Select branch" off \
      "9" "Set name or IP of own git server" off \
     "10" "Create a debdiff" off \
    --cancel-button "Exit" 3>&2 2>&1 1>&3)

    if [ -z "${Task}" ]
    then
        exit
    fi
    TaskSelect
}

function AskOrigName {
    # Called by BuildApp ConfigFileLEC and itself
    
    # Name of the project (without this name the app cannot work)
    OrigName=$(whiptail --title "This name is required!" \
    --inputbox "Name of the project:" \
    --cancel-button "Exit" 15 60 3>&2 2>&1 1>&3)
    if [ $? -ne 0 ]
    then
        whiptail --title "Bye" --msgbox "Bye" 15 60
        exit
    fi

    if [ -z "${OrigName}" ]
    then
        whiptail --title "No project name" \
        --msgbox "You have to identify a project name\n \
        even it is a new project!" 15 60
        AskOrigName
    fi
    ConfigFileLEC
}

function BuildApp {
    # Called by main program

    ##############

    # Intro

    ##############

    intro="Assistant to build simple Debian packages\nusing git-buildpackage\n
Authors: Mechtilde Stehmann\n
         Michael Stehmann\n
Version: 0.9.9\n
License: GPL v3+\n
This program does not build Debian packages itself.
It is only an assistant for the package maintainer."

    whiptail --title "Introduction" --msgbox "$intro" 20 60

    # Definitions of Project
    AskOrigName
    CreateDirsAndLogFile

    # Flag for additional gbp buildpackage options
    OptFlag=0

    ##############

    # End of intro

    ## Checks whether there is a git repo
    cd ${GitPath}
    set +e
    git status 1>/dev/null 2>&1

    # '==' does the same as '-eq'
    if [ $? == 0 ]
    then
        if [ -d .git ]
        then
            SelectBranch
        else
            SupOrdMsg="Is there a git repository in a superordinate directory?"
            echo ${SupOrdMsg} >> ${log}
            whiptail --title="Attention!" --msgbox "${SupOrdMsg}" 15 60
            StartTasks
        fi
    else
        StartTasks
    fi

    set -e
    # Start of Packaging
    CommonTasks
}

##############
# Here it starts
BuildApp

############## 
# This is the end, my friend 
#generated on Sun, 04 May 2025 09:23:46 +0000
