home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #----------------------------------------------------------------------
- # NOM
- # tips = Gestionnaire d'astuces et d'informations a se souvenir.
- #
- # SYNTAXE
- # tips -h|H (aide)
- # tips [-c|X]
- #
- #----------------------------------------------------------------------
- # VERSION
- # 1.1
- #
- # DESCRIPTION
- # Permet de gerer des Tips (astuces, infos, trucs, etc.) pour conserver
- # les infos quotidiennes d'un adminstrateur Unix/Reseaux.
- #
- # Le plus pratique est de designer un repertoire ou seront enregistres
- # les Tips, ainsi il est possible de changer de base de Tips en donnant
- # uniquement le nom du fichier. La procedure se charge d'ajouter le Path.
- #
- # La page "Preferences" de la procedure permet de positionner certaines
- # variables generales comme : l'auteur, l'adresse Mail ou l'editeur de
- # saisie des Tips. Au sujet de l'editeur ASCII, par defaut la procedure
- # propose vi. Dans le cas ou vous souhaitez utiliser un autre editeur,
- # vous devez vous assurer que la commande qui l'execute ne rend pas la
- # "main" a la procedure (pas d'execution en background !). La procedure
- # effectue des traitements tout de suite apres la fin d'execution de
- # l'editeur, si l'editeur est lance en "background" les donnees que vous
- # aurez saisie ne seront pas prise en compte.
- #
- # Les importations de Tips concernent l'utilisation de fichier ASCII
- # issu d'un Mail. La procedure se charge d'extraire les informations en
- # supprimant les entetes et les fichiers attaches qui n'ont pas une
- # origine ASCII (binaire, archive compressee, etc.)
- #
- # L'utilisation de l'option -X offre la possibilite d'executer la
- # procedure dans une fenetre. Dans le cas ou les fenetres hpterm (HP)
- # et dtterm (CDE) sont accessibles, les menus sont affiches avec des
- # couleurs.
- #
- #
- # OPTIONS
- # -h|H aide courte ou longue.
- #
- # -c active le mode couleur, utilisable uniquement dans des
- # fenetres hpterm. Pour les autres fenetres, la procedure
- # utilise les codes tput connus.
- #
- # -X lance la procedure dans une fenetre dtterm, hpterm ou
- # xterm. La procedure effectue le choix automatiquement.
- #
- #
- # EXEMPLE(S)
- # * Lancement de l'application avec affichage de l'aide longue:
- # $ tips -H
- #
- # FICHIER(S)
- # $HOME/.Tips_rc Contient la sauvegarde des options.
- #
- # REMARQUE(S)
- # Procedure distribuee en Freeware/Gratuiciel.
- #
- # AUTEUR
- # Copyright (c) 1998 Bertrand LE QUELLEC, All Rigths Reserved.
- #
- # CONTACT
- # eMail : blq@mygale.org ou blq@wanadoo.fr
- # Url : http://www.mygale.org/09/blq/ ou http://perso.wanadoo.fr/blq/
- #
- # Cree : 04/02/98
- #----------------------------------------------------------------------
- # Permission to use, copy, modify, distribute, and sell this software
- # and its documentation for any purpose is hereby granted without fee,
- # provided that the above copyright notice appear in all copies and
- # that both that copyright notice and this permission notice appear in
- # supporting documentation, and that the name of Bertrand LE QUELLEC
- # not be used in advertising or publicity pertaining to distribution
- # of the software without specific, written prior permission. Bertrand
- # LE QUELLEC makes no representations about the suitability of
- # this software for any purpose. It is provided "as is" without
- # express or implied warranty.
- #
- # THIS SOFTWARE IS PROVIDED BY Bertrand LE QUELLEC `AS IS' AND ANY
- # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Bertrand LE QUELLEC BE
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- #----------------------------------------------------------------------
-
- # ------------------------------------------
- # ZONE DE DEFINITION DES VARIABLES GLOBALES:
- # ------------------------------------------
- NOM_PROCEDURE=`basename $0`
- LA_PROCEDURE=$0
- CD=`pwd`
- AWK=`[ -f /usr/bin/nawk ] && echo "nawk" || echo "awk" `
-
-
- ##
- ## Variables particulieres:
- ##
- DATE=`date "+%d/%m/%y"`
- MODE_COULEUR=0
- VISU_HTML=netscape
-
-
- ##
- ## Les variables concernant l'utilisateur:
- ##
- DEFAUT_AUTEUR=`whoami`
- DEFAUT_EDITEUR=${EDITOR}
- DEFAUT_SHELL=${SHELL}
-
-
- #----------------------------------------------------------------------
- # -----------------------------------------
- # ZONE DE DEFINITION DES FONCTIONS LOCALES:
- # -----------------------------------------
- # La fonction doit etre precedee d'un commentaire avec en debut de ligne
- # le caractere # (diese) repete deux fois.
-
- ##
- ## En cas d'une interruption la fonction suivante est executee.
- ## Les interruptions sont des signaux envoyes au processus du script,
- ## par la commande Unix: kill(1). La "capture" de ces signaux est
- ## identifiee par la commande Shell: trap definie apres la zone des
- ## options.
- ##
- TrapInterrup()
- {
- SauveRC
-
- # Vous pouvez executer des instructions avant une sortie
- # par signal (ou brutale!).
- exit 1
- }
-
-
- ##
- ## Renvoie le PATH et nom d'un ou plusieurs executables.
- ## Si le ou les executables sont introuvables la fonction ne renvoie rien.
- ## Dans le cas d'un alias la fonction ne renvoie rien, car le PATH n'est
- ## pas recuperable.
- ##
- Type()
- {
- [ $# -ne 0 ] && type $* | ${AWK} '$2=="is" && $4!="alias" {print $NF}'
- }
-
-
- ##
- ## Affiche l'aide indiquee en en-tete du script shell.
- ## Ne pas supprimer car cette fonction est utilisee a l'appel de la
- ## procedure avec les options -H ou -H
- ##
- AideProc()
- {
- fichier=$1
- niveau=$2
-
- echo "${NORMAL}"
-
- [ -z "$fichier" ] && {
- Erreur "AideProc(): nombre d'argument incorect."
- return 0
- }
-
- [ ! -f "$fichier" ] && {
- [ -f "`basename $fichier`" ] && fichier=`basename $fichier` || {
- Erreur "AideProc(): impossible d'atteindre le fichier $fichier."
- return 0
- }
- }
-
- [ ${niveau:=2} = 2 ] && {
- ${AWK} 'BEGIN {i=2}
- /^#[-]+/{
- if(--i<=0)exit
- next
- }
- /^#[ ]*[A-Z]*[ ]*$/{
- next
- }
- /^#[^!]/{
- print substr($0,1,80)
- }
- /^#[ \t]*$/{
- print ""
- }
- ' $fichier | sed -e 's/^#[ ]*//'
- } || {
- ${AWK} '\
- /^#[-]+/{
- if(--i<=0) exit
- next
- }
- /^#[^!]/{
- print substr($0,2,80)
- }
- /^#[ \t]*$/{
- print ""
- }
- ' i=$niveau $fichier | pg -e
- }
-
- sleep 3
- }
-
- ##
- ## Renvoie le type de la machine ou l'on se trouve et surtout le
- ## systeme d'exploitation en cours. La fonction renvoie un des numero
- ## suivant en reponse:
- ##
- ## inconue 0
- ##
- ## SunOs 1
- ## Sun Solaris 2
- ## HP s700 3
- ## HP s800 4
- ## HP s300 5
- ## Silicon Graphic 6
- ## IBM AIX 7
- ##
- ## Pour recuperer le code retour de la fonction, utilisez la variable $?
- ##
- Machine()
- {
- os=`uname`
-
- [ "$os" = "Solaris" ] && return 2
-
- [ "$os" = "SunOS" ] && {
- [ -f /vmunix ] && return 1 || return 2
- }
-
- [ "$os" = "HP-UX" ] && {
- if uname -a | grep "PA-RISC" 1> /dev/null
- then
- return 3
- elif uname -a | grep "HP-PA" 1> /dev/null
- return 4
- then
- return 5
- fi
- }
-
- [ "$os" = "IRIX" ] && return 6
-
- [ "$os" = "AIX" ] && return 7
-
- return 0
- }
-
-
- ##
- ## Affiche un message en rouge si l'on se trouve dans une fenetre hpterm
- ## et se met en attente de 2 secondes.
- ## Il est possible de recuperer le code retour de la fonction.
- ##
- Erreur()
- {
- [ $# -eq 0 ] && return -1
-
- echo "${NORMAL}\n\t${ROUGE}$*"
- sleep 2
-
- return 0
- }
-
-
- ##
- ## Permet de visualiser un fichier HTML avec le bon executable:
- ## netscape ou mosaic
- ##
- VoirHTML ()
- {
- fichier="$*"
-
- [ -z "$VISU_HTML" ] && VISU_HTML=mosaic
-
- chemin=`Type $VISU_HTML`
- [ -z "$chemin" ] && VISU_HTML=netscape
-
- chemin=`Type $VISU_HTML`
- [ -z "$chemin" ] && {
- Erreur "Executable du visualiseur HTML non accessible !"
- return 0
- }
-
- $VISU_HTML $fichier &
- return 1
- }
-
-
- #----------------------------------------------------------------------
- # ----------------------------------------------
- # DEFENITION DES VARIABLES LOCALES AU PROGRAMME:
- # ----------------------------------------------
-
- OPEN_TIPS=" @>@>"
- CLOSE_TIPS="<@<@"
-
- #----------------------------------------------------------------------
- # ----------------------------------------------
- # DEFENITION DES FONCTIONS LOCALES AU PROGRAMME:
- # ----------------------------------------------
-
- ##
- ## Renvoie le numero de Tips le plus grand
- ##
- MaxNumTips ()
- {
- fichier=$1
- [ -z "$fichier" ] && return 0
- [ ! -f "$fichier" ] && return 0
-
- max=`$AWK -F"No" ' BEGIN { max=0 }
- /^Tips No [0-9]*/{
- sub(sep_o, "", $0)
- if (max < $2) max=$2
- } END { printf("%d", max) }' sep_o="${OPEN_TIPS}" $fichier`
-
- return $max
- }
-
- ##
- ## Renvoie le nombre de Tips
- ##
- NbTips ()
- {
- fichier=$1
- [ -z "$fichier" ] && return 0
- [ ! -f "$fichier" ] && return 0
-
- nb=`$AWK ' BEGIN { nb=0 }
- /^Tips No [0-9]* /{
- nb=nb+1
- } END { printf("%d", nb) }' $fichier`
-
- return $nb
- }
-
- ##
- ## Met a jour les variables NB et MAX des Tips
- ##
- NbMaxTips()
- {
- NbTips ${SOURCE_TIPS}
- NB_TIPS=$?
- [ -z "$NB_TIPS" ] && NB_TIPS=0
-
- MaxNumTips ${SOURCE_TIPS}
- MAX_TIPS=$?
- [ -z "$MAX_TIPS" ] && MAX_TIPS=$NB_TIPS
- }
-
- ##
- ## Envoie d'un Tips par Mail
- ##
- MailTips()
- {
- titre_tips=$1
- fichier_tips=$2
- [ -z "$fichier_tips" ] && return 0
-
- echo "${NORMAL}
- Souhaitez-vous ditribuer le Tips par mail (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
-
- [ "${reponse:=n}" = "o" ] && {
- defaut=" [${VERT}${DISTRIB_TIPS}${NORMAL}] "
-
- echo "${NORMAL}
- Entrez l'adresse mail${defaut}: ${JAUNE}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse:=Q}" = Q -o "${reponse:=q}" = q ] && continue
- DISTRIB_TIPS="$reponse"
-
- SauveRC
-
- mail ${DISTRIB_TIPS} << ETIQ
- Subject:${titre_tips}
- From:${DEFAUT_AUTEUR} <${DEFAUT_MAIL}>
- 'cat $fichier_tips'
- ETIQ
- }
-
- return 1
- }
-
- ##
- ## Ecrit un Tips dans un fichier
- ##
- WriteTips()
- {
- num_tips=$1
- fichier_tips=$2
- [ -z "$fichier_tips" ] && return 0
-
- echo "
- Tips No ${num_tips}${OPEN_TIPS}
- LA_DATE=${LA_DATE}
- L_AUTEUR=\"${L_AUTEUR}\"
- LE_MAIL=\"${LE_MAIL}\"
- LE_TITRE=\"${LE_TITRE}\"
- L_OS=\"${L_OS}\"
- LA_MACHINE=\"${LA_MACHINE}\"
- LES_MOTS_CLEFS=\"${LES_MOTS_CLEFS}\"
- L_INFO=\"${L_INFO}\"
- ${CLOSE_TIPS}" > $fichier_tips
-
- return 1
- }
-
- ##
- ## Visualise un Tips apres demande du numeo
- ##
- VisuUnTips()
- {
- clear
- echo "${NORMAL}
- Entrez le numero du tips a visualiser : ${JAUNE}\c"
- read nb ; echo ${NORMAL}
- [ "${nb}" = Q -o "${nb}" = q ] && continue
-
- $AWK ' BEGIN {flag=0}
- {
- if ($0 == sep_c)
- {
- if (flag == 1) flag=0
- }
-
- if (flag == 1) print $0
- }
- /Tips/{
- if ($3 == num) flag=1
- }' num="$nb" sep_c="${CLOSE_TIPS}" ${SOURCE_TIPS} > /tmp/visu_tips$$
-
- chmod 777 /tmp/visu_tips$$
- . /tmp/visu_tips$$
- rm -f /tmp/visu_tips$$ > /dev/null
-
- echo "${NORMAL}
- ${INVERSE}${JAUNE}Titre : ${NORMAL} ${JAUNE}$LE_TITRE${NORMAL}
-
- Mots clefs : ${CYAN}$LES_MOT_CLEFS${NORMAL}
- Date de creation : ${CYAN}$LA_DATE${NORMAL}
- Auteur : ${CYAN}$L_AUTEUR${NORMAL}
- Mail auteur : ${CYAN}$LE_MAIL${NORMAL}
-
- OS/Version : ${VERT}$L_OS${NORMAL}
- Modele/Machine : ${VERT}$LA_MACHINE${NORMAL}
-
- ${INVERSE}${JAUNE}Descriptif du Tips : ${NORMAL}
-
- $L_INFO
-
- " | pg
-
- return 1
- }
-
- ##
- ## Sauvegarde le contenu des variables globales
- ## dans le fichier de ressources de l'utilisateur.
- ##
- SauveRC()
- {
- [ -f ${TIPS_RC} ] && cp -f ${TIPS_RC} ${TIPS_RC}.sav
-
- echo "
- #----------------------------------------------------------------------
- # VARIABLES GENERALES:
- # --------------------
- MAX_TIPS=\"${MAX_TIPS}\"
- NB_TIPS=\"${NB_TIPS}\"
- DISTRIB_TIPS=\"${DISTRIB_TIPS}\"
-
- #----------------------------------------------------------------------
- # REPERTOIRE DES FICHIERS TIPS:
- # ------------------------------
- REP_TIPS=\"${REP_TIPS}\"
- SOURCE_TIPS=\"${SOURCE_TIPS}\"
-
- #----------------------------------------------------------------------
- # LISTE DES VARIABLES GLOBALES CONCERNANT L'UTILISATEUR:
- # ------------------------------------------------------
- DEFAUT_AUTEUR=\"${DEFAUT_AUTEUR}\"
- DEFAUT_MAIL=\"${DEFAUT_MAIL}\"
- DEFAUT_EDITEUR=\"${DEFAUT_EDITEUR}\"
- " > ${TIPS_RC}
-
- chmod 777 ${TIPS_RC} 2> /dev/null
- }
-
- #----------------------------------------------------------------------
-
- #----------------------------------------------------------------------
- # -------------------------
- # RECUPERATION DES OPTIONS:
- # -------------------------
- set -- `getopt hHxMcX $*`
- for opt in $*
- do
- case $opt in
- -h) AideProc $LA_PROCEDURE ; exit 0 ;;
- -H) AideProc $LA_PROCEDURE 3 ; exit 0 ;;
-
- -x) set -x ; shift ;;
-
- -c) shift ; MODE_COULEUR=1;;
-
- -X) [ -x /usr/dt/bin/dtterm ] && LE_TERM="/usr/dt/bin/dtterm" || {
- [ -x /usr/bin/X11/hpterm ] && LE_TERM="/usr/bin/X11/hpterm" || LE_TERM=xterm
- }
-
- $LE_TERM -geometry 80x35 -ms red -cr red -fg white -bg black \
- -name $NOM_PROCEDURE \
- -title "$HOSTNAME - $NOM_PROCEDURE - $DEFAUT_USER" \
- -n $NOM_PROCEDURE -e $NOM_PROCEDURE -c &
- exit 0 ;;
-
- --) shift ; break ;;
- esac
- done
-
-
- #----------------------------------------------------------------------
- # AUTRES DEFINITIONS:
- # -------------------
- trap TrapInterrup 3 2 15 # Recuperation des interruptions 3, 2 et 15
-
- ##
- ## Caracteres speciaux valable uniquement sur HP:
- ## Permet d'obtenir de la couleur sur des fenetres hp-term.
- ##
- [ $MODE_COULEUR -eq 1 ] && {
- [ $TERM = "hpterm" ] && {
- BLANC="\033&v0S"; ROUGE="\033&v1S"; VERT="\033&v2S"; JAUNE="\033&v3S"
- BLEU="\033&v4S"; MAGENTA="\033&v5S"; CYAN="\033&v6S"; NOIR="\033&v7S"
- SOULIGNE="\033&dD"; INVERSE="\033&dB"; INVSOUS="\033&dF"; NORM="\033&d@"
- NORMAL=${NORM}${BLANC}
- } || {
- NOIR=`tput setaf 0 2> /dev/null`; ROUGE=`tput setaf 1 2> /dev/null`
- VERT=`tput setaf 2 2> /dev/null`; JAUNE=`tput setaf 3 2> /dev/null`
- BLEU=`tput setaf 4 2> /dev/null`; MAGENTA=`tput setaf 5 2> /dev/null`
- CYAN=`tput setaf 6 2> /dev/null`; BLANC=`tput setaf 7 2> /dev/null`
- SOULIGNE=`tput smul 2> /dev/null`; INVERSE=`tput smso 2> /dev/null`
- INVSOUS=${SOULIGNE}${INVERSE}; NORM=`tput sgr0 2> /dev/null`
- NORMAL=${NORM}${BLANC}
- }
- } || {
- NOIR=""; ROUGE=""
- VERT=""; JAUNE=""
- BLEU=""; MAGENTA=""
- CYAN=""; BLANC=""
- SOULIGNE=""; INVERSE=""; INVSOUS=""; NORM=""; NORMAL=""
- }
-
-
- #----------------------------------------------------------------------
- # DEBUT ZONE DU PROGRAMME:
- # ------------------------
- NB_TIPS=0
- MAX_TIPS=0
- TIPS_RC=$HOME/.Tips_rc
- SOURCE_TIPS=$HOME/MesTips
-
- [ -f "${TIPS_RC}" ] && . $TIPS_RC || SauveRC
- [ -z "$NB_TIPS" ] && NB_TIPS=0
- [ -z "$MAX_TIPS" ] && MAX_TIPS=0
-
- [ ! -f "$SOURCE_TIPS" ] && {
- MAX_TIPS=0
- NB_TIPS=0
- }
-
- [ "$MAX_TIPS" -gt 0 -a "$NB_TIPS" -eq 0 ] && {
- MAX_TIPS=0
- NbTips
- NB_TIPS=$?
- }
-
- [ "$NB_TIPS" -gt 0 -a "$MAX_TIPS" -eq 0 ] && {
- MaxNumTips
- MAX_TIPS=$?
- }
-
-
- ## ---------------------------------------------------------------------
- ##
- ## BOUCLE DU PREMIER MENU (PAGE 1):
- ##
- ## ---------------------------------------------------------------------
- while true
- do
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} GESTIONNAIRE DE TIPS ${NORMAL} ${INVERSE}${JAUNE} ${NB_TIPS} ${NORMAL}${INVERSE}${VERT} ${MAX_TIPS} ${NORMAL}
-
- ${INVERSE}${VERT} Variables par defaut ${NORMAL}
- Repertoire Tips : ${VERT}${REP_TIPS}${NORMAL}
- Fichier Tips : ${VERT}${SOURCE_TIPS}${NORMAL}
- Editeur : ${VERT}${DEFAUT_EDITEUR}${NORMAL}
- Auteur : ${VERT}${DEFAUT_AUTEUR}${NORMAL}
-
-
- ${INVERSE}${JAUNE} Menu principal ${NORMAL}
- h|H|help${JAUNE} .......... ${NORMAL}L'${JAUNE}aide${NORMAL} de la procedure.
- p|pref${JAUNE} ............ ${NORMAL}Affiche du menu ${JAUNE}Preferences${NORMAL}.
- o|open${JAUNE} ............ ${NORMAL}${ROUGE}Editer directement${NORMAL} le fichier des Tips.
-
- l|lst${JAUNE} ............. ${NORMAL}${JAUNE}Lister${NORMAL} les Tips.
- r|rech${JAUNE} ............ ${NORMAL}${JAUNE}Rechercher${NORMAL} un Tips.
-
- n|new${JAUNE} ............. ${NORMAL}${JAUNE}Nouveau${NORMAL} Tips.
- e|edit${JAUNE} ............ ${NORMAL}${JAUNE}Editer${NORMAL} un Tips.
- v|visu${JAUNE} ............ ${NORMAL}${JAUNE}Visualiser${NORMAL} un Tips.
-
- m|mail${JAUNE} ............ ${NORMAL}${JAUNE}Mail${NORMAL} un Tips.
- i|import${JAUNE} .......... ${NORMAL}${JAUNE}Importer${NORMAL} des Tips.
-
- q|quit${ROUGE} ............ Quitte${NORMAL} le programme.
-
-
- Votre choix : ${JAUNE}\c"
-
- read choix ; echo ${NORMAL}
- [ -z "$choix" ] && continue
-
- nom=""
- nb=`echo $choix | ${AWK} '{ print NF }'`
-
- [ $nb -gt 1 ] && {
- nom=`echo $choix | cut -f2 -d" "`
- choix=`echo $choix | cut -f1 -d" "`
- }
-
- clear
-
- case $choix in
- ## ------------------------------------------------------------
- [lL]|list)
- clear
-
- [ ${NB_TIPS} -le 0 ] && {
- Erreur "Aucun Tips dans la base"
- continue
- }
-
- echo "\n ${INVERSE}${JAUNE} LISTE DES TIPS ${NORMAL}\n\n"
-
- $AWK -F= '
- /^Tips No/{
- sub(sep_o, "", $1)
- nb=$1
- }
- /^LE_TITRE/{
- gsub(/\"/, "", $2)
- printf("%s : %s %s %s\n", nb, jaune, $2, normal)
- }' sep_o="${OPEN_TIPS}" normal=${NORMAL} inverse=${INVERSE} jaune=${JAUNE} ${SOURCE_TIPS} | pg
-
-
- echo "${NORMAL}
- Souhaitez-vous visualiser un Tips (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse}" = Q -o "${reponse}" = q ] && continue
- [ "${reponse:=n}" = "o" ] && VisuUnTips
- ;;
-
- ## ------------------------------------------------------------
- [rR]|rech)
- ## ------------------------------------------------------------{
- ## MENU RECHERCHE (PAGE 3)
- ## ------------------------------------------------------------
- while true
- do
- clear
- echo "
- ${INVERSE}${CYAN} RECHERCHE DANS LES TIPS ${NORMAL}
-
- ${JAUNE}1${NORMAL}) Titre
- ${JAUNE}2${NORMAL}) Auteur
- ${JAUNE}3${NORMAL}) OS/Version
- ${JAUNE}4${NORMAL}) Modele/Machine
- ${JAUNE}5${NORMAL}) Mots clefs
- ${JAUNE}6${NORMAL}) Description
-
- q|Q${ROUGE} ...... ${NORMAL}Retour au menu principal.
-
- Votre choix : ${JAUNE}\c"
- read choix ; echo ${NORMAL}
-
- case $choix in
- ## ------------------------------------
- 1|2|3|4|5|6)
- echo "${NORMAL}
- Entrez l'information a rechercher : ${JAUNE}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse}" = Q -o "${reponse}" = q ] && continue
-
- clear
-
- $AWK -F= ' BEGIN {
- flagInfo=0
- flag=0
- leTitre=""
- leTips= ""
- printf("\n\n%s%s Liste des Tips repondant aux criteres de recherche %s\n\n", inv, jaune, normal)
- }
- /^Tips No/{
- if (flag == 1) printf("%s%s : %s %s %s \n", normal, leTips, jaune, leTitre, normal)
-
- sub(sep_o, "", $0)
- leTips=$0
- leTitre=""
- flag=0
- flagInfo=0
- }
- /^LA_DATE/{
- }
- /^L_AUTEUR/{
- if (recherche == 2 ) {
- if (index($2, info)) flag=1
- }
- }
- /^LE_MAIL/{
- }
- /^L_OS/{
- if (recherche == 3 ) {
- if (index($2, info)) flag=1
- }
- }
- /^LA_MACHINE/{
- if (recherche == 4 ) {
- if (index($2, info)) flag=1
- }
- }
- /^LES_MOTS_CLEFS/{
- if (recherche == 5 ) {
- if (index($2, info)) flag=1
- }
- }
- /^LE_TITRE/{
- gsub(/"/, "", $0)
- leTitre=$2
-
- if (recherche == 1 ) {
- if (index($2, info)) flag=1
- }
- }
- /^L_INFO/{
- if (recherche == 6 )
- flagInfo=1
- else
- flagInfo=0
- }
- {
- if (flagInfo == 1)
- {
- if (index($0, info)) flag=1
- }
- }
- 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
-
- echo "${NORMAL}
- Souhaitez-vous visualiser un Tips (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse}" = Q -o "${reponse}" = q ] && continue
- [ "${reponse:=n}" = "o" ] && VisuUnTips
- ;;
-
- ## ------------------------------------
- [qQ]*) break ;;
-
- ## ------------------------------------
- *) Erreur "Commande <$choix> inconnue !?" ;;
- esac
- done ;;
-
- ## ------------------------------------------------------------
- [nN]*)
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} Creation d'un nouveau Tips : ${NORMAL} [qQ] pour annuler
-
- Entrez le titre du Tips (${ROUGE}obligatoire${NORMAL}) : ${JAUNE}\c"
- read titre ; echo ${NORMAL}
- [ "${titre:=Q}" = Q -o "${titre:=q}" = q ] && continue
-
- echo "${NORMAL}
- Entrez l'OS concerne et sa version : ${JAUNE}\c"
- read os ; echo ${NORMAL}
- [ "${os}" = Q -o "${os}" = q ] && continue
-
- echo "${NORMAL}
- Entrez le constructeur
- et le modele de la machine : ${JAUNE}\c"
- read modele ; echo ${NORMAL}
- [ "${modele}" = Q -o "${modele}" = q ] && continue
-
- echo "${NORMAL}
- Entrez quelques mots clefs : ${JAUNE}\c"
- read mots ; echo ${NORMAL}
- [ "${mots}" = Q -o "${mots}" = q ] && continue
-
- $DEFAUT_EDITEUR /tmp/new_tips$$
-
- sleep 2
- MAX_TIPS=`expr $MAX_TIPS + 1`
- NB_TIPS=`expr $NB_TIPS + 1`
-
- LA_DATE=${DATE}
- L_AUTEUR=\"${DEFAUT_AUTEUR}\"
- LE_MAIL=\"${DEFAUT_MAIL}\"
- LE_TITRE=\"${titre}\"
- L_OS=\"${os}\"
- LA_MACHINE=\"${modele}\"
- LES_MOTS_CLEFS=\"${mots}\"
- L_INFO=\"`cat /tmp/new_tips$$`\"
-
- WriteTips ${MAX_TIPS} /tmp/new_tips$$
-
- cat /tmp/new_tips$$ >> $SOURCE_TIPS
-
- MailTips "${titre}" /tmp/new_tips$$
- rm -f /tmp/new_tips$$ > /dev/null
- ;;
-
-
- ## ------------------------------------------------------------
- [eE]|edit)
- clear
- echo "${NORMAL}
- Entrez le numero du tips a editer : ${JAUNE}\c"
- read nb ; echo ${NORMAL}
- [ "${nb}" = Q -o "${nb}" = q ] && continue
-
- $AWK ' BEGIN {flag=0}
- {
- if ($0 == sep_c) flag=0
- if (flag == 1) print $0
- }
- /Tips/{
- if ($3 == num) flag=1
- }' sep_c="${CLOSE_TIPS}" num="$nb" ${SOURCE_TIPS} > /tmp/modif_tips$$
-
- chmod 777 /tmp/modif_tips$$
- . /tmp/modif_tips$$
- rm -f /tmp/modif_tips$$ > /dev/null
-
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}
-
- Titre : ${JAUNE}$LE_TITRE${NORMAL}
- Souhaitez-vous le modifier (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse}" = Q -o "${reponse}" = q ] && continue
- [ "${reponse:=n}" = "o" ] && {
- echo $LE_TITRE > /tmp/modif_tips$$
- $DEFAUT_EDITEUR /tmp/modif_tips$$
- LE_TITRE=`cat /tmp/modif_tips$$`
- rm -f /tmp/modif_tips$$ > /dev/null
-
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
- }
-
- echo "${NORMAL}
- OS/Version : ${JAUNE}$L_OS
- Souhaitez-vous le modifier (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse}" = Q -o "${reponse}" = q ] && continue
- [ "${reponse:=n}" = "o" ] && {
- echo $L_OS > /tmp/modif_tips$$
- $DEFAUT_EDITEUR /tmp/modif_tips$$
- L_OS=`cat /tmp/modif_tips$$`
- rm -f /tmp/modif_tips$$ > /dev/null
-
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
- }
-
- echo "${NORMAL}
- Modele/Machine : ${JAUNE}$LA_MACHINE
- Souhaitez-vous le modifier (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse}" = Q -o "${reponse}" = q ] && continue
- [ "${reponse:=n}" = "o" ] && {
- echo $LA_MACHINE > /tmp/modif_tips$$
- $DEFAUT_EDITEUR /tmp/modif_tips$$
- LA_MACHINE=`cat /tmp/modif_tips$$`
- rm -f /tmp/modif_tips$$ > /dev/null
-
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
- }
-
- echo "${NORMAL}
- Mots clefs : ${JAUNE}$LES_MOTS_CLES
- Souhaitez-vous les modifier (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse}" = Q -o "${reponse}" = q ] && continue
- [ "${reponse:=n}" = "o" ] && {
- echo $LES_MOTS_CLEFS > /tmp/modif_tips$$
- $DEFAUT_EDITEUR /tmp/modif_tips$$
- LES_MOTS_CLEFS=`cat /tmp/modif_tips$$`
- rm -f /tmp/modif_tips$$ > /dev/null
-
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
- }
-
- echo "${NORMAL}
- Souhaitez-vous modifier le descriptif (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}n${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse}" = Q -o "${reponse}" = q ] && continue
- [ "${reponse:=n}" = "o" ] && {
- echo $L_INFO > /tmp/modif_tips$$
- $DEFAUT_EDITEUR /tmp/modif_tips$$
- L_INFO=`cat /tmp/modif_tips$$`
- rm -f /tmp/modif_tips$$ > /dev/null
-
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} Modification du Tips No ${JAUNE} $nb ${NORMAL}"
- }
-
- WriteTips $nb /tmp/edit_tips$$
-
- cp ${SOURCE_TIPS} ${SOURCE_TIPS}_sav
-
- $AWK ' BEGIN {flag=0}
- /Tips/{ if ($3 == num) exit 0 }
- { if (flag == 0) print $0
- }' num="$nb" ${SOURCE_TIPS} > ${SOURCE_TIPS}_1
-
- $AWK ' BEGIN {flag=0}
- /Tips/{
- if ($3 == num) flag=1
- }
- {
- if (flag == 2) print $0
-
- if {$0 == sep_c)
- {
- if (flag == 1) flag=2
- }
- }' sep_c="${CLOSE_TIPS}" num="$nb" ${SOURCE_TIPS} > ${SOURCE_TIPS}_2
-
- cat ${SOURCE_TIPS}_1 /tmp/edit_tips$$ ${SOURCE_TIPS}_2 > ${SOURCE_TIPS}_old
- cp ${SOURCE_TIPS}_old ${SOURCE_TIPS}
-
- MailTips "${LE_TITRE}" /tmp/edit_tips$$
- rm -f /tmp/edit_tips$$
- ;;
-
-
- ## ------------------------------------------------------------
- [vV]|visu) VisuUnTips ;;
-
- ## ------------------------------------------------------------
- [mM]|mail)
- clear
- echo "${NORMAL}
- Entrez le numero du tips a envoyer en Mail : ${JAUNE}\c"
- read nb ; echo ${NORMAL}
- [ "${nb}:=q" = Q -o "${nb}" = q ] && continue
-
- $AWK ' BEGIN {flag=0}
- {
- if ($0 == sep_c) flag=0
- if (flag == 1) print $0
- }
- /Tips/{
- if ($3 == num) flag=1
- }' sep_c="${CLOSE_TIPS}" num="$nb" ${SOURCE_TIPS} > /tmp/visu_tips$$
-
- MailTips "${LE_TITRE}" /tmp/visu_tips$$
- rm -f /tmp/visu_tips$$
- ;;
-
-
- ## ------------------------------------------------------------
- [iI]*)
- clear
- echo "${NORMAL}
- Entrez le chemin et le fichier Mail
- contenant le(s) tips a importer : ${JAUNE}\c"
-
- [ "${fichier}:=Q" = Q -o "${fichier}" = q ] && continue
- [ ! -f "${fichier}" ] && continue
-
- echo "${NORMAL}
- importation en cours ...\c"
-
- $AWK -F: ' BEGIN {first=0; flag=0
- tag_from=""
- tag_date=""
- tag_subject=""
- }
- /^From /{
- if (flag >= 2) printf("\"\n%s\n\n", sep_c)
-
- flag=1
- tag_from=""
- tag_date=""
- tag_subject=""
- num=num+1
- }
- /^From:/{
- if (flag==1) {
- sub(/ /, "", $2)
- tag_from=$2
- }
- }
- /^Date:/{
- if (flag==1) {
- sub(/ /, "", $2)
- tag_date=$2
- }
- }
- /^Subject:/{
- if (flag==1) {
- if(index($0, "Fwd:") || index($0, "Re")) {
- sub(/\]$/, "", $0)
- sub(/\[Fwd: /, "", $0)
- sub(/Re: /, "", $0)
- sub(/Subject:/, "", $0)
- sub(/ /, "", $2)
- tag_subject=$0
- }
- else {
- sub(/ /, "", $2)
- tag_subject=$2
- }
- }
- }
- /^Content-Transfer-Encoding:/{
- if (flag==1) {
- if (index($2, "7bit")) flag=2
- }
- else if (flag==2) {
- if (index($2, "7bit")) flag=3
- }
- else if (flag==3) {
- if (index($2, "base64")) flag=2
- }
- }
- {
- if (flag == 3) {
- gsub(/\=20/, "", $0)
- gsub(/\=$/, "", $0)
-
- gsub(/\=E0/, "a", $0)
- gsub(/\=E9/, "e", $0)
- gsub(/\=EA/, "e", $0)
-
- info=$0
-
- if (index($0, "=3D")) info=div
- if (index($0, "Content-")) info=div
- if (index($0, "X-Sun-")) info=div
- if (index($0, "X-Mozilla-")) info=div
- if (index($0, "X-dt")) info=div
- if (index($0, "--1ecd")) info=div
- if (index($0, "--4e86")) info=div
- if (index($0, "--5d31")) info=div
- if (index($0, "-=_NextPart")) info=div
-
- if (index($0, "Path: ")) info=div
- if (index($0, "Subject: ")) info=div
- if (index($0, "Message-ID: ")) info=div
- if (index($0, "References: ")) info=div
- if (index($0, "NNTP-")) info=div
- if (index($0, "X-Newsreader: ")) info=div
- if (index($0, "Xref: ")) info=div
- if (index($0, "Organization: ")) info=div
-
- if (info != div) {
- gsub(/"/, "\\\"", info)
-
- if (first == 1) {
- first=0
-
- printf("Tips No %d%s\n", num, sep_o)
- printf("LA_DATE=\"%s\"\n", tag_date)
- printf("L_AUTEUR=\"%s\"\n", tag_from)
- printf("LE_TITRE=\"%s\"\n", tag_subject)
- printf("L_INFO=\"%s", info)
- } else {
- printf("\n%s", info)
- }
- }
- }
- }
- /^Status:/{ first=1; flag=3 }
- END {
- if(flag==3) printf("\"\n%s\n\n", sep_c)
- }' div="###@@@" sep_o="${OPEN_TIPS}" sep_c="${CLOSE_TIPS}" num="${MAX_TIPS}" ${fichier} > /tmp/import_tips$$
-
- echo ".\c"
- [ -f "${SOURCE_TIPS}" ] && {
- echo ".\c"
- cp ${SOURCE_TIPS} ${SOURCE_TIPS}.old
-
- echo ".\c"
- cat ${SOURCE_TIPS}.old /tmp/import_tips$$ > ${SOURCE_TIPS}
- } || {
- echo ".\c"
- cp /tmp/import_tips$$ ${SOURCE_TIPS}
- }
-
- echo ".\c"
- SauveRC
-
- echo ".\c"
- NbMaxTips
-
- echo ".\c"
- #[ "$MAX_TIPS" -eq 0 && "$NUM_TIPS" -eq 0 ] && > ${SOURCE_TIPS}
-
- echo ".\c"
- rm -f /tmp/import_tips$$
- ;;
-
-
- ## ------------------------------------------------------------
- h*) clear; AideProc $LA_PROCEDURE ;;
- H*) clear; AideProc $LA_PROCEDURE 3 ;;
-
- ## ------------------------------------------------------------
- [pP]*)
-
- ## ------------------------------------------------------------{
- ## MENU OPTION (PAGE 2)
- ## ------------------------------------------------------------
- while true
- do
- clear
- echo "${NORMAL}
- ${INVERSE}${CYAN} Menu Preferences : modification des valeurs par defaut ${NORMAL}
-
- Nombre de Tips : ${INVERSE}${JAUNE} ${NB_TIPS} ${NORMAL}
- Numero de Tips le plus grand : ${INVERSE}${VERT} ${MAX_TIPS} ${NORMAL}
-
-
- m|mail${CYAN} ...... ${NORMAL}E-MAIL : ${CYAN}$DEFAUT_MAIL${NORMAL}
- a|auteur${CYAN} .... ${NORMAL}AUTEUR : ${CYAN}$DEFAUT_AUTEUR${NORMAL}
- e|editeur${CYAN} ... ${NORMAL}EDITEUR : ${CYAN}$DEFAUT_EDITEUR${NORMAL}
- f|fich${CYAN} ...... ${NORMAL}FICHIER : ${CYAN}$SOURCE_TIPS${NORMAL}
- r|rep${CYAN} ....... ${NORMAL}REPERTOIRE : ${CYAN}$REP_TIPS${NORMAL}
-
-
- o|open${CYAN} ...... ${NORMAL}${CYAN}Ouverture directe${NORMAL} du fichier des preferences.
- l|lst${CYAN} ....... ${NORMAL}${CYAN}Liste${NORMAL} des fichiers Tips du repertoire source.
-
- q|quit${ROUGE} ...... ${NORMAL}Retour au menu principal.
-
-
- Votre choix : ${CYAN}\c"
- read choix ; echo ${NORMAL}
-
- clear
- echo "${NORMAL}"
-
- case $choix in
- ## ------------------------------------
- mail|[mM]|1)
- echo "${NORMAL}\nNouvelle adresse : ${CYAN}\c"
- read choix ; echo ${NORMAL}
- [ "$choix:=q" = "q" -o "$choix" = "Q" ] && continue
-
- DEFAUT_MAIL="$choix"
- ;;
-
- ## ------------------------------------
- auteur|a|A|2)
- echo "${NORMAL}\n Nouvel auteur : ${CYAN}\c"
- read choix ; echo ${NORMAL}
- [ "$choix:=q" = "q" -o "$choix" = "Q" ] && continue
-
- DEFAUT_AUTEUR="$choix"
- ;;
-
- ## ------------------------------------
- [eE]*|3)
- echo "${NORMAL}\n Nouvel editeur : ${CYAN}\c"
- read choix ; echo ${NORMAL}
- [ "$choix:=q" = "q" -o "$choix" = "Q" ] && continue
-
- DEFAUT_EDITEUR="$choix"
- ;;
-
- ## ------------------------------------
- [fF]*|4)
- echo ""
- defaut=" [${VERT}${SOURCE_TIPS}${NORMAL}] "
-
- [ ! -z "$REP_TIPS" ] && {
- ls -C $REP_TIPS
-
- [ -d "$REP_TIPS" -a "$REP_TIPS/`basename $SOURCE_TIPS`" = "$SOURCE_TIPS" ] && {
- defaut=" [${VERT}`basename ${SOURCE_TIPS}`${NORMAL}] "
- }
- }
-
- echo "${NORMAL}
- Entrez le fichier Tips a utiliser${defaut}: ${CYAN}\c"
- read choix ; echo ${NORMAL}
- [ -z "$choix" ] && {
- [ ! -z "$defaut" ] && choix="${SOURCE_TIPS}" || continue
- }
-
- [ "$choix" = "q" ] && continue
- [ "$choix" = "Q" ] && continue
-
- [ ! -z "$REP_TIPS" ] && {
- [ -d "$REP_TIPS" -a `echo ${choix} | grep -c "$REP_TIPS"` -eq 0 ] && choix="${REP_TIPS}/${choix}"
- }
-
- echo "
- Initialisation des variables...\c"
- SOURCE_TIPS="$choix"
- NbMaxTips
- ;;
-
- ## ------------------------------------
- [rR]*|5)
- defaut=" [${VERT}${REP_TIPS}${NORMAL}] "
- echo "${NORMAL}\n Repertoire des fichiers Tips${defaut}: ${CYAN}\c"
- read choix ; echo ${NORMAL}
- [ -z "$choix" ] && {
- [ ! -z "$defaut" ] && choix="${REP_TIPS}" || continue
- }
-
- [ "$choix" = "q" -o "$choix" = "Q" ] && continue
-
- [ ! -d "$choix" ] && {
- echo "${NORMAL}
- Le repertoire ${JAUNE}$choix${NORMAL} est inexistant.
- Souhaitez-vous le creer (${JAUNE}o${NORMAL}/${JAUNE}n${NORMAL}) ? [${VERT}o${NORMAL}] : ${VERT}\c"
- read reponse ; echo ${NORMAL}
- [ "${reponse:=o}" = "o" ] && mkdir $choix
- }
-
- [ -d "$choix" ] && REP_TIPS="$choix"
- ;;
-
- ## ------------------------------------
- [oO]|open|6) $DEFAUT_EDITEUR $TIPS_RC ; . $TIPS_RC ;;
-
- ## ------------------------------------
- [lL]*|7)
- [ -z "$REP_TIPS" ] && {
- Erreur "Le repertoire des Tips n'est pas designe."
- } || ls -C $REP_TIPS | pg
- ;;
-
- ## ------------------------------------
- [qQ]*) SauveRC ; break ;;
-
- ## ------------------------------------
- *) Erreur "Commande <$choix> inconnue !?" ;;
- esac
- done ;;
- ## --------------------------------------------------------------------}
-
- ## ------------------------------------------------------------
- [oO]|open)
- $DEFAUT_EDITEUR $SOURCE_TIPS
- NbMaxTips
- SauveRC
- ;;
-
- ## ------------------------------------------------------------
- [qQ]|quit*) flag=0 ; echo "${NORMAL} Fermeture de l'application en cours..."
- exit 0 ;;
-
- ## ------------------------------------------------------------
- *) Erreur "Commande <${NORMAL}$choix${ROUGE}> inconnue !?" ;;
- esac
- done