home *** CD-ROM | disk | FTP | other *** search
/ Freelog 9 / Freelog009.iso / BAS / Systeme / ShellUnix / TIPS.SH < prev    next >
Linux/UNIX/POSIX Shell Script  |  1998-07-09  |  36KB  |  1,296 lines

  1. #!/bin/sh
  2. #---------------------------------------------------------------------- 
  3. # NOM                                        
  4. #    tips = Gestionnaire d'astuces et d'informations a se souvenir.
  5. # SYNTAXE                                    
  6. #    tips -h|H          (aide)   
  7. #    tips [-c|X]
  8. #---------------------------------------------------------------------- 
  9. # VERSION
  10. #    1.1
  11. # DESCRIPTION
  12. #   Permet de gerer des Tips (astuces, infos, trucs, etc.) pour conserver
  13. #    les infos quotidiennes d'un adminstrateur Unix/Reseaux.
  14. #    Le plus pratique est de designer un repertoire ou seront enregistres
  15. #    les Tips, ainsi il est possible de changer de base de Tips en donnant
  16. #    uniquement le nom du fichier. La procedure se charge d'ajouter le Path.
  17. #     La page "Preferences" de la procedure permet de positionner certaines
  18. #    variables generales comme : l'auteur, l'adresse Mail ou l'editeur de
  19. #    saisie des Tips. Au sujet de l'editeur ASCII, par defaut la procedure
  20. #    propose vi. Dans le cas ou vous souhaitez utiliser un autre editeur,
  21. #    vous devez vous assurer que la commande qui l'execute ne rend pas la
  22. #    "main" a la procedure (pas d'execution en background !). La procedure
  23. #    effectue des traitements tout de suite apres la fin d'execution de
  24. #    l'editeur, si l'editeur est lance en "background" les donnees que vous
  25. #    aurez saisie ne seront pas prise en compte.
  26. #     Les importations de Tips concernent l'utilisation de fichier ASCII
  27. #    issu d'un Mail. La procedure se charge d'extraire les informations en
  28. #    supprimant les entetes et les fichiers attaches qui n'ont pas une
  29. #    origine ASCII (binaire, archive compressee, etc.)
  30. #     L'utilisation de l'option -X offre la possibilite d'executer la
  31. #    procedure dans une fenetre. Dans le cas ou les fenetres hpterm (HP)
  32. #    et dtterm (CDE) sont accessibles, les menus sont affiches avec des
  33. #    couleurs.
  34. # OPTIONS
  35. #    -h|H        aide courte ou longue.        
  36. #                                            
  37. #    -c          active le mode couleur, utilisable uniquement dans des
  38. #                fenetres hpterm. Pour les autres fenetres, la procedure
  39. #                 utilise les codes tput connus.
  40. #    -X          lance la procedure dans une fenetre dtterm, hpterm ou
  41. #                 xterm. La procedure effectue le choix automatiquement.
  42. #                                            
  43. #                                            
  44. # EXEMPLE(S)
  45. #    * Lancement de l'application avec affichage de l'aide longue:
  46. #        $ tips -H
  47. # FICHIER(S)
  48. #    $HOME/.Tips_rc        Contient la sauvegarde des options.
  49. #                                            
  50. # REMARQUE(S)
  51. #    Procedure distribuee en Freeware/Gratuiciel.
  52. #                                            
  53. # AUTEUR
  54. #     Copyright (c) 1998 Bertrand LE QUELLEC, All Rigths Reserved.
  55. # CONTACT
  56. #   eMail : blq@mygale.org ou blq@wanadoo.fr
  57. #   Url   : http://www.mygale.org/09/blq/ ou http://perso.wanadoo.fr/blq/
  58. #
  59. # Cree : 04/02/98
  60. #---------------------------------------------------------------------- 
  61. # Permission to use, copy, modify, distribute, and sell this software
  62. # and its documentation for any purpose is hereby granted without fee,
  63. # provided that the above copyright notice appear in all copies and
  64. # that both that copyright notice and this permission notice appear in
  65. # supporting documentation, and that the name of Bertrand LE QUELLEC    
  66. # not be used in advertising or publicity pertaining to distribution 
  67. # of the software without specific, written prior permission. Bertrand 
  68. # LE QUELLEC makes no representations about the suitability of
  69. # this software for any purpose. It is provided "as is" without
  70. # express or implied warranty.
  71. #
  72. # THIS SOFTWARE IS PROVIDED BY Bertrand LE QUELLEC `AS IS' AND ANY
  73. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  75. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Bertrand LE QUELLEC BE
  76. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  77. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  78. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  79. # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  80. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  81. # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  82. # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  83. #---------------------------------------------------------------------- 
  84.  
  85. # ------------------------------------------ 
  86. # ZONE DE DEFINITION DES VARIABLES GLOBALES:
  87. # ------------------------------------------
  88. NOM_PROCEDURE=`basename $0`
  89. LA_PROCEDURE=$0
  90. CD=`pwd`
  91. AWK=`[ -f /usr/bin/nawk ] && echo "nawk" || echo "awk" `
  92.  
  93.  
  94. ##
  95. ## Variables particulieres:
  96. ##
  97. DATE=`date "+%d/%m/%y"`
  98. MODE_COULEUR=0
  99. VISU_HTML=netscape
  100.  
  101.  
  102. ##
  103. ## Les variables concernant l'utilisateur:
  104. ##
  105. DEFAUT_AUTEUR=`whoami`
  106. DEFAUT_EDITEUR=${EDITOR}
  107. DEFAUT_SHELL=${SHELL}
  108.  
  109.  
  110. #---------------------------------------------------------------------- 
  111. # ----------------------------------------- 
  112. # ZONE DE DEFINITION DES FONCTIONS LOCALES:
  113. # -----------------------------------------
  114. # La fonction doit etre precedee d'un commentaire avec en debut de ligne
  115. # le caractere # (diese) repete deux fois.
  116.  
  117. ##
  118. ## En cas d'une interruption la fonction suivante est executee.
  119. ## Les interruptions sont des signaux envoyes au processus du script,
  120. ## par la commande Unix: kill(1). La "capture" de ces signaux est
  121. ## identifiee par la commande Shell: trap definie apres la zone des
  122. ## options.
  123. ##
  124. TrapInterrup()
  125. {
  126.     SauveRC
  127.  
  128.     # Vous pouvez executer des instructions avant une sortie 
  129.     # par signal (ou brutale!).
  130.     exit 1
  131. }
  132.  
  133.  
  134. ##
  135. ## Renvoie le PATH et nom d'un ou plusieurs executables.
  136. ## Si le ou les executables sont introuvables la fonction ne renvoie rien.
  137. ## Dans le cas d'un alias la fonction ne renvoie rien, car le PATH n'est
  138. ## pas recuperable.
  139. ##
  140. Type()
  141. {
  142.     [ $# -ne 0 ] && type $* | ${AWK} '$2=="is" && $4!="alias" {print $NF}'
  143. }
  144.  
  145.  
  146. ##
  147. ## Affiche l'aide indiquee en en-tete du script shell.
  148. ## Ne pas supprimer car cette fonction est utilisee a l'appel de la
  149. ## procedure avec les options -H ou -H
  150. ##
  151. AideProc()
  152. {
  153.     fichier=$1
  154.     niveau=$2
  155.  
  156.     echo "${NORMAL}"
  157.  
  158.     [ -z "$fichier" ] && {
  159.         Erreur "AideProc(): nombre d'argument incorect."
  160.         return 0
  161.     }
  162.  
  163.     [ ! -f "$fichier" ] && {
  164.         [ -f "`basename $fichier`" ] && fichier=`basename $fichier` || {
  165.             Erreur "AideProc(): impossible d'atteindre le fichier $fichier."
  166.             return 0
  167.         }
  168.     }
  169.  
  170.     [ ${niveau:=2} = 2 ] && {
  171.         ${AWK} 'BEGIN {i=2}
  172.             /^#[-]+/{
  173.                 if(--i<=0)exit
  174.                 next
  175.             }
  176.             /^#[     ]*[A-Z]*[     ]*$/{
  177.                 next
  178.             }
  179.             /^#[^!]/{
  180.                 print substr($0,1,80)
  181.             }
  182.             /^#[ \t]*$/{
  183.                 print ""
  184.             }
  185.         ' $fichier | sed -e 's/^#[     ]*//'
  186.     } || {
  187.         ${AWK} '\
  188.             /^#[-]+/{
  189.                 if(--i<=0) exit
  190.                 next
  191.             }
  192.             /^#[^!]/{
  193.                 print substr($0,2,80)
  194.             }
  195.             /^#[ \t]*$/{
  196.                 print ""
  197.             }
  198.         ' i=$niveau $fichier | pg -e
  199.     }
  200.  
  201.     sleep 3
  202. }
  203.  
  204. ##
  205. ## Renvoie le type de la machine ou l'on se trouve et surtout le
  206. ## systeme d'exploitation en cours. La fonction renvoie un des numero
  207. ## suivant en reponse:
  208. ##
  209. ##    inconue            0
  210. ##
  211. ##    SunOs                 1
  212. ##    Sun Solaris        2
  213. ##    HP s700            3
  214. ##    HP s800            4
  215. ##    HP s300            5
  216. ##    Silicon Graphic    6
  217. ##    IBM AIX            7
  218. ##
  219. ## Pour recuperer le code retour de la fonction, utilisez la variable $?
  220. ##
  221. Machine()
  222. {
  223.     os=`uname`
  224.  
  225.     [ "$os" = "Solaris" ] && return 2
  226.  
  227.     [ "$os" = "SunOS" ] && {
  228.         [ -f /vmunix ] && return 1 || return 2
  229.     }
  230.     
  231.     [ "$os" = "HP-UX" ] && {
  232.         if uname -a | grep "PA-RISC" 1> /dev/null
  233.         then
  234.             return 3
  235.         elif uname -a | grep "HP-PA" 1> /dev/null
  236.             return 4
  237.         then
  238.             return 5
  239.         fi
  240.     }
  241.  
  242.     [ "$os" = "IRIX" ] && return 6
  243.  
  244.     [ "$os" = "AIX" ] && return 7
  245.  
  246.     return 0
  247. }
  248.  
  249.  
  250. ##
  251. ## Affiche un message en rouge si l'on se trouve dans une fenetre hpterm
  252. ## et se met en attente de 2 secondes.
  253. ## Il est possible de recuperer le code retour de la fonction.
  254. ##
  255. Erreur()
  256. {
  257.     [ $# -eq 0 ] && return -1
  258.  
  259.     echo "${NORMAL}\n\t${ROUGE}$*"
  260.     sleep 2
  261.  
  262.     return 0
  263. }
  264.  
  265.  
  266. ##
  267. ## Permet de visualiser un fichier HTML avec le bon executable:
  268. ##    netscape ou mosaic
  269. ##
  270. VoirHTML ()
  271. {
  272.     fichier="$*"
  273.  
  274.     [ -z "$VISU_HTML" ] && VISU_HTML=mosaic
  275.  
  276.     chemin=`Type $VISU_HTML`
  277.     [ -z "$chemin" ] && VISU_HTML=netscape
  278.  
  279.     chemin=`Type $VISU_HTML`
  280.     [ -z "$chemin" ] && {
  281.         Erreur "Executable du visualiseur HTML non accessible !"
  282.         return 0
  283.     }
  284.  
  285.     $VISU_HTML $fichier &
  286.     return 1
  287. }
  288.  
  289.  
  290. #---------------------------------------------------------------------- 
  291. # ---------------------------------------------- 
  292. # DEFENITION DES VARIABLES LOCALES AU PROGRAMME:
  293. # ----------------------------------------------
  294.  
  295. OPEN_TIPS=" @>@>"
  296. CLOSE_TIPS="<@<@"
  297.  
  298. #---------------------------------------------------------------------- 
  299. # ---------------------------------------------- 
  300. # DEFENITION DES FONCTIONS LOCALES AU PROGRAMME:
  301. # ----------------------------------------------
  302.  
  303. ##
  304. ## Renvoie le numero de Tips le plus grand
  305. ##
  306. MaxNumTips ()
  307. {
  308.     fichier=$1
  309.     [ -z "$fichier" ] && return 0
  310.     [ ! -f "$fichier" ] && return 0
  311.  
  312.     max=`$AWK -F"No" ' BEGIN { max=0 }
  313.         /^Tips No [0-9]*/{
  314.             sub(sep_o, "", $0)
  315.             if (max < $2) max=$2
  316.         } END { printf("%d", max) }' sep_o="${OPEN_TIPS}" $fichier`
  317.  
  318.     return $max
  319. }
  320.  
  321. ##
  322. ## Renvoie le nombre de Tips
  323. ##
  324. NbTips ()
  325. {
  326.     fichier=$1
  327.     [ -z "$fichier" ] && return 0
  328.     [ ! -f "$fichier" ] && return 0
  329.  
  330.     nb=`$AWK ' BEGIN { nb=0 }
  331.         /^Tips No [0-9]* /{
  332.             nb=nb+1
  333.         } END { printf("%d", nb) }' $fichier`
  334.  
  335.     return $nb
  336. }
  337.  
  338. ##
  339. ## Met a jour les variables NB et MAX des Tips
  340. ##
  341. NbMaxTips()
  342. {
  343.     NbTips ${SOURCE_TIPS}
  344.     NB_TIPS=$?
  345.     [ -z "$NB_TIPS" ] && NB_TIPS=0
  346.  
  347.     MaxNumTips ${SOURCE_TIPS}
  348.     MAX_TIPS=$?
  349.     [ -z "$MAX_TIPS" ] && MAX_TIPS=$NB_TIPS
  350. }
  351.  
  352. ##
  353. ## Envoie d'un Tips par Mail
  354. ##
  355. MailTips()
  356. {
  357.     titre_tips=$1
  358.     fichier_tips=$2
  359.     [ -z "$fichier_tips" ] && return 0
  360.  
  361.     echo "${NORMAL}
  362.     Souhaitez-vous ditribuer le Tips par mail (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
  363.     read reponse ; echo ${NORMAL}
  364.  
  365.     [ "${reponse:=n}" = "o" ] && {
  366.         defaut=" [${VERT}${DISTRIB_TIPS}${NORMAL}] "
  367.  
  368.         echo "${NORMAL}
  369.     Entrez l'adresse mail${defaut}: ${JAUNE}\c"
  370.         read reponse ; echo ${NORMAL}
  371.         [ "${reponse:=Q}" = Q -o "${reponse:=q}" = q ] && continue
  372.         DISTRIB_TIPS="$reponse"
  373.  
  374.         SauveRC
  375.  
  376.         mail ${DISTRIB_TIPS} << ETIQ 
  377. Subject:${titre_tips}
  378. From:${DEFAUT_AUTEUR} <${DEFAUT_MAIL}>
  379. 'cat $fichier_tips'
  380. ETIQ
  381.     }
  382.  
  383.     return 1
  384. }
  385.  
  386. ##
  387. ## Ecrit un Tips dans un fichier
  388. ##
  389. WriteTips()
  390. {
  391.     num_tips=$1
  392.     fichier_tips=$2
  393.     [ -z "$fichier_tips" ] && return 0
  394.  
  395.     echo "
  396. Tips No ${num_tips}${OPEN_TIPS}
  397. LA_DATE=${LA_DATE}
  398. L_AUTEUR=\"${L_AUTEUR}\"
  399. LE_MAIL=\"${LE_MAIL}\"
  400. LE_TITRE=\"${LE_TITRE}\"
  401. L_OS=\"${L_OS}\"
  402. LA_MACHINE=\"${LA_MACHINE}\"
  403. LES_MOTS_CLEFS=\"${LES_MOTS_CLEFS}\"
  404. L_INFO=\"${L_INFO}\"
  405. ${CLOSE_TIPS}" > $fichier_tips
  406.  
  407.     return 1
  408. }
  409.  
  410. ##
  411. ## Visualise un Tips apres demande du numeo
  412. ##
  413. VisuUnTips()
  414. {
  415.     clear
  416.     echo "${NORMAL}
  417.     Entrez le numero du tips a visualiser : ${JAUNE}\c"
  418.     read nb ; echo ${NORMAL}
  419.     [ "${nb}" = Q -o "${nb}" = q ] && continue
  420.  
  421.     $AWK ' BEGIN {flag=0}
  422.         {
  423.             if ($0 == sep_c)
  424.             {
  425.                 if (flag == 1) flag=0
  426.             }
  427.  
  428.             if (flag == 1) print $0
  429.         }
  430.         /Tips/{
  431.             if ($3 == num) flag=1
  432.     }' num="$nb" sep_c="${CLOSE_TIPS}" ${SOURCE_TIPS} > /tmp/visu_tips$$
  433.  
  434.     chmod 777 /tmp/visu_tips$$
  435.     . /tmp/visu_tips$$
  436.     rm -f /tmp/visu_tips$$ > /dev/null
  437.  
  438.     echo "${NORMAL}
  439. ${INVERSE}${JAUNE}Titre            : ${NORMAL} ${JAUNE}$LE_TITRE${NORMAL}
  440.  
  441. Mots clefs       :  ${CYAN}$LES_MOT_CLEFS${NORMAL}
  442. Date de creation :  ${CYAN}$LA_DATE${NORMAL}
  443. Auteur           :  ${CYAN}$L_AUTEUR${NORMAL}
  444. Mail auteur      :  ${CYAN}$LE_MAIL${NORMAL}
  445.  
  446. OS/Version       :  ${VERT}$L_OS${NORMAL}
  447. Modele/Machine   :  ${VERT}$LA_MACHINE${NORMAL}
  448.  
  449. ${INVERSE}${JAUNE}Descriptif du Tips : ${NORMAL}
  450.  
  451. $L_INFO
  452.  
  453. " | pg
  454.  
  455.     return 1
  456. }
  457.  
  458. ##
  459. ## Sauvegarde le contenu des variables globales 
  460. ## dans le fichier de ressources de l'utilisateur.
  461. ##
  462. SauveRC()
  463. {
  464.     [ -f ${TIPS_RC} ] && cp -f ${TIPS_RC} ${TIPS_RC}.sav
  465.  
  466.     echo "
  467. #---------------------------------------------------------------------- 
  468. # VARIABLES GENERALES:
  469. # --------------------
  470. MAX_TIPS=\"${MAX_TIPS}\"
  471. NB_TIPS=\"${NB_TIPS}\"
  472. DISTRIB_TIPS=\"${DISTRIB_TIPS}\"
  473.  
  474. #---------------------------------------------------------------------- 
  475. # REPERTOIRE DES FICHIERS TIPS:
  476. # ------------------------------
  477. REP_TIPS=\"${REP_TIPS}\"
  478. SOURCE_TIPS=\"${SOURCE_TIPS}\"
  479.  
  480. #---------------------------------------------------------------------- 
  481. # LISTE DES VARIABLES GLOBALES CONCERNANT L'UTILISATEUR:
  482. # ------------------------------------------------------
  483. DEFAUT_AUTEUR=\"${DEFAUT_AUTEUR}\"
  484. DEFAUT_MAIL=\"${DEFAUT_MAIL}\"
  485. DEFAUT_EDITEUR=\"${DEFAUT_EDITEUR}\"
  486.     " > ${TIPS_RC}
  487.  
  488.     chmod 777 ${TIPS_RC} 2> /dev/null
  489. }
  490.  
  491. #---------------------------------------------------------------------- 
  492.  
  493. #---------------------------------------------------------------------- 
  494. # ------------------------- 
  495. # RECUPERATION DES OPTIONS:
  496. # -------------------------
  497. set -- `getopt hHxMcX $*`                
  498. for opt in $*                                            
  499. do                                                             
  500.     case $opt in                                           
  501.         -h) AideProc $LA_PROCEDURE    ; exit 0 ;;
  502.         -H) AideProc $LA_PROCEDURE 3  ; exit 0 ;;
  503.  
  504.         -x) set -x ; shift ;;
  505.  
  506.         -c) shift ; MODE_COULEUR=1;;
  507.  
  508.         -X) [ -x /usr/dt/bin/dtterm ] && LE_TERM="/usr/dt/bin/dtterm" || {
  509.                 [ -x /usr/bin/X11/hpterm ] && LE_TERM="/usr/bin/X11/hpterm" || LE_TERM=xterm
  510.             }
  511.  
  512.             $LE_TERM -geometry 80x35 -ms red -cr red -fg white -bg black \
  513.                 -name $NOM_PROCEDURE \
  514.                 -title "$HOSTNAME - $NOM_PROCEDURE - $DEFAUT_USER" \
  515.                 -n $NOM_PROCEDURE -e $NOM_PROCEDURE -c & 
  516.             exit 0 ;;
  517.  
  518.         --) shift ; break ;;
  519.     esac                                                        
  520. done                                                          
  521.  
  522.  
  523. #----------------------------------------------------------------------
  524. # AUTRES DEFINITIONS:
  525. # -------------------
  526. trap TrapInterrup 3 2 15    # Recuperation des interruptions 3, 2 et 15
  527.  
  528. ##
  529. ## Caracteres speciaux valable uniquement sur HP:
  530. ## Permet d'obtenir de la couleur sur des fenetres hp-term.
  531. ##
  532. [ $MODE_COULEUR -eq 1 ] && {
  533.     [ $TERM = "hpterm" ] && {
  534.         BLANC="\033&v0S"; ROUGE="\033&v1S"; VERT="\033&v2S"; JAUNE="\033&v3S"
  535.         BLEU="\033&v4S"; MAGENTA="\033&v5S"; CYAN="\033&v6S"; NOIR="\033&v7S"
  536.         SOULIGNE="\033&dD"; INVERSE="\033&dB"; INVSOUS="\033&dF"; NORM="\033&d@"
  537.         NORMAL=${NORM}${BLANC}
  538.     } || {
  539.         NOIR=`tput setaf 0 2> /dev/null`; ROUGE=`tput setaf 1 2> /dev/null`
  540.         VERT=`tput setaf 2 2> /dev/null`; JAUNE=`tput setaf 3 2> /dev/null`
  541.         BLEU=`tput setaf 4 2> /dev/null`; MAGENTA=`tput setaf 5 2> /dev/null`
  542.         CYAN=`tput setaf 6 2> /dev/null`; BLANC=`tput setaf 7 2> /dev/null`
  543.         SOULIGNE=`tput smul 2> /dev/null`; INVERSE=`tput smso 2> /dev/null`
  544.         INVSOUS=${SOULIGNE}${INVERSE}; NORM=`tput sgr0 2> /dev/null`
  545.         NORMAL=${NORM}${BLANC}
  546.     }
  547. } || {
  548.     NOIR=""; ROUGE=""
  549.     VERT=""; JAUNE=""
  550.     BLEU=""; MAGENTA=""
  551.     CYAN=""; BLANC=""
  552.     SOULIGNE=""; INVERSE=""; INVSOUS=""; NORM=""; NORMAL=""
  553. }
  554.  
  555.  
  556. #----------------------------------------------------------------------
  557. # DEBUT ZONE DU PROGRAMME:
  558. # ------------------------
  559. NB_TIPS=0
  560. MAX_TIPS=0
  561. TIPS_RC=$HOME/.Tips_rc
  562. SOURCE_TIPS=$HOME/MesTips
  563.  
  564. [ -f "${TIPS_RC}" ] && . $TIPS_RC || SauveRC
  565. [ -z "$NB_TIPS" ] && NB_TIPS=0
  566. [ -z "$MAX_TIPS" ] && MAX_TIPS=0
  567.  
  568. [ ! -f "$SOURCE_TIPS" ] && {
  569.     MAX_TIPS=0
  570.     NB_TIPS=0
  571. }
  572.  
  573. [ "$MAX_TIPS" -gt 0 -a "$NB_TIPS" -eq 0 ] && {
  574.     MAX_TIPS=0
  575.     NbTips
  576.     NB_TIPS=$?
  577. }
  578.  
  579. [ "$NB_TIPS" -gt 0 -a "$MAX_TIPS" -eq 0 ] && {
  580.     MaxNumTips
  581.     MAX_TIPS=$?
  582. }
  583.  
  584.  
  585. ## ---------------------------------------------------------------------
  586. ##
  587. ## BOUCLE DU PREMIER MENU (PAGE 1):
  588. ##
  589. ## ---------------------------------------------------------------------
  590. while true
  591. do
  592.     clear
  593.     echo "${NORMAL}
  594.         ${INVERSE}${CYAN} GESTIONNAIRE DE TIPS ${NORMAL} ${INVERSE}${JAUNE} ${NB_TIPS} ${NORMAL}${INVERSE}${VERT} ${MAX_TIPS} ${NORMAL}
  595.  
  596.  ${INVERSE}${VERT} Variables par defaut                                                         ${NORMAL}
  597.     Repertoire Tips : ${VERT}${REP_TIPS}${NORMAL}
  598.     Fichier Tips    : ${VERT}${SOURCE_TIPS}${NORMAL}
  599.     Editeur         : ${VERT}${DEFAUT_EDITEUR}${NORMAL}
  600.     Auteur          : ${VERT}${DEFAUT_AUTEUR}${NORMAL}
  601.  
  602.  
  603.  ${INVERSE}${JAUNE} Menu principal                                                               ${NORMAL}
  604.     h|H|help${JAUNE} .......... ${NORMAL}L'${JAUNE}aide${NORMAL} de la procedure.
  605.     p|pref${JAUNE} ............ ${NORMAL}Affiche du menu ${JAUNE}Preferences${NORMAL}.
  606.     o|open${JAUNE} ............ ${NORMAL}${ROUGE}Editer directement${NORMAL} le fichier des Tips.
  607.  
  608.     l|lst${JAUNE} ............. ${NORMAL}${JAUNE}Lister${NORMAL} les Tips.
  609.     r|rech${JAUNE} ............ ${NORMAL}${JAUNE}Rechercher${NORMAL} un Tips.
  610.  
  611.     n|new${JAUNE} ............. ${NORMAL}${JAUNE}Nouveau${NORMAL} Tips.
  612.     e|edit${JAUNE} ............ ${NORMAL}${JAUNE}Editer${NORMAL} un Tips.
  613.     v|visu${JAUNE} ............ ${NORMAL}${JAUNE}Visualiser${NORMAL} un Tips.
  614.  
  615.     m|mail${JAUNE} ............ ${NORMAL}${JAUNE}Mail${NORMAL} un Tips.
  616.     i|import${JAUNE} .......... ${NORMAL}${JAUNE}Importer${NORMAL} des Tips.
  617.  
  618.     q|quit${ROUGE} ............ Quitte${NORMAL} le programme.
  619.  
  620.  
  621.  Votre choix : ${JAUNE}\c"
  622.  
  623.     read choix ; echo ${NORMAL}
  624.     [ -z "$choix" ] && continue
  625.  
  626.     nom=""
  627.     nb=`echo $choix | ${AWK} '{ print NF }'`
  628.  
  629.     [ $nb -gt 1 ] && {
  630.         nom=`echo $choix | cut -f2 -d" "`
  631.         choix=`echo $choix | cut -f1 -d" "`
  632.     }
  633.  
  634.     clear
  635.  
  636.     case $choix in
  637.         ## ------------------------------------------------------------
  638.         [lL]|list)
  639.             clear
  640.  
  641.             [ ${NB_TIPS} -le 0 ] && {
  642.                 Erreur "Aucun Tips dans la base"
  643.                 continue
  644.             }
  645.  
  646.             echo "\n ${INVERSE}${JAUNE} LISTE DES TIPS ${NORMAL}\n\n"
  647.  
  648.             $AWK -F= '
  649.                 /^Tips No/{
  650.                     sub(sep_o, "", $1)
  651.                     nb=$1
  652.                 }
  653.                 /^LE_TITRE/{
  654.                     gsub(/\"/, "", $2)
  655.                     printf("%s : %s %s %s\n", nb, jaune, $2, normal)
  656.             }' sep_o="${OPEN_TIPS}" normal=${NORMAL} inverse=${INVERSE} jaune=${JAUNE} ${SOURCE_TIPS} | pg
  657.  
  658.  
  659.             echo "${NORMAL}
  660.     Souhaitez-vous visualiser un Tips (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
  661.             read reponse ; echo ${NORMAL}
  662.             [ "${reponse}" = Q -o "${reponse}" = q ] && continue
  663.             [ "${reponse:=n}" = "o" ] && VisuUnTips
  664.             ;;
  665.  
  666.         ## ------------------------------------------------------------
  667.         [rR]|rech)
  668. ## ------------------------------------------------------------{
  669. ##  MENU RECHERCHE (PAGE 3)
  670. ## ------------------------------------------------------------
  671. while true
  672. do
  673.             clear
  674.             echo "
  675.     ${INVERSE}${CYAN}  RECHERCHE DANS LES TIPS  ${NORMAL}
  676.  
  677.         ${JAUNE}1${NORMAL}) Titre
  678.         ${JAUNE}2${NORMAL}) Auteur
  679.         ${JAUNE}3${NORMAL}) OS/Version
  680.         ${JAUNE}4${NORMAL}) Modele/Machine
  681.         ${JAUNE}5${NORMAL}) Mots clefs
  682.         ${JAUNE}6${NORMAL}) Description
  683.  
  684.         q|Q${ROUGE} ...... ${NORMAL}Retour au menu principal.
  685.  
  686.     Votre choix : ${JAUNE}\c"
  687.     read choix ; echo ${NORMAL}
  688.  
  689.     case $choix in
  690.         ## ------------------------------------
  691.         1|2|3|4|5|6)
  692.             echo "${NORMAL}
  693.     Entrez l'information a rechercher : ${JAUNE}\c"
  694.             read reponse ; echo ${NORMAL}
  695.             [ "${reponse}" = Q -o "${reponse}" = q ] && continue
  696.     
  697.             clear
  698.  
  699.             $AWK -F= ' BEGIN {
  700.                     flagInfo=0
  701.                     flag=0
  702.                     leTitre=""
  703.                     leTips= ""
  704.                     printf("\n\n%s%s Liste des Tips repondant aux criteres de recherche %s\n\n", inv, jaune, normal)
  705.                 }
  706.                 /^Tips No/{
  707.                     if (flag == 1) printf("%s%s : %s %s %s \n", normal, leTips, jaune, leTitre, normal)
  708.  
  709.                     sub(sep_o, "", $0)
  710.                     leTips=$0
  711.                     leTitre=""
  712.                     flag=0
  713.                     flagInfo=0
  714.                 }
  715.                 /^LA_DATE/{
  716.                 }
  717.                 /^L_AUTEUR/{
  718.                     if (recherche == 2 ) {
  719.                         if (index($2, info)) flag=1 
  720.                     }
  721.                 }
  722.                 /^LE_MAIL/{
  723.                 }
  724.                 /^L_OS/{
  725.                     if (recherche == 3 ) {
  726.                         if (index($2, info)) flag=1 
  727.                     }
  728.                 }
  729.                 /^LA_MACHINE/{
  730.                     if (recherche == 4 ) {
  731.                         if (index($2, info)) flag=1 
  732.                     }
  733.                 }
  734.                 /^LES_MOTS_CLEFS/{
  735.                     if (recherche == 5 ) {
  736.                         if (index($2, info)) flag=1 
  737.                     }
  738.                 }
  739.                 /^LE_TITRE/{
  740.                     gsub(/"/, "", $0)
  741.                     leTitre=$2
  742.  
  743.                     if (recherche == 1 ) {
  744.                         if (index($2, info)) flag=1 
  745.                     }
  746.                 }
  747.                 /^L_INFO/{
  748.                     if (recherche == 6 )
  749.                         flagInfo=1
  750.                     else
  751.                         flagInfo=0
  752.                 }
  753.                 {
  754.                     if (flagInfo == 1)
  755.                     {
  756.                         if (index($0, info)) flag=1 
  757.                     }
  758.                 }
  759.                 END { if (flag == 1) printf("%s%s : %s %s %s \n", normal, leTips, jaune, leTitre, normal) }' sep_o="${OPEN_TIPS}" recherche="${choix}" info="${reponse}" normal="${NORMAL}" jaune="${JAUNE}" inv="${INVERSE}" ${SOURCE_TIPS} | pg
  760.  
  761.                 echo "${NORMAL}
  762.     Souhaitez-vous visualiser un Tips (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
  763.                 read reponse ; echo ${NORMAL}
  764.                 [ "${reponse}" = Q -o "${reponse}" = q ] && continue
  765.                 [ "${reponse:=n}" = "o" ] && VisuUnTips
  766.                 ;;
  767.  
  768.         ## ------------------------------------
  769.         [qQ]*) break ;;
  770.  
  771.         ## ------------------------------------
  772.         *) Erreur "Commande <$choix> inconnue !?" ;;
  773.     esac
  774. done ;;
  775.  
  776.         ## ------------------------------------------------------------
  777.         [nN]*)
  778.             clear
  779.             echo "${NORMAL}
  780.  ${INVERSE}${CYAN} Creation d'un nouveau Tips : ${NORMAL} [qQ] pour annuler
  781.  
  782.     Entrez le titre du Tips (${ROUGE}obligatoire${NORMAL}) : ${JAUNE}\c"
  783.             read titre ; echo ${NORMAL}
  784.             [ "${titre:=Q}" = Q -o "${titre:=q}" = q ] && continue
  785.  
  786.             echo "${NORMAL}
  787.     Entrez l'OS concerne et sa version : ${JAUNE}\c"
  788.             read os ; echo ${NORMAL}
  789.             [ "${os}" = Q -o "${os}" = q ] && continue
  790.  
  791.             echo "${NORMAL}
  792.     Entrez le constructeur 
  793.     et le modele de la machine : ${JAUNE}\c"
  794.             read modele ; echo ${NORMAL}
  795.             [ "${modele}" = Q -o "${modele}" = q ] && continue
  796.  
  797.             echo "${NORMAL}
  798.     Entrez quelques mots clefs : ${JAUNE}\c"
  799.             read mots ; echo ${NORMAL}
  800.             [ "${mots}" = Q -o "${mots}" = q ] && continue
  801.  
  802.             $DEFAUT_EDITEUR /tmp/new_tips$$
  803.             
  804.             sleep 2
  805.             MAX_TIPS=`expr $MAX_TIPS + 1`
  806.             NB_TIPS=`expr $NB_TIPS + 1`
  807.  
  808.             LA_DATE=${DATE}
  809.             L_AUTEUR=\"${DEFAUT_AUTEUR}\"
  810.             LE_MAIL=\"${DEFAUT_MAIL}\"
  811.             LE_TITRE=\"${titre}\"
  812.             L_OS=\"${os}\"
  813.             LA_MACHINE=\"${modele}\"
  814.             LES_MOTS_CLEFS=\"${mots}\"
  815.             L_INFO=\"`cat /tmp/new_tips$$`\"
  816.  
  817.             WriteTips ${MAX_TIPS} /tmp/new_tips$$
  818.  
  819.             cat /tmp/new_tips$$ >> $SOURCE_TIPS
  820.  
  821.             MailTips "${titre}" /tmp/new_tips$$
  822.             rm -f /tmp/new_tips$$ > /dev/null
  823.             ;;
  824.  
  825.  
  826.         ## ------------------------------------------------------------
  827.         [eE]|edit)
  828.             clear
  829.             echo "${NORMAL}
  830.     Entrez le numero du tips a editer : ${JAUNE}\c"
  831.             read nb ; echo ${NORMAL}
  832.             [ "${nb}" = Q -o "${nb}" = q ] && continue
  833.  
  834.             $AWK ' BEGIN {flag=0}
  835.                 {
  836.                     if ($0 == sep_c) flag=0
  837.                     if (flag == 1) print $0
  838.                 }
  839.                 /Tips/{
  840.                     if ($3 == num) flag=1
  841.             }' sep_c="${CLOSE_TIPS}" num="$nb" ${SOURCE_TIPS} > /tmp/modif_tips$$
  842.  
  843.             chmod 777 /tmp/modif_tips$$
  844.             . /tmp/modif_tips$$
  845.             rm -f /tmp/modif_tips$$ > /dev/null
  846.  
  847.             clear
  848.             echo "${NORMAL}
  849.  ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}
  850.  
  851.     Titre : ${JAUNE}$LE_TITRE${NORMAL}
  852.     Souhaitez-vous le modifier (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
  853.             read reponse ; echo ${NORMAL}
  854.             [ "${reponse}" = Q -o "${reponse}" = q ] && continue
  855.             [ "${reponse:=n}" = "o" ] && {
  856.                 echo $LE_TITRE > /tmp/modif_tips$$
  857.                 $DEFAUT_EDITEUR /tmp/modif_tips$$
  858.                 LE_TITRE=`cat /tmp/modif_tips$$`
  859.                 rm -f /tmp/modif_tips$$ > /dev/null
  860.  
  861.                 clear
  862.                 echo "${NORMAL}
  863.  ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
  864.             }
  865.  
  866.             echo "${NORMAL}
  867.     OS/Version : ${JAUNE}$L_OS
  868.     Souhaitez-vous le modifier (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
  869.             read reponse ; echo ${NORMAL}
  870.             [ "${reponse}" = Q -o "${reponse}" = q ] && continue
  871.             [ "${reponse:=n}" = "o" ] && {
  872.                 echo $L_OS > /tmp/modif_tips$$
  873.                 $DEFAUT_EDITEUR /tmp/modif_tips$$
  874.                 L_OS=`cat /tmp/modif_tips$$`
  875.                 rm -f /tmp/modif_tips$$ > /dev/null
  876.  
  877.                 clear
  878.                 echo "${NORMAL}
  879.  ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
  880.             }
  881.  
  882.             echo "${NORMAL}
  883.     Modele/Machine : ${JAUNE}$LA_MACHINE
  884.     Souhaitez-vous le modifier (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
  885.             read reponse ; echo ${NORMAL}
  886.             [ "${reponse}" = Q -o "${reponse}" = q ] && continue
  887.             [ "${reponse:=n}" = "o" ] && {
  888.                 echo $LA_MACHINE > /tmp/modif_tips$$
  889.                 $DEFAUT_EDITEUR /tmp/modif_tips$$
  890.                 LA_MACHINE=`cat /tmp/modif_tips$$`
  891.                 rm -f /tmp/modif_tips$$ > /dev/null
  892.  
  893.                 clear
  894.                 echo "${NORMAL}
  895.  ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
  896.             }
  897.  
  898.             echo "${NORMAL}
  899.     Mots clefs : ${JAUNE}$LES_MOTS_CLES
  900.     Souhaitez-vous les modifier (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
  901.             read reponse ; echo ${NORMAL}
  902.             [ "${reponse}" = Q -o "${reponse}" = q ] && continue
  903.             [ "${reponse:=n}" = "o" ] && {
  904.                 echo $LES_MOTS_CLEFS > /tmp/modif_tips$$
  905.                 $DEFAUT_EDITEUR /tmp/modif_tips$$
  906.                 LES_MOTS_CLEFS=`cat /tmp/modif_tips$$`
  907.                 rm -f /tmp/modif_tips$$ > /dev/null
  908.  
  909.                 clear
  910.                 echo "${NORMAL}
  911.  ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
  912.             }
  913.  
  914.             echo "${NORMAL}
  915.     Souhaitez-vous modifier le descriptif (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
  916.             read reponse ; echo ${NORMAL}
  917.             [ "${reponse}" = Q -o "${reponse}" = q ] && continue
  918.             [ "${reponse:=n}" = "o" ] && {
  919.                 echo $L_INFO > /tmp/modif_tips$$
  920.                 $DEFAUT_EDITEUR /tmp/modif_tips$$
  921.                 L_INFO=`cat /tmp/modif_tips$$`
  922.                 rm -f /tmp/modif_tips$$ > /dev/null
  923.  
  924.                 clear
  925.                 echo "${NORMAL}
  926.  ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
  927.             }
  928.  
  929.             WriteTips $nb /tmp/edit_tips$$
  930.  
  931.             cp ${SOURCE_TIPS} ${SOURCE_TIPS}_sav
  932.  
  933.             $AWK ' BEGIN {flag=0}
  934.                 /Tips/{ if ($3 == num) exit 0 }
  935.                 { if (flag == 0) print $0
  936.             }' num="$nb" ${SOURCE_TIPS} > ${SOURCE_TIPS}_1
  937.  
  938.             $AWK ' BEGIN {flag=0}
  939.                 /Tips/{
  940.                     if ($3 == num) flag=1 
  941.                 }
  942.                 {
  943.                     if (flag == 2) print $0
  944.  
  945.                     if {$0 == sep_c)
  946.                     {
  947.                         if (flag == 1) flag=2
  948.                     }
  949.             }' sep_c="${CLOSE_TIPS}" num="$nb" ${SOURCE_TIPS} > ${SOURCE_TIPS}_2
  950.  
  951.             cat ${SOURCE_TIPS}_1 /tmp/edit_tips$$ ${SOURCE_TIPS}_2 > ${SOURCE_TIPS}_old
  952.             cp ${SOURCE_TIPS}_old ${SOURCE_TIPS}
  953.  
  954.             MailTips "${LE_TITRE}" /tmp/edit_tips$$
  955.             rm -f /tmp/edit_tips$$
  956.             ;;
  957.  
  958.  
  959.         ## ------------------------------------------------------------
  960.         [vV]|visu) VisuUnTips ;;
  961.  
  962.         ## ------------------------------------------------------------
  963.         [mM]|mail)
  964.             clear
  965.             echo "${NORMAL}
  966.     Entrez le numero du tips a envoyer en Mail : ${JAUNE}\c"
  967.             read nb ; echo ${NORMAL}
  968.             [ "${nb}:=q" = Q -o "${nb}" = q ] && continue
  969.  
  970.             $AWK ' BEGIN {flag=0}
  971.                 {
  972.                     if ($0 == sep_c) flag=0
  973.                     if (flag == 1) print $0
  974.                 }
  975.                 /Tips/{
  976.                     if ($3 == num) flag=1
  977.             }' sep_c="${CLOSE_TIPS}" num="$nb" ${SOURCE_TIPS} > /tmp/visu_tips$$
  978.  
  979.             MailTips "${LE_TITRE}" /tmp/visu_tips$$
  980.             rm -f /tmp/visu_tips$$
  981.             ;;
  982.         
  983.  
  984.         ## ------------------------------------------------------------
  985.         [iI]*)
  986.             clear
  987.             echo "${NORMAL}
  988.   Entrez le chemin et le fichier Mail
  989.   contenant le(s) tips a importer : ${JAUNE}\c"
  990.  
  991.             [ "${fichier}:=Q" = Q -o "${fichier}" = q ] && continue
  992.             [ ! -f "${fichier}" ] && continue
  993.  
  994.             echo "${NORMAL}
  995.     importation en cours ...\c"
  996.  
  997.             $AWK -F: ' BEGIN {first=0; flag=0
  998.                     tag_from=""
  999.                     tag_date=""
  1000.                     tag_subject=""
  1001.                 }
  1002.                 /^From /{
  1003.                     if (flag >= 2) printf("\"\n%s\n\n", sep_c)
  1004.  
  1005.                     flag=1
  1006.                     tag_from=""
  1007.                     tag_date=""
  1008.                     tag_subject=""
  1009.                     num=num+1
  1010.                 }
  1011.                 /^From:/{
  1012.                     if (flag==1) {
  1013.                         sub(/ /, "", $2)
  1014.                         tag_from=$2
  1015.                     }
  1016.                 }
  1017.                 /^Date:/{
  1018.                     if (flag==1) {
  1019.                         sub(/ /, "", $2)
  1020.                         tag_date=$2
  1021.                     }
  1022.                 }
  1023.                 /^Subject:/{
  1024.                     if (flag==1) {
  1025.                         if(index($0, "Fwd:") || index($0, "Re")) {
  1026.                             sub(/\]$/, "", $0)
  1027.                             sub(/\[Fwd: /, "", $0)
  1028.                             sub(/Re: /, "", $0)
  1029.                             sub(/Subject:/, "", $0)
  1030.                             sub(/ /, "", $2)
  1031.                             tag_subject=$0
  1032.                         }
  1033.                         else {
  1034.                             sub(/ /, "", $2)
  1035.                             tag_subject=$2
  1036.                         }
  1037.                     }
  1038.                 }
  1039.                 /^Content-Transfer-Encoding:/{
  1040.                     if (flag==1) {
  1041.                         if (index($2, "7bit")) flag=2
  1042.                     }
  1043.                     else if (flag==2) {
  1044.                         if (index($2, "7bit")) flag=3
  1045.                     }
  1046.                     else if (flag==3) {
  1047.                         if (index($2, "base64")) flag=2
  1048.                     }
  1049.                 }
  1050.                 {
  1051.                     if (flag == 3) {
  1052.                         gsub(/\=20/, "", $0)
  1053.                         gsub(/\=$/, "", $0)
  1054.  
  1055.                         gsub(/\=E0/, "a", $0)
  1056.                         gsub(/\=E9/, "e", $0)
  1057.                         gsub(/\=EA/, "e", $0)
  1058.  
  1059.                         info=$0
  1060.  
  1061.                         if (index($0, "=3D")) info=div    
  1062.                         if (index($0, "Content-")) info=div    
  1063.                         if (index($0, "X-Sun-")) info=div    
  1064.                         if (index($0, "X-Mozilla-")) info=div    
  1065.                         if (index($0, "X-dt")) info=div    
  1066.                         if (index($0, "--1ecd")) info=div    
  1067.                         if (index($0, "--4e86")) info=div    
  1068.                         if (index($0, "--5d31")) info=div    
  1069.                         if (index($0, "-=_NextPart")) info=div    
  1070.  
  1071.                         if (index($0, "Path: ")) info=div    
  1072.                         if (index($0, "Subject: ")) info=div    
  1073.                         if (index($0, "Message-ID: ")) info=div    
  1074.                         if (index($0, "References: ")) info=div    
  1075.                         if (index($0, "NNTP-")) info=div    
  1076.                         if (index($0, "X-Newsreader: ")) info=div    
  1077.                         if (index($0, "Xref: ")) info=div    
  1078.                         if (index($0, "Organization: ")) info=div    
  1079.  
  1080.                         if (info != div) {
  1081.                             gsub(/"/, "\\\"", info)
  1082.  
  1083.                             if (first == 1) {
  1084.                                 first=0
  1085.  
  1086.                                 printf("Tips No %d%s\n", num, sep_o)
  1087.                                 printf("LA_DATE=\"%s\"\n", tag_date)
  1088.                                 printf("L_AUTEUR=\"%s\"\n", tag_from)
  1089.                                 printf("LE_TITRE=\"%s\"\n", tag_subject)
  1090.                                 printf("L_INFO=\"%s", info)
  1091.                             } else {
  1092.                                 printf("\n%s", info)
  1093.                             }
  1094.                         }
  1095.                     }
  1096.                 }
  1097.                 /^Status:/{ first=1; flag=3 }
  1098.             END {
  1099.                 if(flag==3) printf("\"\n%s\n\n", sep_c)
  1100.             }' div="###@@@" sep_o="${OPEN_TIPS}" sep_c="${CLOSE_TIPS}" num="${MAX_TIPS}" ${fichier} > /tmp/import_tips$$
  1101.  
  1102.             echo ".\c"
  1103.             [ -f "${SOURCE_TIPS}" ] && {
  1104.                 echo ".\c"
  1105.                 cp ${SOURCE_TIPS} ${SOURCE_TIPS}.old
  1106.                 
  1107.                 echo ".\c"
  1108.                 cat ${SOURCE_TIPS}.old /tmp/import_tips$$ > ${SOURCE_TIPS}
  1109.             } || {
  1110.                 echo ".\c"
  1111.                 cp /tmp/import_tips$$ ${SOURCE_TIPS}
  1112.             }
  1113.  
  1114.             echo ".\c"
  1115.             SauveRC
  1116.  
  1117.             echo ".\c"
  1118.             NbMaxTips
  1119.  
  1120.             echo ".\c"
  1121.             #[ "$MAX_TIPS" -eq 0  && "$NUM_TIPS" -eq 0 ] && > ${SOURCE_TIPS}
  1122.  
  1123.             echo ".\c"
  1124.             rm -f /tmp/import_tips$$
  1125.             ;;
  1126.  
  1127.  
  1128.         ## ------------------------------------------------------------
  1129.         h*) clear; AideProc $LA_PROCEDURE   ;;
  1130.         H*) clear; AideProc $LA_PROCEDURE 3 ;;
  1131.  
  1132.         ## ------------------------------------------------------------
  1133.         [pP]*) 
  1134.  
  1135. ## ------------------------------------------------------------{
  1136. ##  MENU OPTION (PAGE 2)
  1137. ## ------------------------------------------------------------
  1138. while true
  1139. do
  1140.     clear
  1141.     echo "${NORMAL}
  1142.  ${INVERSE}${CYAN} Menu Preferences : modification des valeurs par defaut ${NORMAL}
  1143.  
  1144.   Nombre de Tips                           : ${INVERSE}${JAUNE} ${NB_TIPS} ${NORMAL}
  1145.   Numero de Tips le plus grand             : ${INVERSE}${VERT} ${MAX_TIPS} ${NORMAL}
  1146.  
  1147.  
  1148.   m|mail${CYAN} ...... ${NORMAL}E-MAIL     : ${CYAN}$DEFAUT_MAIL${NORMAL}
  1149.   a|auteur${CYAN} .... ${NORMAL}AUTEUR     : ${CYAN}$DEFAUT_AUTEUR${NORMAL}
  1150.   e|editeur${CYAN} ... ${NORMAL}EDITEUR    : ${CYAN}$DEFAUT_EDITEUR${NORMAL}
  1151.   f|fich${CYAN} ...... ${NORMAL}FICHIER    : ${CYAN}$SOURCE_TIPS${NORMAL}
  1152.   r|rep${CYAN} ....... ${NORMAL}REPERTOIRE : ${CYAN}$REP_TIPS${NORMAL}
  1153.  
  1154.  
  1155.   o|open${CYAN} ...... ${NORMAL}${CYAN}Ouverture directe${NORMAL} du fichier des preferences.
  1156.   l|lst${CYAN} ....... ${NORMAL}${CYAN}Liste${NORMAL} des fichiers Tips du repertoire source.
  1157.  
  1158.   q|quit${ROUGE} ...... ${NORMAL}Retour au menu principal.
  1159.  
  1160.     
  1161.     Votre choix : ${CYAN}\c"
  1162.     read choix ; echo ${NORMAL}
  1163.  
  1164.     clear
  1165.     echo "${NORMAL}"
  1166.  
  1167.     case $choix in
  1168.         ## ------------------------------------
  1169.         mail|[mM]|1)
  1170.             echo "${NORMAL}\nNouvelle adresse : ${CYAN}\c"
  1171.             read choix ; echo ${NORMAL}
  1172.             [ "$choix:=q" = "q" -o "$choix" = "Q" ] && continue
  1173.     
  1174.             DEFAUT_MAIL="$choix"
  1175.             ;;
  1176.  
  1177.         ## ------------------------------------
  1178.         auteur|a|A|2)
  1179.             echo "${NORMAL}\n Nouvel auteur : ${CYAN}\c"
  1180.             read choix ; echo ${NORMAL}
  1181.             [ "$choix:=q" = "q" -o "$choix" = "Q" ] && continue
  1182.  
  1183.             DEFAUT_AUTEUR="$choix"
  1184.             ;;
  1185.  
  1186.         ## ------------------------------------
  1187.         [eE]*|3)
  1188.             echo "${NORMAL}\n Nouvel editeur : ${CYAN}\c"
  1189.             read choix ; echo ${NORMAL}
  1190.             [ "$choix:=q" = "q" -o "$choix" = "Q" ] && continue
  1191.  
  1192.             DEFAUT_EDITEUR="$choix"
  1193.             ;;
  1194.  
  1195.         ## ------------------------------------
  1196.         [fF]*|4)
  1197.             echo ""
  1198.             defaut=" [${VERT}${SOURCE_TIPS}${NORMAL}] "
  1199.  
  1200.             [ ! -z "$REP_TIPS" ] && {
  1201.                 ls -C $REP_TIPS
  1202.  
  1203.                 [ -d "$REP_TIPS" -a "$REP_TIPS/`basename $SOURCE_TIPS`" = "$SOURCE_TIPS" ] && {
  1204.                     defaut=" [${VERT}`basename ${SOURCE_TIPS}`${NORMAL}] "
  1205.                 }
  1206.             }
  1207.  
  1208.             echo "${NORMAL}
  1209.     Entrez le fichier Tips a utiliser${defaut}: ${CYAN}\c"
  1210.             read choix ; echo ${NORMAL}
  1211.             [ -z "$choix" ] && {
  1212.                 [ ! -z "$defaut" ] && choix="${SOURCE_TIPS}" || continue
  1213.             }
  1214.  
  1215.             [ "$choix" = "q" ] && continue
  1216.             [ "$choix" = "Q" ] && continue
  1217.  
  1218.             [ ! -z "$REP_TIPS" ] && {
  1219.                 [ -d "$REP_TIPS" -a `echo ${choix} | grep -c "$REP_TIPS"` -eq 0 ] && choix="${REP_TIPS}/${choix}"
  1220.             }
  1221.  
  1222.             echo "
  1223.     Initialisation des variables...\c"
  1224.             SOURCE_TIPS="$choix"
  1225.             NbMaxTips
  1226.             ;;
  1227.  
  1228.         ## ------------------------------------
  1229.         [rR]*|5)
  1230.             defaut=" [${VERT}${REP_TIPS}${NORMAL}] "
  1231.             echo "${NORMAL}\n Repertoire des fichiers Tips${defaut}: ${CYAN}\c"
  1232.             read choix ; echo ${NORMAL}
  1233.             [ -z "$choix" ] && {
  1234.                 [ ! -z "$defaut" ] && choix="${REP_TIPS}" || continue
  1235.             }
  1236.  
  1237.             [ "$choix" = "q" -o "$choix" = "Q" ] && continue
  1238.  
  1239.             [ ! -d "$choix" ] && {
  1240.                 echo "${NORMAL}
  1241.     Le repertoire ${JAUNE}$choix${NORMAL} est inexistant.
  1242.     Souhaitez-vous le creer (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}o${NORMAL}] : ${VERT}\c"
  1243.                 read reponse ; echo ${NORMAL}
  1244.                 [ "${reponse:=o}" = "o" ] && mkdir $choix
  1245.             }
  1246.  
  1247.             [ -d "$choix" ] && REP_TIPS="$choix"
  1248.             ;;
  1249.  
  1250.         ## ------------------------------------
  1251.         [oO]|open|6) $DEFAUT_EDITEUR $TIPS_RC ; . $TIPS_RC ;;
  1252.  
  1253.         ## ------------------------------------
  1254.         [lL]*|7)
  1255.             [ -z "$REP_TIPS" ] && {
  1256.                 Erreur "Le repertoire des Tips n'est pas designe."
  1257.             } || ls -C $REP_TIPS | pg
  1258.             ;;
  1259.  
  1260.         ## ------------------------------------
  1261.         [qQ]*) SauveRC ; break ;;
  1262.  
  1263.         ## ------------------------------------
  1264.         *) Erreur "Commande <$choix> inconnue !?" ;;
  1265.     esac
  1266. done ;;
  1267. ## --------------------------------------------------------------------}
  1268.  
  1269.         ## ------------------------------------------------------------
  1270.         [oO]|open)
  1271.             $DEFAUT_EDITEUR $SOURCE_TIPS
  1272.             NbMaxTips
  1273.             SauveRC
  1274.             ;;
  1275.  
  1276.         ## ------------------------------------------------------------
  1277.         [qQ]|quit*) flag=0 ; echo "${NORMAL} Fermeture de l'application en cours..."
  1278.             exit 0 ;;
  1279.  
  1280.         ## ------------------------------------------------------------
  1281.         *) Erreur "Commande <${NORMAL}$choix${ROUGE}> inconnue !?" ;;
  1282.     esac
  1283. done
  1284.