#! /bin/sh #---------------------------------------------------------------------------- # list-packages - list packages # # Creation: 2001-11-04 fm # Last Update: $Id$ # # Copyright (c) 2001-2012 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: # backup base chat communication contrib database devel drivers game lib # libdev mail misc multimedia netservices netutils news plang printer-file # security system utils web # # Deprecated sections from old section structure: # admin etc interpreter net #---------------------------------------------------------------------------- # --------------------------------------------------------------------------- # define some constants # --------------------------------------------------------------------------- show_progress=1 # --------------------------------------------------------------------------- # Define list of valid sections # --------------------------------------------------------------------------- valid_sections="backup base chat communication contrib database devel drivers game lib libdev mail misc multimedia netservices netutils news plang printer-file security system utils web" # --------------------------------------------------------------------------- # include eislib # --------------------------------------------------------------------------- . /var/install/include/eislib . /var/install/include/packagelib #debug_list_packages=true if ${debug_list_pacakges:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi # --------------------------------------------------------------------------- # 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 # check for EISFAIR_SYSTEM is set, or check it once if [ -z "${EISFAIR_SYSTEM}" ] then # get eisfair system-type . /var/install/include/check-eisfair-version # set eisfair system-type _system_work=${EISFAIR_SYSTEM} else # set eisfair system-type _system_work=${EISFAIR_SYSTEM} fi #---------------------------------------------------------------------------- # execute cui package list application if curses menu is active #---------------------------------------------------------------------------- if `grep -qE "^MENU=['\"]/var/install/bin/show-menu.cui['\"]" /etc/config.d/setup` then case "${selected_section}" in "all") /var/install/bin/list-packages.cui \ --system=${_system_work} \ --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=${_system_work} \ --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=${_system_work} \ -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=${_system_work} \ -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 echo 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}" then vret=`check_for_updates ${package}` fi case $vret in 0) level='--warn' update='update' ;; 1) level='' update='no update' ;; 2) level='--error' update='not found' ;; 3) level='--info' update='included' ;; esac else # no internet access available level='' update='' fi section='' version='' date='' _svn='' eval section='$_'${_n}'_PACKAGE_SECTION' eval version='$_'${_n}'_PACKAGE_VERSION' eval date='$_'${_n}'_PACKAGE_DATE' # split version and set svn-date in date token, if given # put svn to version token if `echo "${version}" | grep -qE "svn|cvs"` then _svn="`echo "${version}" | sed 's/[-0-9.:]//g'`" date="`echo "${version}" | sed 's/^.*[cvs|svn]//'`" version="`echo "${version}" | sed 's/[cvs|svn].*$//'`${_svn}" fi [ "$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" 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" 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" if echo "${valid_sections}" | grep -q "^${section}$" then section_invalid="false" fi } # --------------------------------------------------------------------------- # function list_package # # check if the package shall be listed dependent on $selected_section # --------------------------------------------------------------------------- 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 # --------------------------------------------------------------------------- get_indextxt () { _clear='' if [ ! -f /tmp/index ] then _clear="--clear" fi /var/install/bin/get-index ${_clear} _index_ret=${?} if [ ${_index_ret} -eq 0 ] then return 1 else return 0 fi # cd /var/tmp # # get download URL # eislist=`cat /var/install/url` # eislist_local=`basename $eislist` # # get eislist # ${wget} -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} -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}` if [ -n "${pnames}" ] then # package found echo "${pnames}" | while read line do set -- ${line} if [ "${stable_check}" = "1" -a "${3}" != "stable" ] then continue fi vcheck=`/var/install/bin/check-version ${pname} ${2}` if [ "${vcheck}" = "new" ] then # fetch info file # check for system version base_packfile=`basename "${4}"` rm -f ${base_packfile} case ${4} in *:*) ${wget} -q ${4} ;; *) ${wget} -q ${index_path}/${4} ;; esac /usr/local/bin/dtou ${base_packfile} # check for system version display_system="`grep "" ${base_packfile} | sed 's###g; s/ /-/'`" if [ -z "${display_system}" ] then display_system="eisfair-1" fi if ! `echo "${display_system}" | grep -q "${_system_work}$"` then rm -f ${base_packfile} continue else index_package_version="`grep "" ${base_packfile} | sed 's###g'`" rm -f ${base_packfile} if [ `/var/install/bin/check-version ${pname} ${index_package_version}` = new ] then # new package found echo datetime >/tmp/new_package_found break fi fi # end if [ "${vcheck}" = "new" ] fi done else case "${pname}" in perl_*) vrtc=3 ;; *) # package not found vrtc=2 ;; esac # end if [ -n "${pnames}" ] fi # end if [ -f ${index_txt_file} -a -s ${index_txt_file} ] fi rm -f ${base_packfile} if [ -f /tmp/new_package_found ] then vrtc=0 rm -f /tmp/new_package_found 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.txt" echo "#" echo "# Available packages:" } > $eislist_txt_file echo "${pnames}" | while read line do set -- ${line} if [ "${stable_check}" = "1" -a "${3}" != "stable" ] then continue fi case ${4} in *:*) pfile_name=${4} ;; *) pfile_name=${index_path}/${4} ;; esac case ${1} in base) # write eis-list entry, for base without version echo "# ${pfile_name}" >> $eislist_txt_file ;; *) # write eis-list entry echo "# ${pfile_name}" >> $eislist_txt_file ;; esac 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#:.*$##' >/var/tmp/_search_section installed_packages=`ls -F /var/install/packages | grep -vE "~|/$" | sed 's#*##'` for pa in ${installed_packages} do if ! `grep -q ${pa} /var/tmp/_search_section` then search_packages=`echo "${search_packages}";echo "${pa}"` fi done rm -f /var/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" echo; echo; echo; techo --begin '4 14 62' techo --row "" "Package:" "$package" echo techo --row "" "Description:" "$description" echo # if true if "$section_invalid" then techo --row "" "Section:" --warn "$section" else techo --row "" "Section:" "$section" fi echo techo --row "" "Version:" "$version" echo techo --row "" "Date:" "$date" echo techo --row "" "Author:" "$author" techo --end echo; echo; echo; echo if [ "$status" = "update" ] then refresh_screensize # update available gotoyx `expr "${_EISLIB_SCREENSIZE_Y}" - 2` 1 echo /var/install/bin/ask "Select" "" "s=Show updates" "^$=Return" "0=Exit" > /tmp/ask.$$ rc=$? a=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then del_file exit 1 fi 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 del_file exit 127 fi ;; 0) del_file exit 127 ;; esac else refresh_screensize # no update available gotoyx `expr "${_EISLIB_SCREENSIZE_Y}" - 2` 1 echo /var/install/bin/ask "Select" "" "^$=Return" "0=Exit" > /tmp/ask.$$ rc=$? a=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then del_file exit 1 fi if [ "$a" = "0" ] then del_file exit 127 fi fi } # --------------------------------------------------------------------------- # deinstall files # --------------------------------------------------------------------------- del_file() { # rm -f ${index_txt_file} rm -f ${_parser_file} } # --------------------------------------------------------------------------- # print base update message # --------------------------------------------------------------------------- print_base_update () { echo mecho --warn "Please update your system, base version, first." echo del_file anykey exit 1 } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- index_txt_file="/tmp/index.txt" eislist_txt_file="/var/tmp/list-packages-list.txt" _parser_file="/var/tmp/list-packages-value" wget=/usr/local/bin/wget.sh _default_base=1.6.1 # try to get file index.txt get_indextxt indextxt_found=$? # get the required base version from index.txt, or set the default _req_base=`awk '/^# required_base/ {print $3}' ${index_txt_file} 2>/dev/null` if [ -z "${_req_base}" ] then _req_base=${_default_base} fi # check for installed base version installed_base=`/var/install/bin/check-version base ${_req_base}` case ${installed_base} in not-installed|new) _inst_base=false ;; *) _inst_base=true ;; esac clrhome stable_check=0 check_update=true write_header vcheck=0 if [ "$indextxt_found" = 1 ] then if [ "$selected_section" != "upgradable" ] then echo /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 del_file exit 1 fi if [ "$yesno" = "yes" ] then # check if selected section != base if [ "${selected_section}" != "base" ] then # check for installed base if ! ${_inst_base} then print_base_update fi fi vcheck=1 else del_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 echo /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 del_file exit 1 fi # check if selected section != base if [ "${selected_section}" != "base" ] then # check for installed base if ! ${_inst_base} then print_base_update fi fi if [ "$yesno" = "yes" ] then stable_check=1 else stable_check=0 fi fi while [ 1 ] do clrhome write_header techo --begin '6r 28* 10* 11 12 11' a='' search_packages='' # do it a little bit faster with grep first case ${selected_section} in all|upgradable) search_packages=`ls -F /var/install/packages | sed 's#:.*$##; s#*##' | grep -vE '~|/$' | sort` ;; nolib) search_packages=`grep -r "
" /var/install/packages | grep -v "section>lib" | sed 's#:.*$##; s#^.*/##; s#*##' | grep -vE '~|/$'` 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#:.*$##; s#^.*/##; s#*##' | grep -v '~|/$'` get_package_with_no_section search_packages=`echo "${search_packages}" | sort` ;; *) search_packages=`grep -r "
${selected_section}" /var/install/packages | sed 's#:.*$##; s#^.*/##; s#*##' | grep -vE '~|/$' | sort` ;; esac _n=0 # touch parser file echo "#" > ${_parser_file} 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 -i , --info infofile # -v , --varpref [variable-prefix] # -o , --outfile /var/tmp/[outfile] parse_infofile -i /var/install/packages/${j} -v _${m} -o ${_parser_file} # include parser file . ${_parser_file} 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' echo echo techo --row "" --warn "No ${selected_section}-packages found" echo echo row=`expr ${row} + 5` anykey techo --end del_file exit 0 fi techo --end if [ -z "${a}" ] then refresh_screensize echo echo echo echo techo --end gotoyx `expr "${_EISLIB_SCREENSIZE_Y}" - 3` 1 echo # 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 echo fi /var/install/bin/ask "More infos of package" "" "1-${_n}" "^$=Return" "0=Exit" >/tmp/ask.$$ rc=$? a=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then del_file exit 1 fi fi case ${a} in '') del_file exit 0 ;; 0) del_file exit 127 ;; *) show_package_info ;; esac done del_file exit 0 # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------