#! /bin/sh #---------------------------------------------------------------------------- # /var/install/bin/package-search - Search package # # Creation: 2012-01-31 hbfl # Last Update: $Id$ # # Copyright (c) 2012-2012 the eisfair team, team(at)eisfair(dot)org # # Usage: package-search # or # package-search package-name # # 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 ask ask=/var/install/bin/ask #debug_package_search=true if ${debug_package_search:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi # --------------------------------------------------------------------------- # {u}mount cdrom or usb devices # --------------------------------------------------------------------------- mount_cdrom () { if ! mount | grep ' /cdrom' >/dev/null then mount /cdrom retvar=${?} if [ ${retvar} -eq 0 ] then _cdrom_mounted=true _mounted=true echo "DATETIME" >/tmp/cdrom_installer_mounted fi else _mounted=true fi } umount_cdrom () { if "${_cdrom_mounted:-false}" then umount /cdrom _cdrom_mounted=false fi } mount_usb () { # extract usb/sd.. from $url like # file:///usb/sd??/download/packages/eis-list.txt usb_dev=`echo ${eislist} | cut -d/ -f3-5` if ! mount | grep "${usb_dev}" >/dev/null then /var/install/bin/system-devices-mount-usb retvar=${?} if [ ${retvar} -eq 0 ] then _usb_mounted=true _mounted=true echo "DATETIME" >/tmp/usb_installer_mounted fi else _mounted=true fi } umount_usb () { if "${_usb_mounted:-false}" then /var/install/bin/system-devices-umount-usb retvar=${?} if [ ${retvar} -eq 0 ] then _usb_mounted=false fi fi } # --------------------------------------------------------------------------- # remove check file # --------------------------------------------------------------------------- remove_check_file () { if ${_index_get:-false} then /var/install/bin/post-setup-packages-menu fi } # --------------------------------------------------------------------------- # show question # --------------------------------------------------------------------------- show_question () { while [ "${#}" -gt "0" ] do case "${1}" in -l) _location="${2}" shift 2 ;; esac done clrhome mecho --info "Package search" echo _ask_tmpfile=$(mktemp -t XXXXXXXXXXXXX) ${ask} "Enter your searchstring (ENTER=Return, 0=Exit)" '' "*" >${_ask_tmpfile} rc=${?} search="$(cat ${_ask_tmpfile})" rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then search=0 fi case ${search} in '') umount_cdrom umount_usb exit 0 ;; 0) umount_cdrom umount_usb exit 127 ;; *) ${_location} -p "${search}" ;; esac } # --------------------------------------------------------------------------- # search pack-eis # --------------------------------------------------------------------------- search_pack_eis () { # this functio was covered from packeis-search, but packeis-search # was obsolet in the future # while [ "${#}" -gt "0" ] # do # case "${1}" in # -p) # search="${2}" # shift 2 # ;; # esac # done # encoded_search=$(echo ${search} | sed 's/ /%20/') # /var/install/bin/install-package "http://www.pack-eis.de/index.php?q=${encoded_search}&type=eis-list" # packeis_ret=${?} # if [ ${packeis_ret} -eq 127 ] # then # exit 127 # fi # if "${show_question:-true}" # then # show_question -l "search_pack_eis" # fi encoded_search=$(echo ${pname} | sed 's/ /%20/') _list_tmp_file="/var/tmp/${encoded_search}-eislist" if ${wget} -t 1 -q --spider http://www.pack-eis.de/index.php then ${wget} -q -O ${_list_tmp_file} "http://www.pack-eis.de/index.php?q=${encoded_search}&type=eis-link" if grep -q '#' ${_list_tmp_file} then if ! ${_header:-false} then write_header fi grep '#' ${_list_tmp_file} | grep -v 'Results' >> $eislist_txt_file rm -f ${_list_tmp_file} return 0 fi fi } # --------------------------------------------------------------------------- # check for installer # --------------------------------------------------------------------------- #check_url () #{ # url=$(cat /var/install/url) # # case "${url}" in # "file:///cdrom/"*) # _installer=true # _medium="CD-ROM" # ;; # "file:///usb/"*) # _installer=true # _medium="USB-Stick" # ;; # esac #} # --------------------------------------------------------------------------- # get search # --------------------------------------------------------------------------- #get_search () #{ # # set page titel # clrhome # mecho --info "Select search location" # echo # echo # # search_location="Search Pack-Eis:search_pack_eis # Search ${_medium} installer:search_installer" # # # show available menu styles # techo --begin '6r 32*' # echo # echo # _idx=1 # echo "${search_location}" | # while read line # do # _s_location=$(echo ${line} | awk -F: '{ print $1 }') # techo --row "${_idx}." "${_s_location}" # _idx=$(/usr/bin/expr ${_idx} + 1) # done # echo # echo # techo --end # _ask_tmpfile=$(mktemp -t XXXXXXXXXXXXX) # ${ask} "Select" "" "1-$(echo "${search_location}" | # wc -l)" "^$=Return" "0=Exit" >${_ask_tmpfile} # rc=${?} # _search_l="$(cat ${_ask_tmpfile})" # rm -f ${_ask_tmpfile} # # if [ ${rc} = 255 ] # then # _search_l=0 # fi # # case "${_search_l}" in # "") exit 0 ;; # 0) exit 127 ;; # *) # # get the line from '$search_location' and display '$2' # selected_location=$(echo "${search_location}" | # awk -F: 'FNR == '${_search_l}' { print $2 }') # # show_question -l "${selected_location}" # ;; # esac #} # --------------------------------------------------------------------------- # search installer # --------------------------------------------------------------------------- search_installer () { while [ "${#}" -gt "0" ] do case "${1}" in -p) search="${2}" shift 2 ;; esac done index_txt_file="/tmp/index.txt" eislist_txt_file="/var/tmp/list-packages-list.txt" wget=/usr/local/bin/wget.sh _default_base=1.6.1 get_indextxt # 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 get_packages ${search} ret=${?} if [ ${ret} -eq 0 ] then /var/install/bin/install-package "file://${eislist_txt_file}" fi rm -f ${eislist_txt_file} # rm -f ${index_txt_file} show_question -l "search_installer" } # --------------------------------------------------------------------------- # get index.txt # --------------------------------------------------------------------------- get_indextxt () { _clear='' if [ ! -s /tmp/index.txt ] then _clear="--clear" # _index_get=true fi # get-index handle multiple index.txt files /var/install/bin/get-index ${_clear} _index_ret=${?} if [ ${_index_ret} -eq 0 ] then return 0 else return 1 fi # cd /var/tmp # # get download URL # eislist=$(cat /var/install/url) # eislist_dir=$(dirname ${eislist}) # # case "${eislist_dir}" in # "file:///cdrom/"*) # mount_cdrom # ;; # "file:///usb/"*) # mount_usb # ;; # esac # # if ! "${_mounted:-false}" # then # echo # mecho --warn "No '${_medium}' installer found." # echo # anykey # exit 1 # else # # 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 # # fi } # --------------------------------------------------------------------------- # write header # --------------------------------------------------------------------------- write_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 _header=true } # --------------------------------------------------------------------------- # get packages # --------------------------------------------------------------------------- get_packages () { pname="$1" if [ -f $index_txt_file -a -s $index_txt_file ] then pnames=$(grep -i "${pname}" ${index_txt_file} | grep -v '#') if [ -n "${pnames}" ] then # package found write_header echo "${pnames}" | while read line do set -- ${line} 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 search_pack_eis _header=false return 0 else search_pack_eis _header=false return ${?:-1} fi pnames="" fi } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- if [ -n "${1}" ] then show_question=false search="${1}" _index_get=true search_installer -p "${search}" # search_pack_eis -p "${search}" remove_check_file exit 0 fi #check_url show_question -l "search_installer" #if "${_installer:-false}" #then # get_search #else # show_question -l "search_pack_eis" #fi # remove_check_file # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------