#!/bin/sh #--------------------------------------------------------------------------- # /var/install/bin/check-package check and search with pack-eis for a package # # Creation: 2006-10-17 hbfl # Last Update: $Id$ # # Copyright (c) 2001-2008 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. #--------------------------------------------------------------------------- # include eislib . /var/install/include/eislib #exec 2> /tmp/versuch-trace$$.log #set -x #--------------------------------------------------------------------------- # print usage #--------------------------------------------------------------------------- usage () { cat <"*) l=`echo "${l}" | sed 's###g'` set -- ${l} have_package_version="${1}" ;; esac done < ${FNAME} } #--------------------------------------------------------------------------- # check package #--------------------------------------------------------------------------- check_package () { packages_name="${1}" msg_do_now="${2}" check_version="${3}" if [ -f /var/install/packages/${packages_name} ] then read_packages_version /var/install/packages/${packages_name} # check for version installed_version=`/var/install/bin/check-version \ -diff \ ${check_version} \ ${have_package_version}` else installed_version=not-installed fi case ${installed_version} in not-installed) # is not installed echo mecho -info "${msg_do_now}" mecho -warn "Package '${packages_name}' is missing." echo ask_for_install ;; new) # is to old echo mecho -info "${msg_do_now}" mecho -info "'${packages_name}' package version must be ${check_version} or higher." echo ask_for_install ;; old|installed) # is good exit 0 ;; esac } #--------------------------------------------------------------------------- # ask for install #--------------------------------------------------------------------------- ask_for_install () { # ask for install ${ask} "Install" case ${?} in 0) # when yes search_for_package ${packages_name} ;; *) # when no echo mecho -info "${msg_do_now}" mecho -warn "Please, solve that first." echo anykey exit 1 ;; esac } #--------------------------------------------------------------------------- # search for package #--------------------------------------------------------------------------- get_indextxt () { 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 } #--------------------------------------------------------------------------- # search for package #--------------------------------------------------------------------------- search_for_package () { get_indextxt indextxt_found=${?} 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}-${pname} done /var/install/bin/install-package "file://${eislist_txt_file}-${pname}" else server=www.pack-eis.de # check if pack-eis is online or the internet connect is down ${wget} ${server} >/dev/null 2>&1 case ${?} in 0) /var/install/bin/install-package \ "http://${server}/index.php?q=${packages_name}&type=eis-list" ;; *) # when not OK echo mecho -info "${msg_do_now}" mecho -warn "No connect to '${server}'." mecho -warn "Please solve that first." echo anykey exit 1 ;; esac fi fi rm -f ${index_txt_file} rm -f ${eislist_txt_file}-${pname} # check, is the right version installed now check_package "${package}" "${msg}" "${version}" } #--------------------------------------------------------------------------- # main #--------------------------------------------------------------------------- index_txt_file="/var/tmp/index.txt" eislist_txt_file="/var/tmp/list-packages-list.txt" wget="/usr/local/bin/wget.sh" ask="/var/install/bin/ask" package='' version='0.0.1' msg='' # check for cmd line input case ${#} in 0|1|2) usage exit 1 ;; esac # read parameters while [ ${#} -ne 0 ] do case ${1} in -p|--setpackage|-setpackage) # set package package="${2}" shift; shift ;; -v|--setversion|-setversion) # set version version="${2}" shift; shift ;; *) msg="${1}" shift ;; esac done # check for packages is given case x${package} in x) echo mecho -info "${msg}" mecho -warn "No package is given" mecho -warn "Please solve that first" echo anykey exit 1 ;; *) if [ -z "${msg}" ] then msg="${package}" fi check_package "${package}" "${msg}" "${version}" ;; esac #-------------------------------------------------------------------------- # end #--------------------------------------------------------------------------