Bei tiefen parse_filters with_objects mit prefix bauen.
[kivitendo-erp.git] / templates / f-tex / setup.sh
1 #!/bin/bash
2
3
4 # Setup script fuer die Nutzung der fancy-LaTeX Umgebung oder
5 # der Label-Print erweiterung (lp) in LX-Office-erp.
6 # Welches Setup ist von der Position innerhalb des Dateisystems abhaengig.
7 # Das Script kann auch nach erfolgtem Setup erneut aufgerufen werden
8
9 #   see  ./setup.sh -h
10
11
12
13
14
15 # Revision 0.2  (13.02.2011) add lp
16 #                            setup add determination of company data
17 # Revision 0.1  (19.12.2010) initial script create
18
19
20 # config
21
22 DB_AUTH='../../config/lx_office.conf'
23
24 FILE_LIST_FTEX='
25    letter.tex
26    sample.lco
27    sample_head.pdf
28    translations.tex
29    xstring.sty
30    zwischensumme.sty
31 '
32
33 FILE_LIST_LP='
34    label_abs_a7_de.tex
35    label_nn_brief_a4_de.tex
36    zweckform_3427.tdf
37    zweckform_3483.tdf
38 '
39
40
41 DOC_TYPE_FTEX='
42    invoice
43    proforma
44    sales_quotation
45    sales_order
46    sales_delivery_order
47    credit_note
48    pick_list
49    purchase_order
50 '
51
52
53 LXO_DETERMINE='
54    ../../SL/Form.pm
55    ../../config/lx_office.conf.default
56    ../../doc/changelog
57 '
58
59 CHK_RAWNUMBER_PATCH='
60    ../../SL/DO.pm
61    ../../SL/IS.pm
62    ../../SL/OE.pm
63 '
64
65 MY_DATA='
66   employeecountry
67   labelcompanyname
68   labelbankname
69   labelbankcode
70   labelbankaccount
71   MYfromname
72   MYaddrsecrow
73   MYrechtsform
74   MYfromaddress
75   MYfromphone
76   MYfromfax
77   MYfromemail
78   MYsignature
79   MYustid
80   MYfrombank
81 '
82
83 BASE_DIR=`readlink -f $0 | sed 's/setup\.sh$//'`
84
85 MODUL=`basename ${BASE_DIR}`
86 export TEXINPUTS=".:${BASE_DIR}:"
87
88 OK='...... [ok]'
89 MARK='\033[1;34m'
90 UNMARK='\033[0m'
91 TIME=`date +%s`
92
93 USAGE="\n\n  setup LaTeX templates for lx-office erp (www.lx-office.org)
94 \n\n  USAGE: ./`basename $0` [OPTION] \n
95 \n
96   -h print this Help\n
97 \n
98 \n
99   OPTIONS for trouble shooting:\n\n
100   -D don't connect to any database\n
101   -C no colored output (don't use any terminal escape character)\n
102 \n\n
103   RECOMMENDED USE ./setup.sh
104
105 \n
106 "
107
108 # script control
109
110 DATABASE=1
111
112 while getopts  "hDC" flag
113 do
114   case $flag in
115     h)
116        echo -e ${USAGE}
117        exit
118        ;;
119     D)
120        DATABASE=0
121        ;;
122     C)
123        NO_COLOR=1
124        ;;
125   esac
126 done
127
128 # Disclaim
129
130 cat << EOD
131
132    ##########################################################################
133    #                        Disclaimer                                      #
134    ##########################################################################
135    #                                                                        #
136    # Dies ist ein Script zum Einrichten von LaTeX Templates                 #
137    # (fancy-latex (f-tex)) oder (label-print (lp) fuer                      #
138    #                                                                        #
139    #      lx-office erp (www.lx-erp.org)                                    #
140    #                                                                        #
141    # Obwohl LX-Office sich an deutschsprachige Anwender richtet ist dieses  #
142    # Script in Englisch und soll auch nicht uebersetzt werden.              #
143    #                                                                        #
144    # * es richtet sich an System-Administratoren                            #
145    # * da es das Script nur in einer Sprache gibt, ist es viel leichter     #
146    #   bei Fehlern und Fehlermeldungen aus dem Script selbst, im Internet   #
147    #   nach Loesungen zu suchen.                                            #
148    #                                                                        #
149    ##########################################################################
150    #                                                                        #
151    # This script provides an easy to use setup for the fancy LaTeX          #
152    # environment of lx-office erp (templates/f-tex)                         #
153    #                                                                        #
154    # Normal use is to run ./setup.sh without any parameter. You may also    #
155    # check                                                                  #
156    #   ./setup.sh -h                                                        #
157    # for help.                                                              #
158    #                                                                        #
159    # The script tries to be as save as possible to avoid unwanted file      #
160    # overwriting by being very interactive. It's designed to be invoked     #
161    # multiple times inside the same template directory. So it is possible   #
162    # to rerun the script if there are updates available or after you break  #
163    # your LaTeX templates by any changes.                                   #
164    #                                                                        #
165    # I recommend to backup your installation and database before you run    #
166    # this script.                                                           #
167    #                                                                        #
168    # ANYHOW: I do not take responsibility for any harm initiated by this    #
169    #         script. (Wulf Coulmann -- scripts_at_gpl.coulmann.de)          #
170    #                                                                        #
171    ##########################################################################
172
173
174 EOD
175
176 QUESTION='  I understand the above warnings [YES/NO/Q]:'
177
178 echo -n "${QUESTION} "
179
180
181 [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
182 read ANSWER
183 [ "${NO_COLOR}" = 1 ] || echo -ne "${UNMARK}"
184
185
186 until [ "${ANSWER}" = YES ]\
187         || [ "${ANSWER}" = NO ] \
188         || [ "${ANSWER}" = N ] \
189         || [ "${ANSWER}" = n ] \
190         || [ "${ANSWER}" = q ] \
191         || [ "${ANSWER}" = Q ] ; do
192    echo -n "${QUESTION} "
193    [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
194    read ANSWER
195    [ "${NO_COLOR}" = 1 ] || echo -ne "${UNMARK}"
196 done
197
198 case ${ANSWER} in
199   YES)
200      echo -n '  accepted'
201   ;;
202   NO|n|N|q|Q)
203      echo
204      echo '  script aborted by user input'
205      exit 72
206   ;;
207 esac
208
209
210 FEEDBACK='################################\n  # FEEDBACK:\n
211 '
212
213
214 # load functions
215
216 function error {
217   echo '[error]' ...... $1 ...... '[terminate script]'
218   exit 72
219 }
220
221 function mark {
222   [ "${NO_COLOR}" = 1 ] || echo -ne "${MARK}"
223   echo -n "${1}"
224   [ "${NO_COLOR}" = 1 ] || echo -ne "${UNMARK}"
225 }
226
227
228
229 function ask_yn {
230   local QUESTION=$1
231   until [ "${ANSWER}" = y ]\
232           || [ "${ANSWER}" = Y ] \
233           || [ "${ANSWER}" = j ] \
234           || [ "${ANSWER}" = J ] \
235           || [ "${ANSWER}" = n ] \
236           || [ "${ANSWER}" = N ] \
237           || [ "${ANSWER}" = Q ] \
238           || [ "${ANSWER}" = q ] ; do
239      echo -n "${QUESTION}"
240      read ANSWER
241   done
242
243   case ${ANSWER} in
244     y|Y|j|J)
245        return
246     ;;
247     n|N)
248        return
249     ;;
250     q|Q)
251        [ "${NO_COLOR}" = 1 ] || echo -ne "${UNMARK}"
252        echo
253        echo '  script aborted by user input'
254        exit 72
255     ;;
256   esac
257 }
258
259 function latex_pack_check {
260   echo '  -> search LaTeX package '$1' '
261   echo -n '    '
262   if [ ! `kpsewhich ${1}.sty` ] ; then
263     echo
264     echo "  can't find package ${1}"
265     echo "  on debian systems you may install apt-file"
266     echo "     aptitude install apt-file"
267     echo "     apt-file update"
268     echo "     apt-file search ${1}.sty"
269     echo "  this will show which package contains the needet LaTeX .sty file"
270     echo "  on other systems, please refer to their documentation on how to "
271     echo "  find matching packages."
272     echo
273     echo "  If you are done, rerun this script"
274     echo " [unsatisfied dependencies]' ...... ${1} ...... [terminate script]"
275     exit 72
276   else
277     echo \ \ ${OK}
278   fi
279
280 }
281
282 function check_accepted_names {
283   echo '  -> check for suspect characters in '${2}
284   echo -n ${1} | egrep '[^-_\.!A-Za-z0-9]' && echo '  [suspect characters found] in ... '${2}' ... [terminate script]' && exit 72
285 }
286
287 function check_int {
288   echo '  -> check for suspect characters in '${2}
289   echo -n ${1} | egrep '[^0-9]' && echo '  [suspect characters found] in ... '${2}' ... [terminate script]' && exit 72
290 }
291
292 function create_file {
293   ANSWER=0
294   if [ "${1}" = ln  ] ;then
295     DO=1
296     echo -n '  -> try to create symbolic link '${3}
297     if [ -e "${3}" ] ; then
298       if [ -L "${3}" ] ; then
299          if [ "`ls -l ${3} | awk '{print $10}'`" = "${2}" ]; then
300            echo ' ...  symbolic link already exists, nothing to do!'
301            DO=0
302          else
303            echo ' ...  symbolic link with different target exist!'
304            ls -lah "${3}"
305            echo '  you may'
306            echo '      [d] delete and replace the current link'
307            echo '      [m] move current link to '${3}.${TIME}.old
308            echo '      [s] skip -- leave it as it is'
309            echo '      [q] abort setup.sh'
310            QUESTION='  what do do? [d/m/s/q]: '
311            echo  -en ${QUESTION}
312            [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
313            read ANSWER
314            [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
315            until [ "${ANSWER}" = D ] \
316                    || [ "${ANSWER}" = d ] \
317                    || [ "${ANSWER}" = m ] \
318                    || [ "${ANSWER}" = s ] \
319                    || [ "${ANSWER}" = q ] ; do
320               echo -n "${QUESTION}"
321               read ANSWER
322            done
323
324            case ${ANSWER} in
325              d)
326                 rm -f ${3}   || error ' unable to delete symbolic link '${3}
327              ;;
328              m)
329                 mv -f ${3} ${3}.${TIME}.old   || error ' unable to move symbolic link '${3}
330              ;;
331              s)
332                 echo '   as you decide, we leave it as it is!'
333                 DO=0
334              ;;
335              q)
336                 [ "${NO_COLOR}" = 1 ] || echo -ne "${UNMARK}"
337                 echo
338                 echo '  script aborted by user input'
339                 exit 72
340              ;;
341            esac
342          fi
343       else
344         echo ' ...  file already exists where I tried to create a symbolic link!'
345           ls -lah "${3}"
346           echo '  you may'
347           echo '      [S] show the file (exit file display with "q")'
348           echo '      [m] move current file to '${3}.${TIME}.old
349           echo '      [d] delete and replace the file with symbolic link'
350           echo '      [s] skip -- leave it as it is'
351           echo '      [q] abort setup.sh'
352           QUESTION='what to do? [S/d/m/s/q]:'
353           echo  -en "  ${QUESTION} "
354           [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
355           read ANSWER
356           [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
357           until [ "${ANSWER}" = S ] \
358                   || [ "${ANSWER}" = d ] \
359                   || [ "${ANSWER}" = m ] \
360                   || [ "${ANSWER}" = s ] \
361                   || [ "${ANSWER}" = q ] ; do
362              echo -n "  ${QUESTION} "
363              read ANSWER
364           done
365
366           case ${ANSWER} in
367             S)
368               echo
369               echo
370               less "${3}"
371               echo
372               echo
373               create_file "${1}" "${2}" "${3}"
374               return
375             ;;
376             m)
377                mv -f ${3} ${3}.${TIME}.old   || error ' unable to move file '${3}
378             ;;
379             d)
380                rm -f ${3}    || error ' unable to delete file '${3}
381             ;;
382             s)
383                echo '   as you decide, we leave it as it is!'
384                DO=0
385             ;;
386             q)
387                [ "${NO_COLOR}" = 1 ] || echo -ne "${UNMARK}"
388                echo
389                echo '  script aborted by user input'
390                exit 72
391             ;;
392           esac
393       fi
394     fi
395     if [ "${DO}" = "1" ] ;then  ln -s "${2}" "${3}" || error ' failed to create symbolic link '${3} ; fi
396     [ "${DO}" = "1" ] && echo \ \ ${OK}
397   fi
398
399   if [ "${1}" = cp  ] ;then
400     echo -n '  -> try to copy file '${3}
401        DO=1
402     if [ -e "${3}" ] ; then
403        echo ' ...  file already exists!'
404        diff "${2}" "${3}" >/dev/null
405        if [ "$?" = 0 ] ; then
406          echo '   files are equal, we leave it as it is!'
407          DO=0
408        else
409          ls -lah "${3}"
410          echo '  you may'
411          echo '      [D] show a diff between the new and current file'
412          echo '      [m] move current file to '${3}.${TIME}.old
413          echo '      [d] delete and replace with new file'
414          echo '      [s] skip -- leave it as it is'
415          echo '      [q] abort setup.sh'
416          QUESTION='what to do? [D/m/d/s/q]:'
417          echo  -en "  ${QUESTION} "
418          [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
419          read ANSWER
420          [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
421          until [ "${ANSWER}" = D ] \
422                  || [ "${ANSWER}" = d ] \
423                  || [ "${ANSWER}" = m ] \
424                  || [ "${ANSWER}" = s ] \
425                  || [ "${ANSWER}" = q ] ; do
426             echo -n "  ${QUESTION} "
427             read ANSWER
428          done
429
430          case ${ANSWER} in
431            D)
432              echo
433              echo
434              [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
435              echo '---------------------------------------'
436              [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
437              diff -C 3  "${2}" "${3}"
438              [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
439              echo '---------------------------------------'
440              [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
441              echo
442              echo
443              create_file "${1}" "${2}" "${3}"
444            ;;
445            m)
446               mv -f ${3} ${3}.${TIME}.old   || error ' unable to move file '${3}
447            ;;
448            d)
449               rm -f ${3}    || error ' unable to delete file '${3}
450            ;;
451            s)
452               echo '   as you decide, we leave it as it is!'
453               DO=0
454            ;;
455            q)
456               [ "${NO_COLOR}" = 1 ] || echo -ne "${UNMARK}"
457               echo
458               echo '  script aborted by user input'
459               exit 72
460            ;;
461          esac
462        fi
463     fi
464     if [ "${DO}" = "1" ] ;then  cp  "${2}" "${3}" || error ' failed to copy '${3} ; fi
465     [ "${DO}" = "1" ] && echo \ \ ${OK}
466   fi
467
468 }
469
470 function create_mydata {
471
472   VALUE=${1}
473   DB=${2}
474   NODATA='  did not get a value corresponding to your template dir'
475
476   SQL="
477     SELECT regexp_replace( u1.cfg_value, E'\n' ,E'\\\\\\\\\\\\' || E'\n')
478     FROM auth.user_config u1, auth.user_config u2
479     WHERE u1.user_id = u2.user_id
480       AND u1.cfg_key = '"${DB}"'
481       AND u2.cfg_key = 'templates'
482       AND u2.cfg_value = 'templates/"${TEMP_DIR}"'
483    ORDER BY u1.cfg_value  DESC
484    LIMIT 1;
485   "
486   case ${DB} in
487     tel)
488       PRE='Tel:'
489       ;;
490     fax)
491       PRE='fax:'
492       ;;
493     co_ustid)
494       if [ ! `psql --pset tuples_only -h "${PGHOST}" -U "${PGUSER}" "${PGDATABASE}" -c "${SQL}"`"" ] ; then
495         SQL="
496           SELECT regexp_replace( u1.cfg_value, E'\n' ,E'\\\\\\\\\\\\' || E'\n')
497           FROM auth.user_config u1, auth.user_config u2
498           WHERE u1.user_id = u2.user_id
499             AND u1.cfg_key = 'taxnumber'
500             AND u2.cfg_key = 'templates'
501             AND u2.cfg_value = 'templates/"${TEMP_DIR}"'
502          ORDER BY u1.cfg_value  DESC
503          LIMIT 1;
504         "
505         PRE='StNr.:'
506       else
507         PRE='UstIdNr:'
508       fi
509       ;;
510     *)
511       PRE=''
512       ;;
513     esac
514
515
516
517   if [ "${2}" ] ; then
518     ANSWER=`psql --pset tuples_only -h "${PGHOST}" -U "${PGUSER}" "${PGDATABASE}" -c "${SQL}"`  || error "unable to connect to auth db"
519     if [ ! "${VALUE}" ] ; then
520       echo '  please fix this later'
521       ANSWER=FIX_ME
522     else
523       echo '  found: '${ANSWER}
524     fi
525   else
526     if [ ! "${2}" ]  && [ ${1} = "employeecountry" ] ; then
527       read ANSWER
528     else
529       echo '  please fix this later'
530       ANSWER=FIX_ME
531     fi
532   fi
533
534   echo -e "\0134"'newcommand{'"\0134"${VALUE}'}{'${PRE}${ANSWER}'}' >> mydata.tex
535
536 }
537
538 function read_db_conf {
539
540   perl -e 'use Config::Std;
541            read_config "'${DB_AUTH}'.default" => my %config_default;
542            my $val_default = $config_default{"authentication/database"}{'${1}'};
543            read_config "'${DB_AUTH}'" => %config;
544            my $val =  $config{"authentication/database"}{'${1}'} if $config{"authentication/database"}{'${1}'};
545            if ( $val ) {
546               print $val;
547            }else{
548               print $val_default;
549            }'
550
551 }
552
553
554
555
556
557 # check for dependencies
558 echo  -n '  -> search kpsewhich '
559   which kpsewhich >/dev/null
560   [ "$?" = 0 ] || error 'unable find programm "kpsewhich" -- is there a propper installed LaTeX? (on debian: aptitude install texlive-base-bin)'
561   echo \ \ ${OK}
562
563 if [ "${MODUL}" = "f-tex" ] ; then
564   echo '  -> search LaTeX documentclass scrlttr2'
565   echo -n '    '
566   if [ ! `kpsewhich scrlttr2.cls` ] ; then
567     echo
568     echo "  can't find documentclass scrlttr2"
569     echo "  on debian systems you may install it by"
570     echo "     aptitude install texlive-latex-recommended"
571     echo "  on other systems, please refer to their documentation how to find"
572     echo "  matching packages."
573     echo
574     echo "  If you are done, rerun this script"
575     echo " [unsatisfied dependencies]' ...... documentclass scrlttr2 ...... [terminate script]"
576     exit 72
577   else
578     echo \ \ ${OK}
579   fi
580 elif [ "${MODUL}" = "lp" ] ; then
581   echo '  -> search LaTeX package ticket and check vor needed version '
582   echo -n '    '
583   HOLD_TEXINPUTS=${TEXINPUTS}
584   export TEXINPUTS=''
585   if [ `kpsewhich ticket.sty` ] ; then
586     grep rowmode `kpsewhich ticket.sty` > /dev/null
587     if [ "$?" -gt "0" ] ;then
588       FILE_LIST_LP=${FILE_LIST_LP}" ticket.sty"
589       echo \ \ "your version of LaTeX Package ticket does not support rowmode - we use our own ticket.sty"
590       echo \ \ \ \ \ \ "ticket.sty supports option rowmode from version v0.4b"
591       echo \ \ \ \ \ \ ${OK}
592     fi
593   else
594       FILE_LIST_LP=${FILE_LIST_LP}" ticket.sty"
595       echo \ \ "can't find LaTeX Package ticket, but we use our own ticket.sty because we need version => v0.4b"
596       echo \ \ \ \ \ \ "ticket.sty supports option rowmode from version v0.4b"
597       echo \ \ \ \ \ \ ${OK}
598   fi
599   export TEXINPUTS=${HOLD_TEXINPUTS}
600 else
601   error  "no valid install modul - is the install script inside ~/templates/f-tex or ~/templates/lp ?"
602 fi
603
604 for PACK in `grep usepackage ${BASE_DIR}/*.tex ${BASE_DIR}/*.sty ${BASE_DIR}/*.lco |awk -F '{' '{print $2}'|awk -F '}' '{print $1}'| sort | uniq`; do
605    latex_pack_check ${PACK}
606 done
607
608
609 # decide the installation target (template directory)
610 echo -n '  -> cd to base directory: '${BASE_DIR}' '
611
612   cd ${BASE_DIR} || error  "unable to change directory"
613   echo \ \ ${OK}
614
615
616
617 echo '  -> check if we are inside an lxo installation'
618
619 if [ ! -e ../../SL/Form.pm ] ; then
620
621   dpkg -l | grep lx-office-erp | egrep '^ii'
622   if [ "$?" = 0 ] ; then
623     echo '   seams like this is a Debian-package'
624     DB_AUTH='/etc/lx-office-erp/lx_office.conf'
625
626     LXO_DETERMINE='
627        /usr/lib/lx-office-erp/SL/Form.pm
628        /etc/lx-office-erp/lx_office.conf.default
629        /usr/share/doc/lx-office-erp/changelog
630     '
631
632     CHK_RAWNUMBER_PATCH='
633        /usr/lib/lx-office-erp/SL/DO.pm
634        /usr/lib/lx-office-erp/SL/IS.pm
635        /usr/lib/lx-office-erp/SL/OE.pm
636     '
637
638   fi
639
640 fi
641
642 for now in ${LXO_DETERMINE} ; do
643   [ -e ${now} ] || error 'missing '${now}', do not run this script outside an lx-office installation!. Is setup.sh located inside an lxo installation in templates/'${MODUL}'?'
644 done
645 echo \ \ ${OK}
646
647 if [ "${MODUL}" = "f-tex" ] ; then
648   echo   '  -> search raw numbers patch '
649      RAW_NUM=`egrep -oh '\{[^{]*_nofmt\}' ${CHK_RAWNUMBER_PATCH} |wc -l`
650
651      if [ "${RAW_NUM}" -lt 20 ] ; then
652        echo '  did not find the raw_number values'
653        echo
654        egrep -oh '\{[^{]*_nofmt\}' ${CHK_RAWNUMBER_PATCH}
655        echo '  seems like you added fancy LaTeX separate and needed raw_number values are missing'
656        echo '  this is already part of the dev-source code.'
657        echo '  please use this script in the environment you got it from'
658        error 'missing raw_number values'
659      fi
660     echo \ \ ${OK}
661 fi
662
663
664 if [ ${DATABASE} = 1 ] ; then
665
666   echo  '  -> request Auth-DB '
667     [ -r ${DB_AUTH} ] || [ -r ${DB_AUTH}.default ]  || error "unable to read ${DB_AUTH} or ${DB_AUTH}.default -- you must be able to read db credentials"
668
669     export PGDATABASE=`read_db_conf db`
670     check_accepted_names ${PGDATABASE} database_name
671     export PGPASSWORD=`read_db_conf password`
672     check_accepted_names ${PGPASSWORD} database_pw
673     export PGUSER=`read_db_conf user`
674     check_accepted_names ${PGUSER} database_user
675     export PGPORT=`read_db_conf port`
676     [ "${#PGPORT}" -lt 1 ] && PGPORT=5432
677     check_int ${PGPORT} database_port
678     export PGHOST=`read_db_conf host`
679     [ "${#PGHOST}" -lt 1 ] && PGHOST=localhost
680     check_accepted_names ${PGHOST} database_host
681
682     SQL="
683          SELECT
684            substring(cfg_value from E'[^/]*$') as template_dir
685          FROM auth.user_config
686          WHERE cfg_key = 'templates'
687          GROUP BY cfg_value ;
688     "
689
690
691   echo  '  -> search active template dirs '
692   echo
693   [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
694
695     psql --pset tuples_only -h "${PGHOST}" -U "${PGUSER}" "${PGDATABASE}" -c "${SQL}"  || error "unable to connect to auth db"
696
697   [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
698   echo  '  I found the above listed template directorys in '`mark '[lxo-home]/templates'`' by requesting your user configuration.'
699   echo  '  in database '`mark "${PGDATABASE}"`'.'
700 fi
701
702 echo  '  Type in which template directory to use (by typing in a name)'
703 echo  '  * if template_dir does not exist, it will be created'
704 echo  '  * template_dir must also be configured in your user administration'
705 echo  '    to make it active.'
706 echo
707 echo  -en '  type name of template dirctory: '
708 [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
709 read TEMP_DIR
710 [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
711
712
713 [ "${#TEMP_DIR}" -gt 0 ] || error 'no value for template dir provided '
714
715
716 if [ -d "../${TEMP_DIR}" ] ; then
717   MV_DIR=${TEMP_DIR}.${TIME}.old
718   echo
719   [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
720   ls -lah ../${TEMP_DIR}
721   [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
722   echo
723   echo '  the directory already exists and contains the above listed files'
724   echo '  you can:'
725   echo -e '    - move the directory to '`mark "templates/${MV_DIR}"`' and create a empty one, or'
726   echo '    - install the templates in the existing directory by interactive overwriting existing files'
727   echo
728   ask_yn '  move templates/'${TEMP_DIR}' to templates/'${MV_DIR}'? [y/n/q]: '
729
730
731
732   if [ "${ANSWER}" = y ] ; then
733      echo  '  -> check for permission to move template directory '
734      mv -i ../${TEMP_DIR} ../${MV_DIR} || error "unable to move directory "
735      echo -n '  -> original directory moved to '${MV_DIR}
736      echo \ \ ${OK}
737   fi
738   if [ "${ANSWER}" = n ] ; then
739      echo  '  -> check for permission to write in template directory [lxo-home]/templates/'${TEMP_DIR}
740      [ -w ../${TEMP_DIR} ] || error "no permission to write directory "
741      echo \ \ ${OK}
742   fi
743   ANSWER=0
744 fi
745
746
747 if [ ! -d "../${TEMP_DIR}" ] ; then
748   echo -n '  -> check for permission to create new template directory '
749       mkdir "../"${TEMP_DIR} || error "unable to write to `echo ${PWD} | sed 's/\/'${MODUL}'$//'` -- you must be able to write in ~/templates "
750   echo \ \ ${OK}
751   echo -n '  -> '${TEMP_DIR}' created'
752   echo \ \ ${OK}
753 fi
754
755 echo -n '  -> cd to template directory: '${TEMP_DIR}' '
756
757   cd ../${TEMP_DIR} || error  "unable to change directory"
758   echo \ \ ${OK}
759 pwd
760
761
762 if [ -e mydata.tex ] ;then
763   echo '  -> check mydata.tex'
764     grep koma ./mydata.tex && FEEDBACK=${FEEDBACK}'   # looks like a DEPRECATED mydata.tex -- please compare to f-tex/mydata.tex.example  \n'
765   for now in ${MY_DATA} ; do
766     grep ${now} ./mydata.tex || FEEDBACK=${FEEDBACK}'   # missing '${now}' in mydata.tex -- please compare to f-tex/mydata.tex.example  \n'
767   done
768
769   echo -e  \ \ "your current mydata.tex looks like"
770   [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
771   cat mydata.tex
772   [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
773
774 else
775   if [ ${DATABASE} = 1 ] ; then
776     # mydata voodooo goes here
777     SQL="
778       SELECT
779        u1.cfg_value as company,
780        u2.cfg_value as address,
781        u3.cfg_value as tel,
782        u4.cfg_value as fax,
783        u5.cfg_value as texnumber,
784        u6.cfg_value as co_ustid
785      FROM
786        auth.user_config u1,
787        auth.user_config u2,
788        auth.user_config u3,
789        auth.user_config u4,
790        auth.user_config u5,
791        auth.user_config u6
792      WHERE
793        u1.user_id = u2.user_id  and
794        u2.user_id = u3.user_id and
795        u3.user_id = u4.user_id and
796        u4.user_id = u5.user_id and
797        u5.user_id = u6.user_id and
798        u1.cfg_key = 'company' and
799        u2.cfg_key = 'address' and
800        u3.cfg_key = 'tel' and
801        u4.cfg_key = 'fax' and
802        u5.cfg_key = 'taxnumber' and
803        u6.cfg_key = 'co_ustid'
804      GROUP BY
805        u1.cfg_value,
806        u2.cfg_value,
807        u3.cfg_value,
808        u4.cfg_value,
809        u5.cfg_value,
810        u6.cfg_value
811      ORDER BY
812        company;
813     "
814 #    [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
815 #
816 #      psql -h "${PGHOST}" -U "${PGUSER}" "${PGDATABASE}" -c "${SQL}"  || error "unable to connect to auth db"
817 #
818 #    [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
819     echo  '  There is no mydata.tex, we try to create it'
820     echo  '  please answer the following questions'
821     echo -n '  - country your company is located eg:"Deutschland" : '
822     create_mydata employeecountry
823     echo  '  - owner of the bankaccount for label print'
824     echo  '    used for "pay on delivery (Nachnahme)"'
825     echo -n '    type ~ instead of blanks eg: "Herbert~Wichtig" : '
826     create_mydata labelcompanyname
827     echo  '  - name of the bank for label print'
828     echo  '    used for "pay on delivery (Nachnahme)"'
829     echo -n '    type ~ instad of blanks eg: "Ensifera~Bank" : '
830     create_mydata labelbankname
831     echo  '  - bank account number for label print'
832     echo  '    used for "pay on delivery (Nachnahme)"'
833     echo -n '    no blanks eg: "123456789" : '
834     create_mydata labelbankcode
835     echo  '  - bank code (BLZ) for label print'
836     echo  '    used for "pay on delivery (Nachnahme)'
837     echo -n '    no blanks eg: "10010010" : '
838     create_mydata labelbankaccount
839     echo  '  - company name for dokuments'
840     echo  '    used for invoice, sales_quotation, etc.'
841     echo -n '    eg: "Die globalen Problemlöser" : '
842     create_mydata MYfromname company
843     echo  '  - company name second row for documents'
844     echo  '    used for invoice, sales_quotation, etc.'
845     echo -n '    eg: "Gesellschaft für anderer Leute Sorgen mbH" : '
846     create_mydata MYaddrsecrow
847     echo  '  - legal form for documents'
848     echo  '    used for invoice, sales_quotation, etc.'
849     echo  '    eg: "Handelsregister: HRA 123456789" : '
850     echo -n '    or: "Inhaber Herbert Wichtig" : '
851     create_mydata MYrechtsform
852     echo  '  - company address for documents'
853     echo  '    used for invoice, sales_quotation, etc.'
854     echo  '    multirow, type \\ as row dilimiter '
855     echo -n '    eg: "Hauptstraße 5\\12345 Hier" : '
856     create_mydata MYfromaddress address
857     echo  '  - tel for documents'
858     echo  '    used for invoice, sales_quotation, etc.'
859     echo -n '    eg: "Tel: +49 (0)12 3456780" : '
860     create_mydata MYfromphone tel
861     echo  '  - fax for documents'
862     echo  '    used for invoice, sales_quotation, etc.'
863     echo -n '    eg: "Fax: +49 (0)12 3456781" : '
864     create_mydata MYfromfax fax
865     echo  '  - email for documents'
866     echo  '    used for invoice, sales_quotation, etc.'
867     echo -n '    eg: "mail@g-problemloeser.com" : '
868     create_mydata MYfromemail
869     echo  '  - signatur for documents'
870     echo  '    used for invoice, sales_quotation, etc.'
871     echo -n '    eg: "Herbert Wichtig - Geschäftsführer" : '
872     create_mydata MYsignature
873     echo  '  - tax number for documents'
874     echo  '    used for invoice, sales_quotation, etc.'
875     echo  '    it is common to use ustid but if you have none'
876     echo  '    type in your main tax number'
877     echo  '    eg: "UstID: DE 123 456 789" : '
878     echo -n '    or: "StrNr: 12/345/6789" : '
879     create_mydata MYustid co_ustid
880     echo  '  - bank account for documents'
881     echo  '    used for invoice, sales_quotation, etc.'
882     echo  '    multirow, type \\ as row delimiter '
883     echo -n '    eg: "Bankverbindung\\Ensifera Bank\\Kto 1234567800\\BLZ 123 456 78" : '
884     create_mydata MYfrombank
885
886      # damn escaping -- gnarf
887      perl -pi -e 's/([^\$\{])\\/$1\\\\/g' mydata.tex
888      perl -pi -e 's/([\&\%])/\\$1/g' mydata.tex
889   else
890     cp ../f-tex/mydata.tex.example mydata.tex
891     FEEDBACK=${FEEDBACK}'   # I generate a mydata.tex please edit this file to match to your needs \n'
892   fi
893     FEEDBACK=${FEEDBACK}'   # I generate a mydata.tex please edit this file to match to your needs \n'
894 fi
895
896
897 if [ "${MODUL}" = "f-tex" ] ; then
898   # search for installed languages
899   if [ ${DATABASE} = 1 ] ; then
900     SQL="
901     SELECT
902       u1.cfg_value || ';' ||
903       u2.cfg_value || ';' ||
904       u3.cfg_value || ';' ||
905       u4.cfg_value || ';' ||
906       u5.cfg_value
907     FROM
908       auth.user_config u1,
909       auth.user_config u2,
910       auth.user_config u3,
911       auth.user_config u4,
912       auth.user_config u5
913     WHERE
914       u1.user_id = u2.user_id  and
915       u2.user_id = u3.user_id and
916       u3.user_id = u4.user_id and
917       u4.user_id = u5.user_id and
918       u1.cfg_key = 'dbname' and
919       u2.cfg_key = 'dbhost' and
920       u3.cfg_key = 'dbport' and
921       u4.cfg_key = 'dbuser' and
922       u5.cfg_key = 'dbpasswd'
923     GROUP BY
924       u1.cfg_value,
925       u2.cfg_value,
926       u3.cfg_value,
927       u4.cfg_value,
928       u5.cfg_value;
929     "
930
931     echo  '  -> try to determine aktive languages ....'
932     echo  '  -> search database '${PGDATABASE}' to find lxo-erp databases ....'
933
934       DBS=`psql --pset tuples_only -h "${PGHOST}" -U "${PGUSER}" "${PGDATABASE}" -c "${SQL}"`  || error "unable to connect to auth db"
935
936     for db in ${DBS} ; do
937
938       PGDATABASE=`echo -n ${db} | awk -F ';' '{print $1}'`
939       echo -e '  -> prepare to request db '`mark ${PGDATABASE}`
940       check_accepted_names ${PGDATABASE} database_name
941       PGHOST=`echo -n ${db} | awk -F ';' '{print $2}'`
942       [ "${#PGHOST}" -lt 1 ] && PGHOST=localhost
943       check_accepted_names ${PGHOST} database_host
944       PGPORT=`echo -n ${db} | awk -F ';' '{print $3}'`
945       [ "${#PGPORT}" -lt 1 ] && PGPORT=5432
946       check_int ${PGPORT} database_port
947       PGUSER=`echo -n ${db} | awk -F ';' '{print $4}'`
948       check_accepted_names ${PGUSER} database_user
949       PGPASSWORD=`echo -n ${db} | awk -F ';' '{print $5}'`
950       check_accepted_names ${PGPASSWORD} database_pw
951       DELCHECK=`echo -n ${db} | awk -F ';' '{print $6}'`
952       [ "${#DELCHECK}" = 0 ] || error 'field delimiter conflict: there may be a ";" in one of your database definitions (db/host/port/user/pw)'
953       SQL="SELECT template_code FROM language ;"
954       echo \ \ ${OK}
955       RES=`psql --pset tuples_only -h "${PGHOST}" -U "${PGUSER}" "${PGDATABASE}" -c "${SQL}"`  || error "unable to connect to db "${PGDATABASE}
956       echo -e '  -> found '`mark "${RES}"`
957       echo \ \ ${OK}
958       LANGS=${LANGS}' '${RES}
959     done
960
961     LANGS=`echo ${LANGS} | sed 's/\ /\n/g'|sort | uniq`
962     echo '  -> join language codes ...'
963     echo
964     echo
965     [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
966     echo -e '    '${LANGS}
967     [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
968     echo
969     echo  '  I found the above listed language template_codes (see: System -> Languages -> List Languages)'
970     echo  '  - you may add more template_codes by type in a [space] seperated list (e.g.: ru it fr)'
971     echo  '  - or you may replace it with your own values by type in a [space] seperated list (e.g.: ru it fr)'
972     ask_yn '  add template_codes? [y/n/q]: '
973
974     if [ "${ANSWER}" = y ] ; then
975        echo -n '  type [space] seperated template_code list to add to current values: '
976        [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
977        read TMP_CO
978        [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
979        echo -n '  list of template_codes is now: '
980        LANGS=${LANGS}' '${TMP_CO}
981        [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
982        echo -e '    '${LANGS}
983        [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
984        echo \ \ ${OK}
985     fi
986     ANSWER=0
987
988     ask_yn '  replace the current template_codes? [y/n/q]: '
989
990     if [ "${ANSWER}" = y ] ; then
991        echo -n '  type [space] seperated template_code list to replace current values: '
992        [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
993        read TMP_CO
994        [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
995        echo -n '  list of template_codes is now: '
996        LANGS=${TMP_CO}
997        [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
998        echo -e '    '${LANGS}
999        [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
1000        echo \ \ ${OK}
1001     fi
1002     ANSWER=0
1003   else
1004      echo -n '  type [space] seperated template_code list (see: System -> Languages -> List Languages eg: de en fr): '
1005      [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
1006      read TMP_CO
1007      [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
1008      echo -n '  list of template_codes is now: '
1009      LANGS=${TMP_CO}
1010      [ "${NO_COLOR}" = 1 ] || echo -ne ${MARK}
1011      echo -e '    '${LANGS}
1012      [ "${NO_COLOR}" = 1 ] || echo -ne ${UNMARK}
1013      echo \ \ ${OK}
1014   fi
1015
1016   echo
1017   echo
1018   echo -e '  your current language template_codes are: '`mark "${LANGS}"`
1019   echo
1020   echo
1021
1022   # copy files and create links
1023
1024
1025
1026   for now in ${FILE_LIST_FTEX} ; do
1027     create_file cp ../f-tex/${now} ${now}
1028   done
1029
1030   for now in ${LANGS} ; do
1031     echo -n '  -> check if language code '${now}' is present in translations.tex'
1032     egrep '^[^%]*\\IfEndWith{\\docname}{_'${now}'}' translations.tex  > /dev/null
1033     if [ "$?" -gt 0 ] ;then
1034       HINT='  edit '${TEMP_DIR}'/translations.tex -- no representation of template_code '${now}
1035       echo '  [warning] '${HINT}
1036       FEEDBACK=${FEEDBACK}'   # '${HINT}'\n'
1037     fi
1038     echo \ \ ${OK}
1039   done
1040
1041
1042   for doc in ${DOC_TYPE_FTEX} ; do
1043     create_file ln  ./letter.tex ./${doc}.tex
1044     for now in ${LANGS} ; do
1045       create_file ln ./letter.tex  ./${doc}_${now}.tex
1046     done
1047   done
1048
1049   create_file ln  ./sample_head.pdf ./letter_head.pdf
1050   create_file ln  ./sample.lco ./letter.lco
1051
1052 fi
1053
1054
1055
1056 if [ "${MODUL}" = "lp" ] ; then
1057
1058   for now in ${FILE_LIST_LP} ; do
1059     create_file cp ../lp/${now} ${now}
1060   done
1061
1062 fi
1063
1064 echo
1065 echo
1066 echo -en ' '${FEEDBACK}
1067 echo -e ' ################################'
1068 echo
1069 echo '  If there are warnings listed in the feedback box above'
1070 echo '  this is totally ok if you know what you do'
1071 echo
1072 echo '  done -> enjoy'
1073 echo '  ### please check "settings" in '`pwd`'letter.lco '
1074
1075
1076 # company
1077 # address
1078 # co_ustid
1079 # email
1080 # taxnumber
1081 # tel
1082 # fax