#! /bin/sh #---------------------------------------------------------------------------- # list-packages - list packages # # Creation: 2001-11-04 fm # Last Update: $Id$ # # Copyright (c) 2001-2007 the eisfair team, team(at)eisfair(dot)org # # 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 #exec 2> /tmp/list-packages-trace$$.log #set -x #---------------------------------------------------------------------------- # check if console minium 80x24 #---------------------------------------------------------------------------- check_screensize case ${?} in 0) # nothing to do ;; *) exit 1 ;; esac gotoyx () { echo -e "\033[$1;$2H\c"; } #---------------------------------------------------------------------------- # read command line option #---------------------------------------------------------------------------- selected_section=$1 if [ -z "$selected_section" ] then selected_section="all" fi shift #---------------------------------------------------------------------------- # get eisfair system version #---------------------------------------------------------------------------- if [ -f /etc/eisfair-system ] then eisfairsystem=`cat /etc/eisfair-system | sed 's/ /-/'` else eisfairsystem="eisfair-1" fi #---------------------------------------------------------------------------- # execute cui package list application if curses menu is active #---------------------------------------------------------------------------- . /etc/config.d/setup if [ "$MENU" = "/var/install/bin/show-menu.cui" ] then case "${selected_section}" in "all") /var/install/bin/list-packages.cui \ --system=${eisfairsystem} \ --upgradable \ --helpfile=/var/install/help/packages \ --helpname=PACKAGELIST \ -l \ --installcmd='/var/install/bin/install-package -y -l %s/index.txt -i %s' ;; "nolib") /var/install/bin/list-packages.cui \ --system=${eisfairsystem} \ --nolib \ --upgradable \ --helpfile=/var/install/help/packages \ --helpname=PACKAGEUPGRADE \ -l \ --installcmd='/var/install/bin/install-package -y -l %s/index.txt -i %s' ;; "upgradable") /var/install/bin/list-packages.cui \ --system=${eisfairsystem} \ -t "List of upgradable packages" \ --onlyupgradable \ --helpfile=/var/install/help/packages \ --helpname=PACKAGEUPGRADEONLY \ -l \ --installcmd='/var/install/bin/install-package -y -l %s/index.txt -i %s' ;; *) /var/install/bin/list-packages.cui \ --system=${eisfairsystem} \ -t "Installed packages of section \"${selected_section}\"" \ --section=${selected_section} \ --helpfile=/var/install/help/packages \ --helpname=PACKAGELIST ;; esac exit 0 fi #---------------------------------------------------------------------------- # 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}" -eq 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 if [ "${check_update}" = "true" ] then vret=`check_for_updates ${package}` fi case $vret in 0) level='-warn' update='update' ;; 1|2) 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_update=true } #---------------------------------------------------------------------------- # 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 check_update=false 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 [ -n "${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` if [ -n "${pnames}" ] then # package found # write eis-list header { echo "# Temporary package list for ${pname} packages" echo "# Copyright (c) 2001-`date +%Y` the eisfair team, team(at)eisfair(dot)org" echo "# ${index}" echo "#" echo "# Available packages:" } > $eislist_txt_file echo "${pnames}" | while read line do set -- ${line} case ${4} in *:*) pfile_name=${4} ;; *) pfile_name=${index_path}/${4} ;; esac # write eis-list entry echo "# ${pfile_name}" >> $eislist_txt_file done fi fi } #---------------------------------------------------------------------------- # search for packages with no section tag #---------------------------------------------------------------------------- get_package_with_no_section () { files_in_folder=0 files_in_section=0 files_in_folder=`ls /var/install/packages | wc -l` files_in_section=`grep -r "
" /var/install/packages | wc -l` if [ ${files_in_folder} -gt ${files_in_section} ] then grep -r "
" /var/install/packages | sed 's#:.*$##' >/tmp/_search_section for pa in /var/install/packages/* do if ! `grep -q ${pa} /tmp/_search_section` then search_packages=`echo "${search_packages}";echo "${pa}"` fi done rm -f /tmp/_search_section fi } #---------------------------------------------------------------------------- # show package info #---------------------------------------------------------------------------- show_package_info () { #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 gotoyx `expr "${_EISLIB_SCREENSIZE_Y}" - 2` 1 mecho a=`/var/install/bin/ask "Please select" "" "s=Show updates" "^$=Return" "0=Return"` case $a in s|S) show_updates $package /var/install/bin/install-package "file://${eislist_txt_file}" retval=${?} if [ -f ${eislist_txt_file} ] then rm -f ${eislist_txt_file} fi # if 0=EXIT from install-packages if [ ${retval} -ne 0 ] then rm -f $index_txt_file exit 127 fi ;; 0) rm -f $index_txt_file exit 127 ;; esac else # no update available gotoyx `expr "${_EISLIB_SCREENSIZE_Y}" - 2` 1 mecho a=`/var/install/bin/ask "Please select" "" "^$=Return" "0=Exit"` if [ "$a" = "0" ] then exit 127 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 stable_check=0 check_update=true 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 2 5r 28 12 10 12 10 a='' search_packages='' # do it a little bit faster with grep first case ${selected_section} in all|upgradable) search_packages=`ls /var/install/packages/* | sort` ;; nolib) search_packages=`grep -r "
" /var/install/packages | grep -v "section>lib" | sed 's#:.*$##'` get_package_with_no_section search_packages=`echo "${search_packages}" | sort` ;; invalid) unlist_sections=`echo "${valid_sections}" | sed 's# #|#g'` search_packages=`grep -r "
" /var/install/packages | grep -v -Ew "
${unlist_sections}
$" | sed 's#:.*$##'` get_package_with_no_section search_packages=`echo "${search_packages}" | sort` ;; *) search_packages=`grep -r "
${selected_section}" /var/install/packages | sed 's#:.*$##' | sort` ;; esac n=0 for j in ${search_packages} do [ ${show_progress} -eq 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"' fi done [ ${show_progress} -eq 1 ] && mecho -n ' ' if [ ${n} -eq 0 ] then techo begin 2 70 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 [ -z "${a}" ] then mecho mecho mecho mecho techo end gotoyx `expr "${_EISLIB_SCREENSIZE_Y}" - 3` 1 mecho # set info line to screen is $row + 6 -gt $LINES if [ ${_EISLIB_SCREENSIZE_Y} -lt `expr "${row}" + 6` ] then mecho -info "Use SHIFT + PAGE-UP to scroll up" else mecho fi a=`/var/install/bin/ask "More infos of package" "" "1-${n}" "^$=Return" "0=Exit"` fi case ${a} in '') rm -f ${index_txt_file} exit 0 ;; 0) rm -f ${index_txt_file} exit 127 ;; *) show_package_info ;; esac done rm -f ${index_txt_file} exit 0 #============================================================================ # END #============================================================================