geek rescue kit Code
Brought to you by:
ctaf
#!/bin/sh
##
## ct-install.sh
## Login : <ctaf@localhost.localdomain>
## Started on Tue Apr 11 13:55:03 2006 GESTES Cedric
## $Id$
##
## Copyright (C) 2006 GESTES Cedric
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
grkdir=~/.ctafconf/etc/grk
#catch a signal, else termcaps shit
_trap_kill ()
{
echo killing
exit 0
}
trap _trap_kill INT
#PKG FUNCTION
pkg_description()
{
local name=$@
eval $name"_description"
return $?
}
pkg_is_installed()
{
local name=$@
eval $name"_is_installed"
return $?
}
pkg_install()
{
local name=$@
echo installing package: $name
eval $name"_install"
return $?
}
pkg_uninstall()
{
local name=$@
eval $name"_uninstall"
return $?
}
pkg_alwaysinstall()
{
local name=$@
eval $name"_alwaysinstall"
return $?
}
pkg_source()
{
local name=$@
. $grkdir/"$name".grk
}
#0 installed
#1 already installed
#2 failed
grk_install()
{
local name=$1
local inst=$2
local ret
pkg_source $name
if [ x$inst = xno ] || pkg_is_installed $name; then
ret=1
else
if pkg_install $name; then
ret=0
else
ret=2
fi
fi
if ! pkg_alwaysinstall $name ; then
ret=2
fi
return $ret
}
#list installed pkg
grk_installed_list()
{
ls -1 $grkdir | grep ".grk$" | while read line; do
name=`echo $line | sed -e s/.grk//`
pkg_source $name
if pkg_is_installed $name >/dev/null; then
echo "$name"
fi
done
}
#install all pkg
grk_install_all()
{
ls -1 $grkdir | grep ".grk$" | while read line; do
name=`echo $line | sed -e s/.grk//`
pkg_source "$name"
grk_install "$name" yes
done
}
#install just those who need, ask for them
grk_install_ask()
{
echo "this is bugged, use choice instead"
exit
#ssft_yesno inside a while read doesnt work
ls -1 $grkdir | grep ".grk$" | while read line; do
name=`echo $line | sed -e s/.grk//`
pkg_source $name
if ! pkg_is_installed $name; then
if ssft_yesno "Do you want to install $name" "`pkg_description $name`"; then
#pkg_install $name
echo "installed"
fi
fi
pkg_alwaysinstall $name
done
}
grk_install_choice()
{
SSFT_DEFAULT=`grk_installed_list`
ssft_select_multiple "Install" "Select packages you want to install" `ls -1 $grkdir | grep ".grk$" | sed -e s/.grk//`
ls -1 $grkdir | grep ".grk$" | while read line; do
name=`echo $line | sed -e s/.grk//`
pkg_source $name
if echo $SSFT_RESULT | grep $name >/dev/null 2>/dev/null; then
pkg_install $name
fi
pkg_alwaysinstall $name
done
}
grk_help()
{
echo "help"
ssft_select_single "Package description" "Select packages you want help for" `ls -1 $grkdir | grep ".grk$" | sed -e s/.grk//`
name=$SSFT_RESULT
pkg_source $name
ssft_display_message "$name description" "`pkg_description $name`"
}
#############################################################################
##START
#############################################################################
if ! [ -d ~/.ctafconf/ ] ; then
echo "Can't find ~/.ctafconf directory"
echo "Aborting, verify that you have untar the archive into your home directory"
exit
fi
#install tools
. ~/.ctafconf/etc/shlib/grktools.sh
#shellscript frontend
. ~/.ctafconf/etc/shlib/ssft.sh
#create default directory
grk_dir ~/.ctafconf/perso
grk_dir ~/.ctafconf/perso/semantic
grk_dir ~/.ctafconf/perso/ssh
grk_dir ~/.ctafconf/perso/repos
grk_dir ~/.ctafconf/perso/wallpaper
grk_dir ~/.ctafconf/perso/bin
grk_dir ~/.ctafconf/perso/previous
#launch profile manager
. ~/.ctafconf/bin/ct-profile
if ! [ -f ~/.ctafconf/perso/user-profile ] ; then
echo "Can't find ~/.ctafconf/perso/user-profile directory"
echo "Aborting, execute ct-profile, or relauch install"
exit
fi
. ~/.ctafconf/perso/user-profile
export SSFT_FRONTEND=$ctafconf_interface
SSFT_DEFAULT=choice
ssft_select_single "Select one installation method" "'All' install every package, 'Ask' ask your before each package, and 'Choice' let you select packages you want in a list. If you want information about a package chouse 'information'" all ask choice information
insmethod=$SSFT_RESULT
###ASK
if [ x$insmethod = xask ] ; then
grk_install_ask
fi
###ALL
if [ x$insmethod = xall ] ; then
grk_install_all
fi
###CHOICE
if [ x$insmethod = xchoice ] ; then
grk_install_choice
fi
if [ x$insmethod = xinformation ] ; then
grk_help
fi