#! /bin/sh

# $1 from-files
# $2 to-file
# $3 additional command
#. /opt/vars

get_files(){
    if [ ! -z "$1" ] 
    then
	ping -q -c 1 ${DRIVERSERVER}
	if [ "$?" -eq "0" ]
	then
lftp <<YYY
open ftp://${DRIVERSADDRESS}
get $1 -o $2
$3
quit
YYY
	return [ -e $2 ]
    else
	return 200
    fi
    else
	return 100
    fi
}

check_for_job_ftp() {
    echo "check for FTP job"
    
    
    if [ -z "$1" ] 
    then
	echo "Missing parameter 1: UserName"
	return 100
    fi
    
    if [ -z "$2" ] 
    then
	echo "Missing parameter 2: DeviceName"
	return 101
    fi

    ping -q -c 1 ${FTPSERVER} > /dev/null
    
    if [ "$?" -ne "0" ]
    then
	echo "can not ping FTP server"
	return 200
    fi
    
    ipz=`echo ${ip}| \
awk -F "." "{printf \"%s%s%s%s\",\
length(\\$1) < \"2\" ? \"00\"\\$1 : length(\\$1) < \"3\" ? \"0\"\\$1 : toupper(\\$1),\
length(\\$2) < \"2\" ? \"00\"\\$2 : length(\\$2) < \"3\" ? \"0\"\\$2 : toupper(\\$2),\
length(\\$3) < \"2\" ? \"00\"\\$3 : length(\\$3) < \"3\" ? \"0\"\\$3 : toupper(\\$3),\
length(\\$4) < \"2\" ? \"00\"\\$4 : length(\\$4) < \"3\" ? \"0\"\\$4 : toupper(\\$4)}"`
    lftp <<YYY
set net:timeout 5s
set net:max-retries 1
set net:reconnect-interval-base 3
set net:reconnect-interval-max 3
open ftp://${FTPJOBSADDRESS}
get ${1}_${2} -o /tmp/jobs.sh
mv  ${1}_${2} ${1}_${2}.${ipz}
quit
YYY

    return 0
}

check_for_job_cifs() {
    echo "check for CIFS job"
    if [ -z "$1" ] 
    then
	echo "Missing parameter 1: UserName"
	return 100
    fi
    
    if [ -z "$2" ] 
    then
	echo "Missing parameter 2: DeviceName"
	return 101
    fi

    ping -q -c 1 ${CIFSSERVER} > /dev/null
    
    if [ "$?" -ne "0" ]
    then
	echo "can not ping CIFS server"
	return 200
    fi
    
    
    ipz=`echo ${ip}| \
awk -F "." "{printf \"%s%s%s%s\",\
length(\\$1) < \"2\" ? \"00\"\\$1 : length(\\$1) < \"3\" ? \"0\"\\$1 : toupper(\\$1),\
length(\\$2) < \"2\" ? \"00\"\\$2 : length(\\$2) < \"3\" ? \"0\"\\$2 : toupper(\\$2),\
length(\\$3) < \"2\" ? \"00\"\\$3 : length(\\$3) < \"3\" ? \"0\"\\$3 : toupper(\\$3),\
length(\\$4) < \"2\" ? \"00\"\\$4 : length(\\$4) < \"3\" ? \"0\"\\$4 : toupper(\\$4)}"`

    mount -t cifs ${CIFSADDRESS} /mnt/cifs -o username=${CIFSUSERNAME},password=${CIFSPASSWORD}
    if [ "$?" -eq "0" ]
    then
	echo "can't mount CIFS share"
	return 300
    fi
    
    if [ ! -e /mnt/cifs/jobs/${1}_${2} ]
    then
	echo "No CIFS job for this device"
	return 0
    fi
    
    cp /mnt/cifs/jobs/${1}_${2} /tmp/jobs.sh
    mv /mnt/cifs/jobs/${1}_${2} /mnt/cifs/jobs/${1}_${2}.${ipz}
    
    umount /mnt/cifs
    return 0
}

find_ip_settings(){
    LANSETTINGS=`ifconfig ${INT}`
    MAC=`echo ${LANSETTINGS} | grep HWaddr | grep -E -o "..:..:..:..:..:.."`
    NETMASK=`echo ${LANSETTINGS} | grep -E -o "Mask:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | grep -E -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}`
}


