#! /bin/sh #---------------------------------------------------------------------------- # list-packages - list packages # # Copyright (c) 2001-2005 Frank Meyer # # Creation: 2001-11-04 fm # Last Update: $Id: list-packages,v 1.7 2006/06/20 17:38:06 ansgar Exp $ # # 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. #---------------------------------------------------------------------------- # # Usage: # # list-packages # or list-packages all - list all packages # list-packages - list only packages of specified category # list-packages invalid - list packages with a non valid section # list-packages nolib - list all packages, but no lib # list-packages upgradable - list upgradable packages # # Valid sections are: # # admin, base, database, devel, drivers, game, interpreter # lib, net, news, mail, misc, web, util # #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # define some constants #---------------------------------------------------------------------------- show_progress=1 #---------------------------------------------------------------------------- # define valid sections #---------------------------------------------------------------------------- valid_sections="lib devel net misc mail web admin base utils interpreter news database drivers game" #---------------------------------------------------------------------------- # include eislib #---------------------------------------------------------------------------- . /var/install/include/eislib . /var/install/include/packagelib #---------------------------------------------------------------------------- # read command line option #---------------------------------------------------------------------------- selected_section=$1 if [ -z "$selected_section" ] then selected_section="all" fi shift #---------------------------------------------------------------------------- # write_header # # writes the header of the package-table dependent on $selected_section #---------------------------------------------------------------------------- write_header () { case $selected_section in "all") mecho -info "List all installed packages" ;; "nolib") mecho -info "List all installed packages (but no libraries)" ;; "invalid") mecho -info "List installed packages with invalid section name" ;; "upgradable") if [ "$stable_check" = 1 ] then mecho -info "List upgradable packages (with stable upgrades)" else mecho -info "List upgradable packages" fi ;; *) mecho -info "List installed ${selected_section}-packages" ;; esac mecho row=3 } #---------------------------------------------------------------------------- # write_row # # writes the rows of the package-table dependent on # $selected_section and $section_invalid #---------------------------------------------------------------------------- write_row () { if [ $vcheck -eq 1 ] then # internet access available vret=`check_for_updates $package` case $vret in 0) level='-warn' update='update' ;; 1) level='' update='no update' ;; 2) level='-error' update='not found' ;; esac else # no internet access available level='' update='' fi eval section='$_'$n'_PACKAGE_SECTION' eval version='$_'$n'_PACKAGE_VERSION' eval date='$_'$n'_PACKAGE_DATE' eval section='$_'$n'_PACKAGE_SECTION' [ "$show_progress" = 1 ] && mecho -n ' \b\b\b\b\b\b\b\b\b\b\b\b' if [ "$selected_section" == "all" ] \ || [ "$selected_section" == "nolib" ] \ || [ "$selected_section" == "upgradable" ] then if [ "$section_invalid" == "true" ] then techo row "" "$n." "$package" -warn "$section" "$version" $level "$update" "$date" else techo row "" "$n." "$package" "$section" "$version" $level "$update" "$date" fi else if [ "$section_invalid" == "true" ] then techo row "" "$n." "$package" -warn "$section" "$version" $level "$update" "$date" else techo row "" "$n." "$package" "" "$version" $level "$update" "$date" fi fi } #---------------------------------------------------------------------------- # check_section # # check if the section is valid an writes the result to $section_invalid #---------------------------------------------------------------------------- check_section () { section_invalid="true" for check_section in $valid_sections do if [ "$section" == "$check_section" ] then section_invalid="false" break fi done } #---------------------------------------------------------------------------- # function list_package # # check if the package shall be listed dependent on $selected_section #---------------------------------------------------------------------------- function list_package () { ret=1 eval section='$_'$m'_PACKAGE_SECTION' check_section if [ "$selected_section" == "all" ] \ || [ "$selected_section" == "$section" ] \ || [ "$selected_section" == "invalid" -a "$section_invalid" == "true" ] then ret=0 fi if [ "$selected_section" == "nolib" ] \ && [ "$section" != "lib" ] then ret=0 fi if [ "$selected_section" == "upgradable" ] then vret=`check_for_updates $package` if [ $vret -eq 0 ] then ret=0 fi fi return $ret } #---------------------------------------------------------------------------- # function get_indextxt # # get name of index.txt # output: 1 - found name # 0 - no index.txt defined #---------------------------------------------------------------------------- function get_indextxt () { cd /var/tmp # get download URL eislist=`cat /var/install/url` eislist_local=`basename $eislist` # get eislist wget.sh -q $eislist rc=$? if [ "$rc" != 0 ] then # no eislist -> return 0 return 0 else indexraw=`grep '#' /var/tmp/$eislist_local` rm -f /var/tmp/$eislist_local if [ "$indexraw" = '' ] then # no index file defined -> return 0 return 0 else set -- $indexraw index="$2" case $index in *:*) ;; *) index_path=`dirname $eislist` index="$index_path/$index" ;; esac base_index=`basename $index` rm -f $base_index # get index.txt wget.sh -q $index if [ $? = 0 ] then return 1 else return 0 fi fi fi } #---------------------------------------------------------------------------- # check for package updates # # input: $1 - package name # output: 0 - update available # 1 - no update available # 2 - package not found #---------------------------------------------------------------------------- check_for_updates () { pname="$1" vrtc=1 if [ -f $index_txt_file -a -s $index_txt_file ] then pnames=`grep "^$pname " $index_txt_file | tr -s ' ' ':'` if [ "$pnames" != "" ] then # package found for PN in `echo $pnames` do # check version number _oldifs=$IFS IFS=':' set -- $PN IFS=$_oldifs if [ $stable_check = 1 ] then if [ "$3" != 'stable' ] then break fi fi vcheck=`/var/install/bin/check-version $pname $2` if [ "$vcheck" = "new" ] then # new package found vrtc=0 break fi done else # package not found vrtc=2 fi fi echo $vrtc } #---------------------------------------------------------------------------- # show available updates # # input: $1 - package name #---------------------------------------------------------------------------- show_updates () { pname="$1" if [ -f $index_txt_file -a -s $index_txt_file ] then pnames=`grep "^$pname " $index_txt_file | tr -s ' ' ':'` if [ "$pnames" != "" ] then # package found # write eis-list header { echo "# Temporary package list for $pname packages" echo "# Copyright (c) 2001-2006 The Eisfair Team, c/o Frank Meyer, " echo "# file://$index_txt_file" echo "#" echo "# Available packages:" } > $eislist_txt_file for PN in `echo $pnames` do # get packages _oldifs=$IFS IFS=':' set -- $PN IFS=$_oldifs # write eis-list entry echo "# $4:$5" >> $eislist_txt_file done fi fi } #============================================================================ # MAIN #============================================================================ index_txt_file="/var/tmp/index.txt" eislist_txt_file="/var/tmp/list-packages-list.txt" # try to get file index.txt get_indextxt indextxt_found=$? clrhome write_header vcheck=0 if [ "$indextxt_found" = 1 ] then if [ "$selected_section" != "upgradable" ] then mecho /var/install/bin/ask "Do you want to look for new package versions" 'n' > /tmp/ask.$$ rc=$? yesno=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then rm -f $index_txt_file exit 1 fi if [ "$yesno" = "yes" ] then vcheck=1 else rm -f $index_txt_file fi fi fi if [ "$selected_section" == "upgradable" ] then vcheck=1 if [ "$indextxt_found" = 0 ] then mecho -error 'no index file available, can not look for new package versions' anykey exit 1 fi fi if [ "$vcheck" = 1 ] then mecho /var/install/bin/ask "Do you want to look only for stable package versions" 'n' > /tmp/ask.$$ rc=$? yesno=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then rm -f $index_txt_file exit 1 fi if [ "$yesno" = "yes" ] then stable_check=1 else stable_check=0 fi fi while [ 1 ] do clrhome write_header techo begin 3 4 28 12 10 12 10 a='' n=0 for j in /var/install/packages/* do [ "$show_progress" = 1 ] && mecho -n 'searching...\b\b\b\b\b\b\b\b\b\b\b\b' j=`basename $j` m=`expr $n + 1` parse_infofile /var/install/packages/$j _$m eval package='$_'$m'_PACKAGE_NAME' if list_package then n=`expr $n + 1` write_row row=`expr $row + 1` eval package_$n='"$j"' eval package_status_$n='"$update"' if [ $row = 21 ] then [ "$show_progress" = 1 ] && mecho -n ' ' mecho mecho a=`/var/install/bin/ask "More infos of package" "" "1-$n" "^$=Continue" "0=Exit"` if [ "$a" = "0" ] then techo end rm -f $index_txt_file exit 0 fi if [ "$a" != "" ] then break fi clrhome write_header fi fi done [ "$show_progress" = 1 ] && mecho -n ' ' if [ $n -eq 0 ] then techo row techo row techo row "" -warn "No ${selected_section}-packages found" techo row techo row row=`expr $row + 5` anykey techo end rm -f $index_txt_file exit 0 fi techo end if [ "$a" = "" ] then mecho mecho a=`/var/install/bin/ask "More infos of package" "" "1-$n" "^$=Continue" "0=Exit"` fi if [ "$a" = "0" ] then rm -f $index_txt_file exit 127 fi if [ "$a" = "" ] then rm -f $index_txt_file exit 0 fi #set -x #eval package='$package_'"$a" eval package='$_'$a'_PACKAGE_NAME' eval status='$package_status_'"$a" eval section='$_'$a'_PACKAGE_SECTION' eval version='$_'$a'_PACKAGE_VERSION' eval date='$_'$a'_PACKAGE_DATE' eval section='$_'$a'_PACKAGE_SECTION' eval author='$_'$a'_PACKAGE_AUTHOR' eval description='$_'$a'_PACKAGE_SHORT' #set | grep "_10_PACKAGE_" #set +x #clrhome mecho -info "Package information" mecho; mecho; mecho; techo begin 4 14 62 techo row "" "Package:" "$package" techo row techo row "" "Description:" "$description" techo row if [ "$section_invalid" == "true" ] then techo row "" "Section:" -warn "$section" else techo row "" "Section:" "$section" fi techo row techo row "" "Version:" "$version" techo row techo row "" "Date:" "$date" techo row techo row "" "Author:" "$author" techo end mecho; mecho; mecho; mecho if [ "$status" = "update" ] then # update available a=`/var/install/bin/ask "Please select" "" "s=Show updates" "^$=Continue" "0=Return"` case $a in s|S) show_updates $package /var/install/bin/install-package "file://${eislist_txt_file}" if [ -f ${eislist_txt_file} ] then rm -f ${eislist_txt_file} fi ;; 0) rm -f $index_txt_file exit 127 ;; esac else # no update available a=`/var/install/bin/ask "Please select" "" "^$=Continue" "0=Exit"` if [ "$a" = "0" ] then exit 127 fi fi done rm -f $index_txt_file exit 0 #============================================================================ # END #============================================================================