#! /bin/sh #---------------------------------------------------------------------------- # install-package - install a package # # usage: # install-package # or: # install-package url-of-eis-list.txt # or: # install-package [-y] -i [package choice_url] info_url # # Copyright (c) 2001-2003 Frank Meyer # # Creation: 04.11.2001 fm # Last Update: 02.11.2003 fm # # 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. #---------------------------------------------------------------------------- new_status=`colecho "n" br x br` old_status=`echo "o"` inst_status=`colecho "i" gn x br` notinst_status=`colecho "-" br x br` unknown_status=`colecho "?" x x br` link_status=`colecho ">" cy` basedir=`dirname $0` if [ "$basedir" = "." ] then basedir=`pwd` fi gotoyx () { echo -e "\033[$1;$2H\c"; } read_info () { info_url=$1 case $info_url in *:*) ;; *) info_path=`dirname $current_url` info_url="$info_path/$info_url" ;; esac base_info_url=`basename $info_url` rm -f $base_info_url /usr/local/bin/wget.sh -q $info_url if [ $? != 0 ] then package_name="" package_version="0.0.0" package="" download_url=`echo "$info_url" | sed 's/\.info$//g'` rm -f $base_info_url return fi package_name= package_version= package= download_url=`echo "$info_url" | sed 's/\.info$//g'` /usr/local/bin/dtou $base_info_url while read a do case "$a" in ""*) package_name=`echo "$a" | sed 's###g'` ;; ""*) package=`echo "$a" | sed 's###g'` ;; ""*) package_version=`echo "$a" | sed 's###g'` ;; esac done <$base_info_url rm -f $base_info_url } f_disp_required_packages () { do_disp=$1 disp_rtc=0 req=/tmp/required_packages_found-$$ rm -f $req echo "$require_packages" | while read p do set $p require_package=$1 require_version=$2 if [ "$require_version" = "" ] then require_version=0.0.0 fi read_info $require_package status=`$basedir/check-version $package_name $require_version` if [ "$status" = "new" -o "$status" = "not-installed" ] then if [ ! -f $req ] then >$req if [ $do_disp = true ] then echo echo "This package requires the following packages:" echo fi fi if [ $do_disp = true ] then if [ "$require_version" != "0.0.0" ] then echo " $package_name >= $require_version - $package" else echo " $package_name - $package" fi fi if [ "$package_name" = "" -o "$package_name" = "" ] then disp_rtc=1 fi fi done return $disp_rtc } display_info () { info_url=$1 base_info_url=`basename $info_url` rm -f $base_info_url /usr/local/bin/wget.sh -q $info_url if [ $? != 0 ] then return fi description_active=false /usr/local/bin/dtou $base_info_url # check, if new tag given: if grep "" $base_info_url >/dev/null then display_require=false # display old require: false else display_require=true # display old require: true fi require_packages= while read a do case "$a" in ""*) ;; ""*) disp_name=`echo "$a" | sed 's###g'` echo " Name: "$disp_name ;; ""*) disp_package=`echo "$a" | sed 's###g'` echo " Package: "$disp_package ;; ""*) disp_version=`echo "$a" | sed 's###g'` echo " Version: "$disp_version ;; ""*) disp_date=`echo "$a" | sed 's###g'` echo " Date: "$disp_date ;; ""*) disp_author=`echo "$a" | sed 's###g'` echo " Author: "$disp_author ;; ""*) disp_status=`echo "$a" | sed 's###g'` echo " Status: "$disp_status ;; "
"*) disp_section=`echo "$a" | sed 's###g'` echo " Section: "$disp_section ;; ""*) disp_source=`echo "$a" | sed 's###g'` echo " Source: "$disp_source ;; ""*) if [ $display_require = true ] then disp_require=`echo "$a" | sed 's###g'` echo " Require: "$disp_require fi ;; ""*) require_package=`echo "$a" | sed 's###g'` case $require_package in *:*) ;; *) ip=`dirname $current_url` require_package="$ip/$require_package" ;; esac if [ "$require_packages" = "" ] then require_packages="$require_package" else require_packages=`echo "$require_packages"; echo "$require_package"` fi ;; ""*) description_active=true ;; ""*) description_active=false ;; ""*) ;; *) if [ "$description_active" = true ] then echo " $a" fi ;; esac done <$base_info_url rm -f $base_info_url if [ "$require_packages" != "" ] then f_disp_required_packages true disp_rtc=$? else disp_rtc=0 fi echo return $disp_rtc } f_install_package () { if [ "$info_url" != "" ] then clrhome colecho "Package: $package" gn echo echo " URL: $choice_url" echo display_info $info_url else echo echo "Package: $package" echo "URL : $choice_url" fi echo if [ $do_ask = yes ] then if $basedir/ask "Install" then do_install=yes else do_install=no fi else do_install=yes fi if [ $do_install = yes ] then disp_rtc=0 if [ "$require_packages" != "" ] then f_disp_required_packages false disp_rtc=$? if [ $disp_rtc != 0 ] then colecho "This package requires some other packages which are unknown." br x br colecho "Installation aborted." br x br else if [ -f $req ] then rm -f $req echo echo "$require_packages" | while read p do set $p require_package=$1 require_version=$2 if [ "$require_version" = "" ] then require_version=0.0.0 fi ( read_info $require_package status=`$basedir/check-version $package_name $require_version` if [ "$status" = "new" -o "$status" = "not-installed" ] then $basedir/install-package -i $require_package <$tty fi ) done fi fi fi if [ $disp_rtc = 0 ] then b=`basename $choice_url` rm -f $b /usr/local/bin/wget.sh $choice_url if [ $? != 0 ] then colecho "Error occured. Get help." br x br else echo "Please wait..." cd / rm -f /tmp/preinstall.sh case $b in *.tar.bz2) cmd=bzcat ;; *) cmd=zcat ;; esac $cmd /tmp/$b | tar xf - tmp/preinstall.sh 2>/dev/null chown root.root /tmp chmod 1777 /tmp # some packages destroy it if [ -f /tmp/preinstall.sh ] then sh /tmp/preinstall.sh pre_rtc=$? rm /tmp/preinstall.sh else pre_rtc=0 fi if [ $pre_rtc != 0 ] then echo "Installation aborted due to previous error" else rm -f /tmp/install.sh case $b in *.tar.bz2) cmd=bzcat ;; *) cmd=zcat ;; esac $cmd /tmp/$b | tar xf - 2>/tmp/install.log if [ ! -s /tmp/install.log ] # empty? then # yes... rm -f /tmp/install.log # remove it fi chown root.root /tmp chmod 1777 /tmp # some packages destroy it rm -f /tmp/preinstall.sh # fm 19.07.2003: remove again if [ -f /tmp/install.sh ] then sh /tmp/install.sh rm -f /tmp/install.sh fi fi fi rm -f /tmp/$b fi fi } pgmname=$0 dir=`dirname $pgmname` case "$dir" in /*) ;; .) pgmname=`pwd`/`basename $pgmname`;; *) pgmname=`pwd`/$pgmname;; esac cd /tmp tty=`tty` if [ "$1" = "" ] then url=`cat /var/install/url` do_ask=yes else if [ "$1" = "-y" ] then do_ask=no shift else do_ask=yes fi if [ "$1" = "-i" ] then if [ $# = 4 ] then package=$2 choice_url=$3 info_url=$4 else info_url=$2 read_info $info_url package=$package_name choice_url=$download_url current_url=$download_url fi f_install_package if [ -s /tmp/install.log ] then echo "Some warnings/errors have been logged." if $basedir/ask "Show them?" then pager=$PAGER if [ "$pager" = "" ] then pager=less fi $pager /tmp/install.log fi fi exit 0 else url=$1 fi fi current_url=$url package_status='?' while [ 1 ] do while [ 1 ] do cd /tmp echo colecho "Install package" gn echo echo "Retrieving list ..." base_url=`basename $url` rm -f $base_url /usr/local/bin/wget.sh $url /usr/local/bin/dtou $base_url if [ $? != 0 ] then colecho "Error occured. Get help." br x br exit 1 fi clrhome colecho "Install package - $url" gn echo redirect=false n=0 while read line do case "$line" in "#"*) set -- $line version="$2" echo " Version $version" ;; "#"*) if [ $n = 0 ] then echo fi n=`expr $n + 1` unset IFS set -- $line shift info_url=$1 if [ "$info_url" != "" ] then read_info $info_url package_status=`$basedir/check-version $package_name $package_version` case "$package_status" in new) package_status="$new_status" ;; old) package_status="$old_status" ;; installed) package_status="$inst_status" ;; not-installed) package_status="$notinst_status" ;; *) package_status="$unknown_status" ;; esac if [ $n -le 9 ] then echo " $n. $package_status $package_version $package" else echo " $n. $package_status $package_version $package" fi eval package_$n='"$package"' eval info_url_$n='"$info_url"' eval url_$n='"$download_url"' eval type_$n='package' package_status="$unknown_status" else if [ $n -le 9 ] then echo " $n." else echo " $n." fi fi ;; "#"*) set -- $line shift message="$*" echo " $message" ;; "#"*) set -- $line shift welcome="$*" colecho " $welcome" x x br ;; "#" | "#"*) echo ;; "#"*) set -- $line shift url="$1" echo "Got redirection:" echo "$url" echo if $basedir/ask "Follow redirection" <$tty then echo $url >/var/install/url current_url=$url redirect=true break fi ;; "#"*) if [ $n = 0 ] then echo fi n=`expr $n + 1` set -- $line shift link_url="$1" shift if [ $n -le 9 ] then echo " $n. $link_status $*" else echo " $n. $link_status $*" fi eval info_url_$n='' eval url_$n='"$link_url"' eval type_$n='link' ;; "#" | "#"*) read line ;; "#"*) ;; *) if [ $n = 0 ] then echo fi n=`expr $n + 1` set -- $line download_url="$1" shift package="$*" if [ $n -le 9 ] then echo " $n. $package_status $package" else echo " $n. $package_status $package" fi eval package_$n='"$package"' eval info_url_$n='' eval url_$n='"$download_url"' eval type_$n='package' package_status='?' ;; esac done < $base_url rm -f $base_url if [ $redirect = false ] then break fi done gotoyx 20 1 echo echo "$unknown_status = unknown $notinst_status = not installed $new_status = New $old_status = Old $inst_status = Installed $link_status = Link" echo echo -e "Package to install (1-$n, ENTER=Return 0=Exit) \c" read a if [ "$a" = "0" ] then exit 127 fi if [ "$a" = "" ] then exit 0 fi case "$a" in [0-9]*) is_numeric=true;; *) is_numeric=false; a=0;; esac if [ $is_numeric = true -a $a -ge 1 -a $a -le $n ] then eval info_url='$info_url_'$a eval choice_url='$url_'$a eval package='$package_'$a eval type='$type_'$a case $choice_url in *:*) ;; *) path=`dirname $current_url` choice_url=$path/$choice_url ;; esac case $type in package) f_install_package ;; link) sh $pgmname $choice_url if [ $? = 127 ] # Exit then exit 127 fi ;; esac fi url=$current_url $basedir/anykey done exit 0