check_for_job_http() {
    echo "check for HTTP job"
    ping -q -c 1 ${HTTPSERVER} > /dev/null
    if [ "$?" -ne "0" ]
    then
	echo "Network error: can't ping http server"
        return 200
    fi
    
    ipz=`echo ${ip}| \
awk -F "." "{printf \"%s%s%s%s\",\
length(\\$1) < \"2\" ? \"00\"\\$1 : length(\\$1) < \"3\" ? \"0\"\\$1 : toupper(\\$1),\
length(\\$2) < \"2\" ? \"00\"\\$2 : length(\\$2) < \"3\" ? \"0\"\\$2 : toupper(\\$2),\
length(\\$3) < \"2\" ? \"00\"\\$3 : length(\\$3) < \"3\" ? \"0\"\\$3 : toupper(\\$3),\
length(\\$4) < \"2\" ? \"00\"\\$4 : length(\\$4) < \"3\" ? \"0\"\\$4 : toupper(\\$4)}"`

     #Get job
    find_ip_settings
    wget -O /tmp/httpanswer.txt --post-data "name=${HTTPDEVICENAME}&token=${HTTPTOKEN}&ip=${ip}&mac=${MAC}&netmask=${NETMASK}" http://${HTTPSERVER}/ajax/getActiveWork
    if [ ! -r /tmp/httpanswer.txt ]
    then
	echo "Error get job via http"
        return 400
    fi
    
    #parse message
    MESSAGE=`cat /tmp/httpanswer.txt | grep -E -o "\"message\":\"[^\"]*\"" | cut -d":" -f2 | sed 's/\"//g'`
    echo "Message from server: ${MESSAGE}"
	
    #parse httpanswer.txt to find result
    SUCCESSCOUNT=`cat /tmp/httpanswer.txt | grep -c "\"result\":\"success\""`
    if [ "${SUCCESSCOUNT}X" != "1X" ]
    then
	echo "Error get job via http: server error"
	return 401
    fi
    
    
    #parse httpanswer.txt to find work id
    WORKID=`cat /tmp/httpanswer.txt | grep -E -o "\"id\":\"[^\"]*\"" | cut -d":" -f2 | sed 's/\"//g'`
    if [ "${WORKID}ID" == "ID" ]
    then
	echo "No work id found"
	return 402
    fi
    
    cat /tmp/httpanswer.txt | grep -E -o "script\":\"[^\"]*\"" | cut -d":" -f2 | sed 's/\"//g' | base64 -d > /tmp/jobs.sh
    echo "successful get job from http server. Work ID: ${WORKID}"
    return 0
}


regdevicehttp(){
    find_ip_settings
    wget -O /tmp/httpanswer.txt --post-data "username=${HTTPUSERNAME}&password=${HTTPPASSWORD}&name=${HTTPDEVICENAME}&ip=${ip}&mac=${MAC}&netmask=${NETMASK}" http://${HTTPSERVER}/ajax/regcomputer
    if [ ! -r /tmp/httpanswer.txt ]
    then
	echo "Error register device via http"
        return 400
    fi

        
    #parse message
    MESSAGE=`cat /tmp/httpanswer.txt | grep -E -o "\"message\":\"[^\"]*\"" | cut -d":" -f2 | sed 's/\"//g'`
    echo "Message from server: ${MESSAGE}"
	
    #parse httpanswer.txt to find result
    SUCCESSCOUNT=`cat /tmp/httpanswer.txt | grep -c "\"result\":\"success\""`
    if [ "${SUCCESSCOUNT}X" != "1X" ]
    then
	echo "Error register device via http: server error"
	return 401
    else
	echo "Successfull registration device"
    fi
    
    HTTPTOKEN=`cat /tmp/httpanswer.txt | grep -E -o "\"token\":\"[^\"]*\"" | cut -d":" -f2 | sed 's/\"//g'`
    if [ "${HTTPTOKEN}X" == "X" ]
    then
	echo "Error find http token in server answer"
	return 403
    fi
}

