#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/webmail-remove-locale - remove additional locale # # Copyright (c) 2001-2011 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2005-06-26 jed # Last Update: $Id$ # # Usage: webmail-remove-locale [-debug] # - debug - show only content of gz-archive # # 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 . /var/install/include/jedlib #---------------------------------------------------------------------------- # create list of locales #---------------------------------------------------------------------------- create_locale_list () { for FNAME in $webmail_path/$locale_mask do disp_code=`basename "$FNAME"|cut -c1-5` inst=`basename "$FNAME"|sed -e 's/^.*filelist-//g' -e 's/.txt$//g'` code=`echo $disp_code|tr 'A-Z' 'a-z'` if [ $inst -eq ${_wminst} ] then echo "$inst:$code:$disp_code:$FNAME" fi done | sort > $tmpfile } #---------------------------------------------------------------------------- # print list of locales #---------------------------------------------------------------------------- print_locale_list () { # print header clrhome mecho -info "List installed locale(s)" mecho mecho -n "Path: " mecho -warn "$wm_root_path" mecho techo begin 2 15 25 techo row "" -info Code tty=`tty` row=6 while read line do _ifs="$IFS" IFS=: set -- $line wm_inst=$1 code="$2" disp_code="$3" IFS="$_ifs" # output data if [ "$code" = "de_de" -o "$code" = "en_us" ] then techo row "" $disp_code "(part of webmail package)" else techo row "" $disp_code fi row=`expr $row + 1` if [ "$act_pmode" = 'tty' ] then if [ $row -eq 21 ] then mecho mecho anykey <$tty # print header clrhome mecho -info "List locales" <$tty mecho techo row "" -info Code row=4 fi fi done < $tmpfile techo end mecho } #---------------------------------------------------------------------------- # print header # input : $1 - country code #---------------------------------------------------------------------------- print_header () { c_code=$1 clrhome mecho -info "Remove locale" mecho mecho -n "Path: " mecho -warn "$wm_root_path" mecho -n "Locale: " mecho -warn "$c_code" mecho } #---------------------------------------------------------------------------- # print list of document roots #---------------------------------------------------------------------------- print_docrootlist () { # print header clrhome mecho -info "List document root(s)" mecho techo begin 2 5 40 techo row "" -info "Nbr" -info "Document root" tty=`tty` row=4 idx=1 while [ $idx -le $WEBMAIL_N ] do eval docroot='$WEBMAIL_'${idx}_'DOCUMENT_ROOT' # output data techo row "" $idx $docroot row=`expr $row + 1` if [ "$act_pmode" = 'tty' ] then if [ $row -eq 21 ] then mecho mecho anykey <$tty # print header clrhome mecho -info "List document root(s)" <$tty mecho techo row "" -info "Nbr" -info "Document root" row=4 fi fi idx=`expr $idx + 1` done techo end mecho } #---------------------------------------------------------------------------- # select webmail instance #---------------------------------------------------------------------------- select_webmail_instance () { # extract document root grep -E "^START_WEBMAIL|^WEBMAIL_N|^WEBMAIL_._DOCUMENT_ROOT" ${webmailfile} > ${tmpfile2} . ${tmpfile2} if [ $WEBMAIL_N -gt 1 ] then # more than one document root have been defined print_docrootlist dr_exit=0 until [ $dr_exit -eq 1 ] do /var/install/bin/ask "Please select webmail instance (1-$WEBMAIL_N), (q)uit:" '' '+' > /tmp/ask.$$ rc=$? instance=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then rm $tmpfile exit 1 fi case $instance in q ) # quit dr_exit=1 ;; * ) # doc root if is_numeric $instance && [ "$instance" -ge 1 -a "$instance" -le $WEBMAIL_N ] then _wminst=$instance dr_exit=1 fi ;; esac done else # less or equal one document root has been defined _wminst=$WEBMAIL_N fi } #---------------------------------------------------------------------------- # remove installed locale #---------------------------------------------------------------------------- remove_locale () { # get document root eval wm_root_path=${testroot}'$WEBMAIL_'${_wminst}'_DOCUMENT_ROOT' clrhome mecho -info "Remove locale" mecho mecho -n "Path: " mecho -warn "$wm_root_path" mecho ccode='' u_exit=0 until [ $u_exit -eq 1 ] do if [ "$ccode" = "" -o "$ccode" = "l" ] then # read uname /var/install/bin/ask "Please enter locale (code) to remove, (l)ist or (q)uit:" '' '+' > /tmp/ask.$$ rc=$? ccode=`cat /tmp/ask.$$|tr 'A-Z' 'a-z'` rm -f /tmp/ask.$$ if [ $rc = 255 ] then rm $tmpfile exit 1 fi fi case $ccode in l ) # list locales print_locale_list ;; q ) # quit u_exit=1 ;; * ) # process locale cut -d: -f2 $tmpfile | grep -q "$ccode" if [ $? -eq 0 ] then display_ccode=`grep ":$ccode:" $tmpfile | cut -d: -f3` print_header $display_ccode if [ "$ccode" = "de_de" -o "$ccode" = "en_us" ] then mecho -info "The '$ccode' locale cannot be removed because it is part of the webmail package!" mecho ccode='' else /var/install/bin/ask "Remove locale" 'n' > /tmp/ask.$$ rc=$? yesno=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then rm $tmpfile exit 1 fi if [ "$yesno" = "yes" ] then locale_file=`grep "^$ccode:" $tmpfile | cut -d: -f3` # remove files for FNAME in `cat $webmail_path/${display_ccode}-filelist-${_wminst}.txt` do rm -f -r "$wm_root_path/$FNAME" done # remove directories for DNAME in help locale do rm -f -r "$wm_root_path/$DNAME/$display_ccode" done # remove list file rm -f $webmail_path/$display_ccode-filelist-${_wminst}.txt mecho "The '$display_ccode' locale has successfully been removed!" fi u_exit=1 fi else if [ "$display_ccode" = "" ] then display_ccode="$ccode" fi mecho -warn "Locale '$display_ccode' doesn't exist!" ccode='' anykey fi ;; esac done } #============================================================================ # main #============================================================================ #testroot=/tmp/wm # only for testing testroot="" act_pmode=`get_printmode` base=`basename $0` tmpfile="/tmp/$base-$$" # set platform specific parameters case ${EISFAIR_SYSTEM} in eisfair-1) # eisfair-1 webmail_path=${testroot}/var/webmail ;; *) # default to eisfair-2/eisxen-1 webmail_path=${testroot}/data/packages/webmail ;; esac ### set file names #### webmailfile=/etc/config.d/webmail tmpfile2=/tmp/$base-$$ locale_mask='??_??-filelist*.txt' # look for locale files # da_DK-1.4.5rc1-20050616.tar.gz ls $webmail_path/$locale_mask > /dev/null 2> /dev/null if [ $? -eq 0 ] then select_webmail_instance if [ "$START_WEBMAIL" = "yes" -a ${_wminst} -gt 0 ] then create_locale_list remove_locale else # no webmail instance defined mecho -warn "The webmail package has not been activated or no webmail" mecho -warn "instance has been defined in the configuration file." mecho mecho -info "Please set START_WEBMAIL='yes' and WEBMAIL_N to a value greater than zero." fi else # no files found mecho -warn "No locale file has been found in $webmail_path!" fi rm -f ${tmpfile} rm -f ${tmpfile2} anykey #============================================================================ # end #============================================================================