#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/get-index - help script to get index.txt # # Creation: 2011-08-27 hbfl # Last Update: $Id$ # # Copyright (c) 2011-@@YEAR@@ 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 MKTEMP=/usr/bin/mktemp GREP=/usr/bin/grep FIND=/usr/bin/find DIRNAME=/usr/bin/dirname SED=/usr/bin/sed SORT=/usr/bin/sort EXPR=/usr/bin/expr TAIL=/usr/bin/tail wget=/usr/local/bin/wget.sh #debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi # --------------------------------------------------------------------------- # get eisfair-system info # --------------------------------------------------------------------------- get_defaults() { # 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 for entry in ${systems} do if [ -z "${eis_systems}" ] then eis_systems="${entry}" else eis_systems="${eis_systems}|"${entry} fi done } # --------------------------------------------------------------------------- # get count number # --------------------------------------------------------------------------- get_count_number() { count_number=$(<${index_count}) expr ${count_number} + 1 >${index_count} } # --------------------------------------------------------------------------- # get index file # --------------------------------------------------------------------------- get_index_file() { index="${1}" if ! grep -q "${index}" ${tmp_dir}/index-done then echo "${index}" >>${tmp_dir}/index-done index_path=$(dirname ${index}) get_count_number # test if path and file available if ${wget} -t 1 -q --spider ${index} then ${wget} -q -O ${tmp_dir}/index.txt${count_number} ${index} /usr/local/bin/dtou ${tmp_dir}/index.txt${count_number} # from index.txt, that comes not from Pack-Eis, # remove lines that contains '//www.pack-eis.de' if [ ${index} != ${default_index} ] then if grep -q '//www.pack-eis.de' ${tmp_dir}/index.txt${count_number} then sed -i '/\/\/www.pack-eis.de/d' ${tmp_dir}/index.txt${count_number} fi # remove lines that have a '#' to begin sed -i '/^#/d' ${tmp_dir}/index.txt${count_number} fi while read line do case ${line} in [a-z]*) set -- ${line} p_path=${4} case ${p_path} in *:*) break ;; *) # write absolute path, if relative path given sed -i "s#${p_path}#${index_path}/${p_path}#" ${tmp_dir}/index.txt${count_number} ;; esac ;; esac done < ${tmp_dir}/index.txt${count_number} fi # merge only in one index.txt file # extraxt header info sort -u $(find ${tmp_dir} -maxdepth 1 -type f -name "index.txt*" 2>/dev/null) | grep -E '^#' >/tmp/index.txt # # extract packages without system-info, only for eisfair-1 # if [ "${system_work}" = "eisfair-1" ] # then # sort -u $(find ${tmp_dir} -maxdepth 1 -type f -name "index.txt*" 2>/dev/null) | grep -vE "${eis_systems}|#" >>/tmp/index.txt # fi # extract matched eisfair-system info # sort -u $(find ${tmp_dir} -maxdepth 1 -type f -name "index.txt*" 2>/dev/null) | grep "${system_work}" >>/tmp/index.txt sort -u $(find ${tmp_dir} -maxdepth 1 -type f -name "index.txt*" 2>/dev/null) | grep -vE '^#' >>/tmp/index.txt # sortidx with --descending-prio, for eisman /var/install/bin/sortidx --descending-prio -u /var/install/url-priority /tmp/index.txt /tmp/index.txt fi } # --------------------------------------------------------------------------- # get additional search paths for index # --------------------------------------------------------------------------- get_additional_search() { additional_path="$(grep -vE '^#' /var/install/url-search)" # get additional index.txt for search echo "${additional_path}" | while read line do case ${line} in file:///media/cdrom*) : ;; file:///media/usb*) : ;; *) eislist=${line} # test if path and index.txt available if ${wget} -t 1 -q --spider $(dirname ${line})/index.txt then index=$(dirname ${line})/index.txt # write tmp index url list echo ${index} >>${tmp_dir}/index-list # test if path and file available elif ${wget} -t 1 -q --spider ${line} then ${wget} -q -O ${tmp_dir}/eis-list ${line} indexraw='' if [ -s ${tmp_dir}/eis-list ] then /usr/local/bin/dtou ${tmp_dir}/eis-list indexraw=$(grep '#' ${tmp_dir}/eis-list) fi rm -f ${tmp_dir}/eis-list if [ -n "${indexraw}" ] then set -- ${indexraw} _index="${2}" case ${_index} in *:*) index="${_index}" ;; *) index_path=$(dirname ${eislist}) index="${index_path}/${_index}" ;; esac # write tmp index url list echo ${index} >>${tmp_dir}/index-list fi else outprint="$(/bin/date '+%Y-%m-%d %T') url-fail:" echo "${outprint}" "${line}" >> /var/log/log.url-error fi ;; esac done # get additional index.txt files if [ -s ${tmp_dir}/index-list ] then while read line do get_index_file ${line} done <${tmp_dir}/index-list fi } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- main() { default_index="https://www.pack-eis.de/index.txt" tmp_dir=/var/lib/index mkdir -p ${tmp_dir} while [ ${#} -gt 0 ] do case ${1} in --index) index=${2} shift;shift ;; --current-url) current_url=${2} shift;shift ;; --clear) _clear=true shift ;; esac done if ${_clear:-false} then rm -f ${tmp_dir}/* fi index_count=${tmp_dir}/counter if [ ! -f ${index_count} ] then echo "1" >${index_count} fi if [ ! -f ${tmp_dir}/index-done ] then >${tmp_dir}/index-done fi # get_defaults # get the default index url if [ -n "${index}" ] then case ${index} in *:*) : ;; *) index_path=$(dirname ${current_url}) index="${index_path}/${index}" ;; esac get_index_file ${index} _index_ret=${?} if [ ${_index_ret} -ne 0 ] then if [ -f /tmp/index.txt ] then # run wget in timeout or something went wrong, # create a dummy index that install can work echo "#datetime" >/tmp/index.txt fi fi fi file_search=$(grep "^file://" /var/install/url-search) if [ -n "${file_search}" ] then for line in "${file_search}" do eislist=${line} case "${eislist}" in "file:///media/cdrom/"*) mount_cdrom ;; "file:///media/usb/"*) mount_usb ;; esac # test if path and index.txt available if ${wget} -t 1 -q --spider $(dirname ${eislist})/index.txt then index=$(dirname ${eislist})/index.txt _index=true # test if path and file available elif ${wget} -t 1 -q --spider ${eislist} then ${wget} -q -O ${tmp_dir}/eis-list ${eislist} /usr/local/bin/dtou ${tmp_dir}/eis-list indexraw=$(grep '#' ${tmp_dir}/eis-list) rm -f ${tmp_dir}/eis-list if [ -n "${indexraw}" ] then set -- ${indexraw} index="${2}" case ${index} in *:*) : ;; *) index_path=$(dirname ${eislist}) index="${index_path}/${index}" ;; esac _index=true fi fi if ${_index:-false} then get_index_file ${index} fi done fi # get also the search index too if [ -f /var/install/url-search -a ! -f ${tmp_dir}/index-search ] then echo "datetime" >${tmp_dir}/index-search get_additional_search fi # # get also the default index too # if [ ! -f ${tmp_dir}/index-default ] # then # echo "datetime" >${tmp_dir}/index-default # get_index_file ${default_index} # fi } # --------------------------------------------------------------------------- # call function main # --------------------------------------------------------------------------- main "${@}" # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------