#!/bin/sh
OUT="/home/bobuse/.menu/added_by_menudrake"
\rm ${OUT}
touch ${OUT}
BASEDIR="/home/bobuse/.kde/share/applnk-mdk/"
CUSTOMDIR="BobuseMenu"
FLAGFIND="" # mode "en force : on efface le fichier, et on le reconstruit"
#FLAGFIND=" -cnewer ~/.menu/added_by_menudrake " # si on veut juste ajouter les lignes correspondantes à des rep/raccourcis plus recent que le fichier
# recup du param longtitle dans le .directory
LONGTITLE=`cat ${BASEDIR}${CUSTOMDIR}/.directory | gawk '{if (index($1,"Comment[fr]" )==1) print substr($1,13)}'`
# recup du param icon dans le .directory, avec ajout d'une extension png si pas d'extension
ICON=`cat ${BASEDIR}${CUSTOMDIR}/.directory | gawk '{if (index($1,"Icon=" )==1) {s=substr($1,6); if ((index(s,"png" )==0)&&(index(s,"xpm" )==0)) print s".png"; else print s;}}'`
# ajout de la ligne dans le fichier de conf
echo "?package(menu): needs=\"kde\" section=\"/\" title=\"${CUSTOMDIR}\" longtitle=\"${LONGTITLE}\" icon=\"${ICON}\" order=\"Internet\" charset=\"ISO-8859-15\"" >> ${OUT}
# bon la racine de noter repertoire perso est traitée passons aux sous-rep
# liste des sous-repertoires à mettre a jour
LISTEREP=`find /home/bobuse/.kde/share/applnk-mdk/BobuseMenu/ ${FLAGFIND} -type d | gawk '{ if (substr($0,length())!="/" ) print }'`
# le gawk sert a ne pas avoir "/home/bobuse/.kde/share/applnk-mdk/BobuseMenu/"
for d in ${LISTEREP}; do
BASENAME=`basename ${d}`
SECTION=`echo $d | gawk '{debut=index($0,"'${CUSTOMDIR}'" ); fin=index($0,"'${BASENAME}'" ); print substr($0,debut,fin-debut)}'`
LONGTITLE=`cat ${d}/.directory | gawk '{if (index($1,"Comment[fr]" )==1) print substr($1,13)}'`
ICON=`cat ${d}/.directory | gawk '{if (index($1,"Icon=" )==1) {s=substr($1,6); if ((index(s,"png" )==0)&&(index(s,"xpm" )==0)) print s".png"; else print s;} }'`
echo "?package(menu): needs=\"kde\" section=\"${SECTION}\" title=\"${BASENAME}\" longtitle=\"${LONGTITLE}\" icon=\"${ICON}\" charset=\"ISO-8859-15\"" >> ${OUT}
done
# mise à jour des fichiers
TMPFILE="/tmp/.$$"
\rm -f ${TMPFILE}
touch ${TMPFILE}
find /home/bobuse/.kde/share/applnk-mdk/BobuseMenu/ ${FLAGFIND} -type f -regex ".*/[^.][^/]*" > ${TMPFILE}
COUNT=`wc -l ${TMPFILE} | gawk '{print $1}'`
for i in `seq 1 ${COUNT}`; do
f=`cat ${TMPFILE}| gawk '{cpt++; if (cpt=='$i') print $0}'`
BASENAME=`basename "${f}" | gawk '{print $1}'`
SECTION=`echo "$f" | gawk '{ begin=index($0,"'${CUSTOMDIR}'" ); end=index($0,"'${BASENAME}'" ); print substr($0,begin,end-begin)}'`
TITLE=`cat "${f}" | gawk '{if (index($1,"Name=" )==1) print substr($1,6)}'`
COMMAND=`cat "${f}" | gawk '{if (index($1,"Exec=" )==1) print substr($1,6)}'`
ICON=`cat "${f}" | gawk '{if (index($1,"Icon=" )==1) { s=substr($1,6); if ((index(s,"png" )==0)&&(index(s,"xpm" )==0)) print s".png"; else print s;}}'`
#cat "${f}" | gawk '{if (index($1,"Icon=" )>0) { s=substr($1,6); if ((index(s,"png" )==0)&&(index(s,"xpm" )==0)) print s".png"; else print s;}}'
echo "?package(menu): needs=\"kde\" section=\"${SECTION}\" title=\"${TITLE}\" command=\"${COMMAND}\" icon=\"${ICON}\" charset=\"ISO-8859-15\"" >> ${OUT}
done
\rm ${TMPFILE}
|