delete_job_ftp() {
    echo "Start delete FTP job"
    
    if [ -z "$1" ] 
    then
	echo "Missing parameter 1: UserName"
	return 100
    fi

    if [ -z "$2" ]
    then
	echo "Missing parameter 2: computerName"
        return 100
    fi

    ping -q -c 1 ${FTPSERVER} > /dev/null
    if [ "$?" -eq "0" ]
    then
	echo "can not ping FTP server"
	return 200
    fi
    #DELETE JOB
    lftp <<XXX
set net:timeout 5s
set net:max-retries 1
set net:reconnect-interval-base 3
set net:reconnect-interval-max 3
open ftp://${FTPJOBSADDRESS}
mv ${1}_${2}.${ipz} ${1}_${2}.done
quit
XXX
}



delete_job_cifs() {
    echo "Start delete CIFS job"

    if [ -z "$1" ] 
    then
	echo "Missing parameter 1: UserName"
	return 100
    fi

    if [ -z "$2" ]
    then
	echo "Missing parameter 2: computerName"
        return 100
    fi

    ping -q -c 1 ${CIFSSERVER} > /dev/null
    if [ "$?" -ne "0" ]
    then
	echo "can not pint CIFS server"
	return 200
    fi
    
    #DELETE JOB
    mount -t cifs ${CIFSADDRESS} /mnt/cifs -o username=${CIFSUSERNAME},password=${CIFSPASSWORD}
    if [ "$?" -ne "0" ]
    then
	echo "can not mount CIFS share"
	return 300
    fi
    
    if [ ! -e /mnt/cifs/jobs/${1}_${2}.${ipz} ]
    then
	echo "No CIFS job to delete"
	return 0
    fi
    
    mv /mnt/cifs/jobs/${1}_${2}.${ipz} /mnt/cifs/jobs/${1}_${2}.done
    umount /mnt/cifs
}



delete_job_http() {
    echo "Start delete HTTP job"

    ping -q -c 1 ${HTTPSERVER} > /dev/null
    if [ "$?" -ne "0" ]
    then
	echo "can not ping http server"
	return 200
    fi
    wget -O /tmp/httpanswerd.txt --post-data "name=${HTTPDEVICENAME}&token=${HTTPTOKEN}&work_id=${WORKID}" http://${HTTPSERVER}/ajax/doneWork
    if [ ! -r /tmp/httpanswerd.txt ]
    then
	echo "Error delete http job"
        return 400
    fi
	
    #parse httpanswer.txt to find result
    SUCCESSCOUNT=`cat /tmp/httpanswerd.txt | grep -c "\"result\":\"success\""`
    if [ "${SUCCESSCOUNT}X" != "1X" ]
    then
	echo "Error delete http job: server error"
	return 401
    else
	echo "Succes delete http job"
    fi
}

load_device(){
    ### Windows partition must be mounted to /mnt/hd before this functions running
    ping -q -c 1 ${DRIVERSERVER} > /dev/null
    if [ "$?" -eq "0" ]
    then
	lftp <<ZZZ
open ftp://${DRIVERSADDRESS}
get ${TXT} -o /tmp/${TXT}
quit
ZZZ
	lspci -m -n > ${LISTPCI}
	readfile /tmp/${TXT} ${LISTPCI} > ${START}
	. ${START}
     fi
}


common_job() {
#echo "COMMON JOB"
if [ "$?" -eq "0" ] 
then
    ntfsmount $NTFSDEVICE /mnt/hd -o force
    load_device
    umount /mnt/hd
    echo "UMOUNT ********************"    
fi
}

readfile() {
    TAB=$'\t'
    devicefile=$1
    filename=$2

    for arg in "MASS 01" "LAN 02" "VIDEO 03" "AUDIO 04"
    do
	set -- $arg	
        counter=0
	device=$1
	
	grep "^.\{8\}\"$2" $filename | \
	while read line 
	do
	    counter=$((counter+1))
	    DIST="$STARTDIST$device$counter"
	    loaddevice "$devicefile" "$line"
	done
    done
}


