This assures, that it is always up to date, also if new dotpups were installed or other changes were made in /usr/share/applications.
However this is an unnecessary slowdown, if the menu did not change since the last restart.
So I added now some lines, that will check that.
If no change is detected, the fixmenus exits before it starts to fix anything.
It uses 2 checks, the size of /usr/share/applications reported by "du", and the number of chars counted by "ls".
This should be quite reliable.
The following code is from Puppy 301.
I also added a patch to keep JWMs theme, that otherwise is overwritten by fixmenus, and in the end I call another script that translates it.
The new code is called "patch2".
Mark
/usr/sbin/fixmenus
Code: Select all
#!/bin/sh
#v2.14 Puppy now has XDG menus.
#this script builds the menus from template files.
#Any templates can be placed into /etc/xdg/templates, and the file must be
#named to show its final destination. For example, the template for JWM:
# _root_.jwmrc
#...the '_' will be converted to a '/', so the generated JWM config file is:
# /root/.jwmrc
#-- patch by MU
theme=`grep '<Include>/root/.jwm/themes' /root/.jwmrc`
#-- patch2 by MU
oldsize=`cat ~/.oldxdg`
newsize=`ls /usr/share/applications | wc -c`
doit="0"
if [ "$oldsize" != "$newsize" ];then
doit="1"
fi
oldsize2=`cat ~/.oldxdg2`
newsize2=`du -b -s /usr/share/applications`
if [ "$oldsize2" != "$newsize2" ];then
doit="1"
fi
if [ "$doit" = "0" ];then
exit 0
fi
echo "$newsize" > ~/.oldxdg
echo "$newsize2" > ~/.oldxdg2
#sync
#-- end of patch2 by MU
#-- added by MU: display a message
xmessage -bg orange -center -borderless -buttons "" "rebuilding menus..." &
pid=$!
TEMPLATES="`ls -1 /etc/xdg/templates | tr '\n' ' '`"
for ONETPL in $TEMPLATES
do
[ "$ONETPL" = "README.txt" ] && continue
ONEDEST="`echo -n "$ONETPL" | sed -e 's/_/\//g'`"
ONESRC="/etc/xdg/templates/$ONETPL"
echo "Generating $ONEDEST..."
[ -f $ONEDEST ] && mv -f $ONEDEST ${ONEDEST}-previous
cat $ONESRC |
while read ONELINE
do
EXECMENU="`echo -n "$ONELINE" | grep -o 'PUPPYMENU.*' | cut -f 2-5 -d ' '`"
if [ "$EXECMENU" = "" ];then
echo "$ONELINE" >> $ONEDEST
else
${EXECMENU} >> ${ONEDEST}
fi
done
done
#-- patch by MU
sed -i -e "s#</JWM>#$theme\n</JWM>#" /root/.jwmrc
translate-menus
kill $pid
###END###