#! /bin/sh #---------------------------------------------------------------------------- # list-packages - list packages # # Copyright (c) 2001-2005 Frank Meyer # # Creation: 04.11.2001 fm # Last Update: $Id$ # # 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 # # Valid sections are: # # admin, base, database, devel, drivers, game, interpreter # lib, net, news, mail, misc, web, util # #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # 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 #---------------------------------------------------------------------------- # 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" ;; "invalid"*) mecho -info "List installed packages with invalid section name" ;; *) 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 [ "$selected_section" == "all" ] then if [ "$section_invalid" == "true" ] then techo row "" "$n." "$package" -warn "$section" "$version" "$date" else techo row "" "$n." "$package" "$section" "$version" "$date" fi else if [ "$section_invalid" == "true" ] then techo row "" "$n." "$package" -warn "$section" "$version" "$date" else techo row "" "$n." "$package" "" "$version" "$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 if [ "$selected_section" == "all" ] \ || [ "$selected_section" == "$section" ] \ || [ "$selected_section" == "invalid" -a "$section_invalid" == "true" ] then ret=0 fi return $ret } #---------------------------------------------------------------------------- # read_package_info # # reads the package info file and writes the result to # $package, $description, $version, $date, $author and $section #---------------------------------------------------------------------------- read_package_info () { file=$1 package='' description='' version='' date='' author='' while read line do case "$line" in ""* | ""*) set -- $line package="$2" [ "$package" = '' ] && package=`echo "$line" | sed 's###g'` ;; ""*) set -- $line shift [ "$description" = '' ] && description="$*" ;; ""*) description=`echo "$line" | sed 's###g'` ;; ""*) set -- $line version="$2" [ "$version" = '' ] && version=`echo "$line" | sed 's###g'` ;; ""*) set -- $line date="$2" [ "$date" = '' ] && date=`echo "$line" | sed 's###g'` ;; ""*) set -- $line author="$*" author=`echo "$author" | sed 's###g' | sed 's###g'` ;; "
"*) section=`echo "$line" | sed 's###g'` ;; *) ;; esac done < $file [ "$section" = '' ] && section="missing" check_section } #---------------------------------------------------------------------------- # normalize_version # # reads the version of the package and normalizes the value # (to provide compatibility to older versions) #---------------------------------------------------------------------------- normalize_version () { v=$1 case $v in 1.0beta) v=0.90.0 ;; 1.0beta-patch-*) IFS='-' set -- $v unset IFS v=0.90.$3 ;; esac case "$v" in [0-9]*.[0-9]*.[0-9]*) IFS='.' set -- $v unset IFS major=$1 minor=$2 revision=$3 ;; [0-9]*.[0-9]*) IFS='.' set -- $v unset IFS major=$1 minor=$2 revision=0 ;; *) major=0 minor=0 revision=0 ;; esac version=$major.$minor.$revision } #---------------------------------------------------------------------------- # MAIN #---------------------------------------------------------------------------- while [ 1 ] do clrhome write_header techo begin 3 4 30 12 20 11 a='' n=0 for j in /var/install/packages/* do read_package_info $j normalize_version $version if list_package then n=`expr $n + 1` write_row row=`expr $row + 1` eval package_$n='"$j"' if [ $row = 21 ] then mecho mecho a=`/var/install/bin/ask "More infos of package" "" "1-$n" "^$=Continue" "0=Return"` if [ "$a" = "0" ] then techo end exit 0 fi if [ "$a" != "" ] then break fi clrhome write_header fi fi done 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 exit 0 fi techo end if [ "$a" = "" ] then mecho mecho a=`/var/install/bin/ask "More infos of package" "" "1-$n" "^$=Continue" "0=Return"` fi if [ "$a" = "0" ] then exit 127 fi if [ "$a" = "" ]; then exit 0 fi eval file='$package_'"$a" read_package_info $file normalize_version $version 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 a=`/var/install/bin/ask "Please select" "" "^$=Continue" "0=Return"` if [ "$a" = "0" ]; then exit 127 fi done exit 0