loaddevice() {
TAB="	"
    echo $2 | \
    sed -e "s/.\{2\}:.\{2\}\..\{1\} \".\{4\}\" \"\(.\{4\}\)\" \"\(.\{4\}\)\" \(-r\(.\{2\}\) \)\?\(-p.\{2\} \)\?\"\(.\{0,4\}\)\" \"\(.\{0,4\}\)\"/\1	\2	\4	\6	\7/g" | \
    awk -F "	" "{printf \"%s\\t%s\\t%s\\t%s\\t%s\\n\" ,\
		toupper(\$1),toupper(\$2),\$4 == \"\" ? \"0000\" : toupper(\$4),\
		\$5 == \"\" ? \"0000\" : toupper(\$5),\
		\$3 == \"\" ? \"00\" : toupper(\$3)}" > "listpci.r"

    grep -f "listpci.r" $1 | dos2unix | \
    awk -F "	" "BEGIN{print \"#!/bin/sh\"} \
		{ if (length(\$6) != 0) {mystr = gensub(/\\[^\\\\]+\$/, \"\", \"g\", \$1); \
			print \"echo Installing ... \", \$1, \$2, \$3, \$4, \$5, \$6 ;  \
		printf \"lftp -c \\\"open ftp://$DRIVERSADDRESS; mirror %s%s %s\\\"\", \"$WINVER\", \$6, \"$DIST\" ; \
		printf \"\n\" ; \
		printf \"if [ -r $DIST/auto.sh ]\" ; \
		printf \"\n\" ; \
		printf \"then\" ; \
		printf \"\n\" ; \
		printf \"dos2unix $DIST/auto.sh\" ; \
		printf \"\n\" ; \
		printf \". $DIST/auto.sh $DIST\" ; \
		printf \"\n\" ; \
		printf \"fi\" ; \
		printf \"\n\" ; } \
		else {print \"echo Driver path not specified \\\"$DIST\\\" \", \$2, \$3, \$4, \$5, \$6 }}" 

}


### UPDATE KERNEL AND INIT.CPIO.GZ

update_ftp(){
    ### linux partition must be mount to /mnt/lin before this function running
    ### Update via FTP
    CURR_KVERSION=0
    CURR_RAMVERSION=0
    RAMVERSION=0
    KVERSION=0
    ping -q -c 1 ${FTPSERVER} > /dev/null
    if [ "$?" -eq "0" ]
    then
lftp <<ZZZ
set net:timeout 5s
set net:max-retries 1
set net:reconnect-interval-base 3
set net:reconnect-interval-max 3
open ftp://${FTPUPDATEADDRESS}
get ${VERSIONTXT} -o /tmp/${VERSIONTXT}
quit
ZZZ
        if [ -r /tmp/${VERSIONTXT} ]
	then
	    dos2unix /tmp/${VERSIONTXT}
	    . /tmp/${VERSIONTXT}
        fi
	if [ -r /mnt/lin/boot/curr_version.txt ]
        then
	    . /mnt/lin/boot/curr_version.txt
        fi
	# check if variables is empty
        if [ "${CURR_KVERSION}" == "" ]
	then
	    CURR_KVERSION=0
        fi
	if [ "${CURR_RAMVERSION}" == "" ]
        then
	    CURR_RAMVERSION=0
        fi
	if [ "${KVERSION}" == "" ]
        then	
	    KVERSION=${CURR_KVERSION}
        fi
	if [ "${RAMVERSION}" == "" ]
        then
	    RAMVERSION=${CURR_RAMVERSION}
        fi
	### Current version: Kernel - $CURR_KVERSION ; Ram - $CURR_RAMVERSION
        ### Updates version: Kernel - $KVERSION ; Ram - $RAMVERSION
        if [ ${CURR_RAMVERSION} -lt ${RAMVERSION} -o ${CURR_KVERSION} -lt ${KVERSION} ]
	then
lftp <<ZZZ
set net:timeout 5s
set net:max-retries 1
set net:reconnect-interval-base 3
set net:reconnect-interval-max 3
open ftp://${FTPUPDATEADDRESS}
get init.cpio.gz -o /mnt/lin/boot/init1.cpio.gz
get kernel -o /mnt/lin/boot/kernel1
get kernel.md5sum -o /mnt/lin/boot/kernel.md5sum
get init.md5sum -o /mnt/lin/boot/init.md5sum
quit
ZZZ
    	    if [ "$?" -eq "0" -o -r /mnt/lin/boot/kernel1 -o -r /mnt/lin/boot/init1.cpio.gz ]
	    then
    		echo "Update ram & kernel..."
	        md5sum -c /mnt/lin/boot/kernel.md5sum
        	if [ "$?" -eq "0" ]	
	        then
		    md5sum -c /mnt/lin/boot/init.md5sum
    		    if [ "$?" -eq "0" ]
                    then
		        if [ -r /mnt/lin/boot/kernel1 ] && [ -r /mnt/lin/boot/init1.cpio.gz ]
	        	then
			    #move downloaded kernel and ram
			    mv /mnt/lin/boot/kernel1 /mnt/lin/boot/kernel
			    mv /mnt/lin/boot/init1.cpio.gz /mnt/lin/boot/init.cpio.gz
	                fi
		        #remove some trash
	        	rm /mnt/lin/boot/kernel.md5sum
		        rm /mnt/lin/boot/init.md5sum
	    
cat > /mnt/lin/boot/curr_version.txt <<EOF
CURR_KVERSION=$KVERSION
CURR_RAMVERSION=$RAMVERSION
EOF
	    
		    fi
	        fi
            fi
	fi
    fi
}



