#!/bin/bash

# Include scripts
scriptPath=$(dirname "${BASH_SOURCE[0]}")

. "$scriptPath/common.sh"

logFolder="/kis/app"

sudo chmod 777 /kis
sudo mkdir -p $logFolder

# First check internet connection

check_internet
internet=$?

if [ ${internet} -eq 1 ]; then
    show_error "$internet Internet connection failed"
    exit 1
fi

(
    cd ~

    rm -rf ~/installation

    mkdir installation
    cd installation

    echo "Download all installation scripts"

    install_url="https://debs.photo-me.eu/installation/scripts/software/group/laundry/revolution"

    wget -r --no-parent -R "index.html*" --no-directories ${install_url}

    if [ $? -ne 0 ] ; then
        show_error "Can't download ${install_url}"
        exit 1
    fi

    echo "Run installation script"

    chmod +x *.sh

    cd .
    source ./install.sh

    echo "# Finished"
    echo "100"

) | zenity --progress --title "Installing..." --pulsate --text "" --auto-close