#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/get-index - help script to get index.txt # # Creation: 2011-08-27 hbfl # Last Update: $Id$ # # Copyright (c) 2011-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. #---------------------------------------------------------------------------- MKTEMP=/bin/mktemp GREP=/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_get_index=true if ${debug_get_index:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi # --------------------------------------------------------------------------- # cdrom and usb handling # --------------------------------------------------------------------------- mount_cdrom () { if ! mount | grep -q ' /cdrom' #>/dev/null then mount /cdrom cdrom_mounted=true echo "DATETIME" >/tmp/cdrom_installer_mounted 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 -q "${usb_dev}" #>/dev/null then /var/install/bin/system-devices-mount-usb retvar=${?} if [ ${retvar} -eq 0 ] then usb_mounted=true echo "DATETIME" >/tmp/usb_installer_mounted fi 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 } # --------------------------------------------------------------------------- # get eisfair-system infor # --------------------------------------------------------------------------- # 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 # --------------------------------------------------------------------------- # 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 'http://www.pack-eis.de' if [ ${index} != ${default_index} ] then if grep -q 'http://www.pack-eis.de' ${tmp_dir}/index.txt${count_number} then mv ${tmp_dir}/index.txt${count_number} ${tmp_dir}/index.txt-tmp grep -v 'http://www.pack-eis.de' ${tmp_dir}/index.txt-tmp >${tmp_dir}/index.txt${count_number} rm -f ${tmp_dir}/index.txt-tmp fi 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 # sort -u $(find ${tmp_dir} -maxdepth 1 -type f -name "index.txt*" 2>/dev/null) >/tmp/index.txt # extraxt header info sort -u $(find ${tmp_dir} -maxdepth 1 -type f -name "index.txt*" 2>/dev/null) | grep '#' >/tmp/index.txt # extract packages without system-info sort -u $(find ${tmp_dir} -maxdepth 1 -type f -name "index.txt*" 2>/dev/null) | grep -vE 'eisfair-1|eisfair-2|eisxen-1|#' >>/tmp/index.txt # 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 /var/install/bin/sortidx -u /var/install/url-priority /tmp/index.txt /tmp/index.txt fi } # --------------------------------------------------------------------------- # get additional search paths for index # --------------------------------------------------------------------------- get_additional_search () { additional_path="$(grep -v '^#' /var/install/url-search)" # get additional index.txt for search echo "${additional_path}" | while read line do case ${line} in file:///cdrom*) : ;; file:///usb*) : ;; *) eislist=${line} # test if path and file available if ${wget} -t 1 -q --spider ${line} then ${wget} -q -O ${tmp_dir}/eis-list ${line} /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="${_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 while read line do get_index_file ${line} done <${tmp_dir}/index-list } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- default_index="http://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 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 if grep -q "file://" /var/install/url then eislist=$(cat /var/install/url) case "${eislist}" in "file:///cdrom/"*) mount_cdrom ;; "file:///usb/"*) mount_usb ;; esac # test if path and file available if ${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 get_index_file ${index} fi fi 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 # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------