update_cifs(){
    ### linux partition must be mount to /mnt/lin before this function running
    ### Update via FTP
    CURR_KVERSION=0
    CURR_RAMVERSION=0
    RAMVERSION=0
    KVERSION=0
    ping -q -c 1 ${CIFSSERVER} > /dev/null
    if [ "$?" -eq "0" ]
    then
	mount -t cifs ${CIFSADDRESS} /mnt/cifs -o username=${CIFSUSERNAME},password=${CIFSPASSWORD}
	cp /mnt/cifs/update/${VERSIONTXT} /tmp/${VERSIONTXT}
    fi
    if [ -r /tmp/${VERSIONTXT} ]
    then
	dos2unix /tmp/${VERSIONTXT}
	. /tmp/${VERSIONTXT}
    fi
    if [ -r /mnt/lin/boot/curr_version.txt ]
    then
	. /mnt/lin/boot/curr_version.txt
    fi
    # check if variables is empty
    if [ "${CURR_KVERSION}" == "" ]
    then
	CURR_KVERSION=0
    fi
    if [ "${CURR_RAMVERSION}" == "" ]
    then
	CURR_RAMVERSION=0
    fi
    if [ "${KVERSION}" == "" ]
    then
	KVERSION=${CURR_KVERSION}
    fi
    if [ "${RAMVERSION}" == "" ]
    then
	RAMVERSION=${CURR_RAMVERSION}
    fi
    ### Current version: Kernel - $CURR_KVERSION ; Ram - $CURR_RAMVERSION
    ### Updates version: Kernel - $KVERSION ; Ram - $RAMVERSION
    if [ ${CURR_RAMVERSION} -lt ${RAMVERSION} -o ${CURR_KVERSION} -lt ${KVERSION} ]
    then
	cp /mnt/cifs/update/init.cpio.gz /mnt/lin/boot/init1.cpio.gz
	cp /mnt/cifs/update/kernel /mnt/lin/boot/kernel1
	cp /mnt/cifs/update/kernel.md5sum /mnt/lin/boot/kernel.md5sum
	cp /mnt/cifs/update/init.md5sum /mnt/lin/boot/init.md5sum
	
        if [ "$?" -eq "0" -o -r /mnt/lin/boot/kernel1 -o -r /mnt/lin/boot/init1.cpio.gz ]
	then
    	    echo "Update ram & kernel from CIFS server..."
	    md5sum -c /mnt/lin/boot/kernel.md5sum
            if [ "$?" -eq "0" ]	
	    then
	        md5sum -c /mnt/lin/boot/init.md5sum
    		if [ "$?" -eq "0" ]
                then
		    if [ -r /mnt/lin/boot/kernel1 ] && [ -r /mnt/lin/boot/init1.cpio.gz ]
	            then
			#move downloaded kernel and ram
		        mv /mnt/lin/boot/kernel1 /mnt/lin/boot/kernel
			mv /mnt/lin/boot/init1.cpio.gz /mnt/lin/boot/init.cpio.gz
	            fi
		    #remove some trash
	            rm /mnt/lin/boot/kernel.md5sum
		    rm /mnt/lin/boot/init.md5sum
	    
cat > /mnt/lin/boot/curr_version.txt <<EOF
CURR_KVERSION=$KVERSION
CURR_RAMVERSION=$RAMVERSION
EOF
	    
		fi
	    fi
        fi
    fi
    umount /mnt/cifs
}


