#!/bin/bash
###################################################################################
# Copyright (C) 2007 Pingviini Web #
# Copyright (C) 2006 UCK Team #
# #
# 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; version 2 #
# of the License. #
# #
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
###################################################################################
function find_dialog()
{
if [ ! -z "$DISPLAY" ] ; then
DIALOG=`which kdialog`
if [ ! -z "$DIALOG" ]; then
DIALOG_TYPE=kdialog
else
DIALOG=`which Xdialog`
if [ ! -z "$DIALOG" ]; then
DIALOG_TYPE=dialog
fi
fi
if [ -z "$DIALOG" ]; then
DIALOG=`which zenity`
if [ ! -z "$DIALOG" ]; then
DIALOG_TYPE=zenity
fi
fi
fi
if [ -z "$DIALOG" ]; then
DIALOG=`which dialog`
if [ ! -z "$DIALOG" ]; then
DIALOG_TYPE=dialog
fi
fi
if [ -z $DIALOG ]; then
failure "You need kdialog, Xdialog or dialog application to run this script, please install it using 'apt-get install packagename' where packagename is 'kdebase-bin' for kdialog, 'xdialog' for dialog, 'dialog' for dialog. If you are using text-mode, you need to install dialog."
fi
}
function dialog_menu()
{
DESCRIPTION="$1"
shift
declare -a PARAMS
if [ "$DIALOG_TYPE" = "zenity" ]; then
declare -i i=0
for v; do
PARAMS[$i]="$v"
i+=1
done
$DIALOG --list --text "$DESCRIPTION" --column "" "${PARAMS[@]}" --width=500 --height=400
else
if [ "$DIALOG_TYPE" = "kdialog" ] ; then
declare -i i=0
for v; do
PARAMS[$i]="$v"
i+=1
PARAMS[$i]="$v" #yes, 2 times as kdialog requires key and value
i+=1
done
$DIALOG --menu "$DESCRIPTION" "${PARAMS[@]}"
else
declare -i i=0
for v; do
PARAMS[$i]="$v"
i+=1
PARAMS[$i]="Language"
i+=1
done
$DIALOG --stdout --menu "$DESCRIPTION" 20 30 10 "${PARAMS[@]}"
fi
fi
}
function dialog_multi_choice()
{
DESCRIPTION="$1"
shift
if [ "$DIALOG_TYPE" = "zenity" ]; then
for i; do
PARAMS="$PARAMS $i $i"
done
$DIALOG --separator $'\n' --list --checklist --multiple --text "$DESCRIPTION" --column "" --column "" $PARAMS --width=500 --height=400
else
if [ "$DIALOG_TYPE" = "kdialog" ] ; then
for i; do
PARAMS="$PARAMS $i $i 0"
done
$DIALOG --separate-output --checklist "$DESCRIPTION" $PARAMS
else
for i; do
PARAMS="$PARAMS $i Language 0"
done
$DIALOG --stdout --separate-output --checklist "$DESCRIPTION" 20 30 10 $PARAMS
fi
fi
RESULT=$?
return $RESULT
}
function dialog_line_input()
{
DESCRIPTION="$1"
INITIAL_VALUE="$2"
if [ "$DIALOG_TYPE" = "zenity" ] ; then
$DIALOG --entry --text "$DESCRIPTION" --entry-text "$INITIAL_VALUE"
else
if [ "$DIALOG_TYPE" = "kdialog" ] ; then
$DIALOG --inputbox "$DESCRIPTION" "$INITIAL_VALUE"
else
$DIALOG --stdout --inputbox "$DESCRIPTION" 20 30 "$INITIAL_VALUE"
fi
fi
RESULT=$?
return $RESULT
}
function dialog_choose_file()
{
TITLE="$1"
if [ "$DIALOG_TYPE" = "zenity" ] ; then
$DIALOG --title "$TITLE" --file-selection "`pwd`/"
else
if [ "$DIALOG_TYPE" = "kdialog" ] ; then
$DIALOG --title "$TITLE" --getopenfilename "`pwd`/"
else
$DIALOG --stdout --title "$TITLE" --fselect "`pwd`/" 20 80
fi
fi
}
function dialog_msgbox()
{
TITLE="$1"
TEXT="$2"
if [ "$DIALOG_TYPE" = "zenity" ]; then
echo -n "$TEXT" | $DIALOG --title "$TITLE" --text-info --width=500 --height=400
else
$DIALOG --title "$TITLE" --msgbox "$TEXT" 20 80
fi
}
function dialog_question()
{
TITLE="$1"
TEXT="$2"
if [ "$DIALOG_TYPE" = "zenity" ]; then
$DIALOG --title "$TITLE" --question --text "$TEXT"
else
$DIALOG --title "$TITLE" --yesno "$TEXT" 20 80
fi
}
find_dialog
########
#TEATED#
#################################################################################
START_TEXT=`cat <<EOF
Olete käivitanud ID kaardi paigaldusutiliidi Linuxile.
Utiliit paigaldab Teie arvutisse ID kaardi kasutamiseks vajaliku
tarkvara.
Kuna Linuxi distributsioone on rohkem kui meie riigis Toompeal
istuvaid rasvaseid muidusööjaid, siis ei pruugi Teie
distributsioon olla toetatud.
Toetuse lisamiseks pöörduge
http://pingviin.org
EOF
`
OK_TEXT=`cat <<EOF
Kas soovid paigaldaja käivitada?
EOF
`
TESTS_TEXT=`cat <<EOF
Kontrollin komponente....
EOF
`
MISSING_TEXT=`cat <<EOF
Distributsioon tundmatu!
Abi saamiseks pöörduge
http://pingviin.org
EOF
`
NETWORK_TEXT=`cat <<EOF
Võrguühendus puudub.
Kontrolli seadistusi.
EOF
`
UBUNTU32_TEXT=`cat <<EOF
Distributsioon on Ubuntu x86
Paigaldus jätkub...
EOF
`
UBUNTU64_TEXT=`cat <<EOF
Distributsioon on Ubuntu AMD64
Paigaldus jätkub...
EOF
`
#############
#START#######
#############
dialog_msgbox "Tervist!" "$START_TEXT"
#RUN_TESTS=`dialog_menu "$OK_TEXT" yes no`
#
#if [ "$RUN_TESTS" = "yes" ]; then
#echo ok;else
#exit 1
#fi
if ping -c 1
www.google.com;then
echo 'Võrguhendus on olemas!';else
dialog_msgbox "Viga!" "$NETWORK_TEXT"
exit 1
fi
cd /tmp
##################
#DISTRIBUTSIOONID#
#########################################################################################
############
#UBUNTU X86#
############
if grep -q buntu /etc/issue;then
uname -m >> distro.txt;if
grep -q 86 distro.txt;then
dialog_msgbox "Distributsioon sobib!" "$UBUNTU32_TEXT"
wget
http://pacho.pri.ee/id/id_ubuntu_x86.tar.gz
tar zxvf id_ubuntu_x86.tar.gz
xterm -hold -e sh id_ubuntu_x86.sh
rm id_ubuntu_x86*
exit 0
fi
fi
##############
#UBUNTU AMD64#
##############
if grep -q buntu /etc/issue;then
uname -m >> distro.txt;if
grep -q 64 distro.txt;then
dialog_msgbox "Distributsioon sobib!" "$UBUNTU64_TEXT"
wget
http://pacho.pri.ee/id/id_ubuntu_64.tar.gz
tar zxvf id_ubuntu_64.tar.gz
xterm -hold -e sh id_ubuntu_64.sh
rm id_ubuntu_64*
exit 0
fi
fi
dialog_msgbox "Viga!" "$MISSING_TEXT"