#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/install-package - install a package # # Copyright (c) 2001-2003 Frank Meyer # # Creation: 04.11.2001 fm # Last Update: $Id$ # # usage: # install-package # or: # install-package url-of-eis-list.txt # or: # install-package [-y] -i [package choice_url] info_url # # 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. #---------------------------------------------------------------------------- # include eislib . /var/install/include/eislib set -f # disable pathname expansion if [ "$0" = "/var/install/update/install-package" ] then wget=/var/install/update/wget.sh new_status='n' old_status='o' inst_status='i' notinst_status='-' unknown_status='?' link_status='>' else new_status=`colecho -tty "n" br b br` old_status=`echo "o"` inst_status=`colecho -tty "i" gn x br` notinst_status=`colecho -tty "-" br b br` unknown_status=`colecho -tty "?" x x br` link_status=`colecho -tty ">" cy` wget=/usr/local/bin/wget.sh fi basedir=`dirname $0` if [ "$basedir" = "." ] then basedir=`pwd` fi gotoyx () { echo -e "\033[$1;$2H\c"; } cdrom_mounted=false mount_cdrom () { if ! mount | grep ' /cdrom' >/dev/null then mount /cdrom cdrom_mounted=true fi } umount_cdrom () { if [ "$cdrom_mounted" = "true" ] then umount /cdrom cdrom_mounted=false fi } 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 $wget -q $info_url if [ $? -ne 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 } get_packagename_by_index () { { name="$1" version="$2" ip=`dirname $index_url` stable_url='' unstable_url='' highest_stable_version='' highest_unstable_version='' while read line do set -- $line packname=$1 packversion=$2 packstatus=$3 packfile=$4 if [ "$packname" = "$name" ] then if [ "$packstatus" = "stable" ] then stat=`/var/install/bin/check-version -diff "$packversion" "$highest_stable_version"` if [ $stat != "old" ] then stable_url="$ip/$packfile $version" highest_stable_version=$packversion fi else stat=`/var/install/bin/check-version -diff "$packversion" "$highest_unstable_version"` if [ $stat != "old" ] then unstable_url="$ip/$packfile $version" highest_unstable_version=$packversion fi fi fi done if [ "$version" != "" ] then if [ "$stable_url" != "" ] then stat=`/var/install/bin/check-version -diff "$highest_stable_version" "$version"` if [ $stat != "old" ] then echo "$stable_url" $version else echo "$unstable_url" $version fi else echo "$unstable_url" $version fi else if [ "$stable_url" != "" ] then echo "$stable_url" $version else echo "$unstable_url" $version fi fi } 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'` r=`echo $require_package | sed 's# .*##g'` # strip version case $r in *:*) ;; *.*) ip=`dirname $current_url` require_package="$ip/$require_package" ;; *) require_package=`get_packagename_by_index $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 -ne 0 ] then colecho "This package requires some other packages which are unknown." br b br colecho "Installation aborted." br b 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 -eq 0 ] then b=`basename $choice_url` rm -f $b $wget $choice_url if [ $? -ne 0 ] then colecho "Error occured. Get help." br b 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 $choice_url pre_rtc=$? rm /tmp/preinstall.sh else pre_rtc=0 fi if [ $pre_rtc -ne 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 $choice_url rm -f /tmp/install.sh fi fi fi rm -f /tmp/$b fi fi } infotag() { 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 } 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` case "$url" in "file:///cdrom/"*) mount_cdrom ;; esac do_ask=yes else if [ "$1" = "-y" ] then do_ask=no shift else do_ask=yes fi if [ "$1" = "-i" ] then if [ $# -eq 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 umount_cdrom 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 $wget $url /usr/local/bin/dtou $base_url if [ $? -ne 0 ] then colecho "Error occured. Get help." br b br umount_cdrom exit 1 fi clrhome colecho "Install package - $url" gn echo redirect=false index_read=false n=0 while read line do case "$line" in "#"*) set -- $line version="$2" echo " Version $version" ;; "#"*) set -- $line index="$2" case $index in *:*) ;; *) index_path=`dirname $current_url` index="$index_path/$index" ;; esac base_index=`basename $index` rm -f $base_index $wget -q $index index_url=$index index_read=true ;; "#"*) if [ $n -eq 0 ] then echo fi n=`expr $n + 1` unset IFS set -- $line shift info_url=$1 infotag ;; "#"*) set -- $line shift req_version=`echo "$1" | sed 's/>.*//g'` st=`/var/install/bin/check-version base $req_version` if [ "$st" != new ] then if [ $n -eq 0 ] then echo fi n=`expr $n + 1` unset IFS shift info_url=$1 infotag 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' ;; "#"*) set -- $line shift req_version=`echo "$1" | sed 's/>.*//g'` st=`/var/install/bin/check-version base $req_version` if [ "$st" != new ] then if [ $n = 0 ] then echo fi n=`expr $n + 1` 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' fi ;; "#" | "#"*) 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 umount_cdrom if [ $index_read = true ] then rm -f /tmp/index.txt index_read=false fi exit 127 fi if [ "$a" = "" ] then umount_cdrom if [ $index_read = true ] then rm -f /tmp/index.txt index_read=false fi 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 umount_cdrom exit 127 fi ;; esac fi url=$current_url if [ $index_read = true ] then rm -f /tmp/index.txt index_read=false fi anykey done umount_cdrom exit 0