#!/bin/sh #------------------------------------------------------------------------------ # /var/install/bin/capi2text-fetch-country-icons - fetch icons from internet # # Copyright (c) 2008-2024 The Eisfair Team, team(at)eisfair(dot)org # # Creation : 2012-02-13 jed # Last Update: $Id$ # # 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. #------------------------------------------------------------------------------ # read eislib etc. . /var/install/include/eislib . /var/install/include/check-eisfair-version #debug_fetch_icons=true if ${debug_fetch_icons:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi #------------------------------------------------------------------------------ # create list to rename png files #------------------------------------------------------------------------------ create_renamelist () { cat >${rename_file} < ${apache2tmpfile} . ${apache2tmpfile} rm -f ${apache2tmpfile} if [ -z "${CAPI2TEXT_WEB_ROOT}" ] then # use default c2t_web_root="${APACHE2_DOCUMENT_ROOT}/capi2text" else c2t_web_root="${CAPI2TEXT_WEB_ROOT}" fi if [ "${START_APACHE2}" = "yes" -a "${CAPI2TEXT_WEB_ACCESS}" = "yes" ] then c2t_web_active=1 fi else c2t_web_active=2 mecho --warn "Apache2 configuration couldn't be found!" fi rename_file=${c2t_web_root}/capi2text-rename-list cd ${c2t_web_root} # download archive mecho "- downloading flag archive '${icon_archive}' ..." # disable download of icon archive file in debug mode if [ "${debug_fetch_icons}" != 'true' ] then wget.sh -q -P ${c2t_web_root} ${icon_url} fi # check if archive exists if [ -f ${c2t_web_root}/${icon_archive} ] then mecho "- extracting files ..." # check of unzip exists if [ -f ${unzip_bin} ] then # make sure that temporary directory doesn't exist if [ -d ${c2t_web_root}/png ] then rm -fr ${c2t_web_root}/png fi # extract files unzip -uq ${c2t_web_root}/${icon_archive} -d ${c2t_web_root} mecho "- removing unrequired files ..." # remove unrequired files and keep only files with size of 48x48px find ${c2t_web_root}/png/ | grep -E -v "^${c2t_web_root}/png/48|^${c2t_web_root}/png/$" | sort -r | while read fname do rm -fr "${fname}" done mecho "- renaming icon files ..." create_renamelist # rename all known flag files, listed in rename list cat ${rename_file} | while read line do sname=`echo ${line} | cut -d'|' -f1` ccode=`echo ${line} | cut -d'|' -f2` echo "${sname}" | grep -q "^#" if [ $? -eq 0 ] then # file comment out, delete it sname="`echo ${sname} | sed 's/^#//'`" # lookup complete file name fname=`find ${c2t_web_root}/png/48 -iname "${sname}*"` if [ -n "${fname}" ] then # delete unrequired file rm -f "${fname}" fi else # lookup complete file name fname=`find ${c2t_web_root}/png/48 -iname "${sname}*"` if [ -n "${fname}" -a -n "${ccode}" ] then # rename file mv "${fname}" ${c2t_web_root}/png/country-${ccode}.png fi fi done mecho "- setting access rights ..." chown -R ${apache_user} ${c2t_web_root}/png chgrp -R ${apache_group} ${c2t_web_root}/png chmod 0444 ${c2t_web_root}/png/*png # don't delete files and directory in debug mode if [ "${debug_fetch_icons}" != 'true' ] then # remove directory and including unknown flag files rm -fr "${c2t_web_root}/png/48" # remove icon archive file rm -f ${c2t_web_root}/${icon_archive} # remove list of know flag files (rename list) rm -f ${rename_file} fi mecho "- done." else mecho --error "- the unzip program '${unzip_bin}' cannot be found!" fi else mecho --error "- the archive '${c2t_web_root}/${icon_archive}' cannot be found!" fi else mecho mecho "- Download aborted by user!" fi #============================================================================== # end #============================================================================== exit 0