write_serial(){
### Windows partition must be mounted to /mnt/hd before this skript running
## Write Serial into reg WINDOWS
reged -e /mnt/hd/WINDOWS/system32/config/system <<EEE
cd ControlSet001
cd Control
nk prorst
cd prorst
nv 1 Login
ed Login
${LOGIN}
q
y
EEE
}

## Two Variables : SERIAL and W_KEY must be defined before this function running
info_save(){
    mount ${LINUXDEVICE} /mnt/lin
    # Write info into file serial.txt
cat > /mnt/lin/settings.txt <<EOF
LOGIN="${LOGIN}"
WID="${WID}"
INTERNALSTORAGE="${INTERNALSTORAGE}"
WORKDEVICE="${WORKDEVICE}"
FTPSERVER="${FTPSERVER}"
FTPUSERNAME="${FTPUSERNAME}"
FTPPASSWORD="${FTPPASSWORD}"
CIFSSERVER="${CIFSSERVER}"
CIFSSHARE="${CIFSSHARE}"
CIFSUSERNAME="${CIFSUSERNAME}"
CIFSPASSWORD="${CIFSPASSWORD}"
HTTPSERVER="${HTTPSERVER}"
HTTPDEVICENAME="${HTTPDEVICENAME}"
HTTPTOKEN="${HTTPTOKEN}"
EOF
}

# TODO make save some info into windows partition
info_write(){
    mount ${LINUXDEVICE} /mnt/lin
    umount /mnt/hd
    umount /mnt/lin
}

info_read(){
    # linux partition must be mounted to /mnt/lin
    sleep 2s
    echo -n "User Login: "
    read LOGIN

    echo -n "Workstation ID: "
    read WID
}

FixWinBoot(){
    ntfsmount ${WORKDEVICE} /mnt/hd -o force
    ################
    cd /mnt/hd
    cp boot.ini /tmp/boot.ini
    sed "s/(1)/(2)/" /tmp/boot.ini > boot.ini
    cd /
    umount /mnt/hd
}

readboard(){
    grep -f "/tmp/board.r" /tmp/$BOARDTXT | dos2unix | \
    awk -F "	" "BEGIN{print \"#!/bin/sh\"} \
		{ if (length(\$4) != 0) {mystr = gensub(/\\[^\\\\]+\$/, \"\", \"g\", \$1); \
			print \"echo Installing ... \", \$1, \$2, \$3 ,\$4;  \
		printf \"for num in 1 2 3 4\" ; \
		printf \"\n\" ; \
		printf \"do\" ; \
		printf \"\n\" ; \
		printf \"lftp -c \\\"open ftp://$DRIVERSADDRESS/$WINVER/board/%s; mirror BOARD\${num} %s\\\"\", \$4, \"${DISTB}\${num}\" ; \
		printf \"\n\" ; \
		printf \"if [ -r ${DISTB}\${num}/auto.sh ]\" ; \
		printf \"\n\" ; \
		printf \"then\" ; \
		printf \"\n\" ; \
		printf \"dos2unix ${DISTB}\${num}/auto.sh\" ; \
		printf \"\n\" ; \
		printf \". ${DISTB}\${num}/auto.sh ${DISTB}\${num}\" ; \
		printf \"\n\" ; \
		printf \"fi\" ; \
		printf \"\n\" ; \
		printf \"done\" ; \
		printf \"\n\" ; } \
		else {print \"echo Driver path not specified \\\"$DISTB\\\" \", \$2, \$3 }}" 


}

loadboard(){
ntfsmount ${WORKDEVICE} /mnt/hd -o force

### load-BOARD
ping -q -c 1 $DRIVERSERVER > /dev/null
if [ "$?" -eq "0" ]
then
lftp <<ZZZ
open ftp://$DRIVERSADDRESS
get $BOARDTXT -o /tmp/$BOARDTXT
quit
ZZZ
fi
### Get Local BOARD
cat > /tmp/board.r <<EOF
`dmidecode -s baseboard-manufacturer|sed "s/ //g`	`dmidecode -s baseboard-product-name|sed "s/ //g`	`dmidecode -s bios-version|sed "s/ //g"`
EOF
### Make download skript
readboard > $STARTBOARD
### Start download skript
. $STARTBOARD
umount /mnt/hd
echo "UMOUNT ********************"    


}



splash(){
    pidof splashy >/dev/null && splashy_update "progress $1" >/dev/null 2>/dev/null
}