Debian Menu for DSL


Forum: Apt-get
Topic: Debian Menu for DSL
started by: cbagger01

Posted by cbagger01 on May 23 2005,04:19
One of the things that I always liked about Debian and specifically Knoppix is this:

If you added a new program via apt-get, dpkg -i, or Synaptic, a new entry was added for this program in the KDE "start" menu if appropriate.  And if you removed the program via apt-get remove, the menu entry would disappear automatically.

I did a little bit of research and learned about the Debian /usr/lib/menu/ files and their syntax.  This knowledge enabled me to write a short script that will create a new submenu titled "Debian" inside the main fluxbox menu, immediately above the "Apps" submenu.

If you install or remove programs via apt-get, if you run the script again, it will dynamically rebuild the Debian menu and add or remove entries as appropriate.

It is my hope that a "Regenerate Debian Menu" item will eventually be added to DSL and this script would also be run at the end of the "Start Synaptic" script.

Anyways, here is how to use it.

1) Make a backup copy of your fluxbox menu, just in case you have a problem and need to restore your original menu:
cp /home/dsl/.fluxbox/menu /home/dsl/.fluxbox/menu.backup

2) Then use Firefox to highlight the script below and then open Beaver and paste it into a new, blank text file.  You can paste highlighted text by pushing the middle mouse button, or scrollwheel button.

3) Save the file as build_debmenu.sh

4) Open an xterminal and type this to make it an executable script:
chmod 755 build_debmenu.sh

5) Run the script by typing:
./build_debmenu.sh

Let me know how it works (or doesn't work) for you.  All feedback is welcome.

Thanks.

-CB

Code Sample
#!/bin/bash
#
# build_debmenu.sh  -   Creates a Fluxbox Debian submenu with menu items for
#                       all Debian packages that add an entry into the
#                       /usr/lib/menu directory
# Rev 0 5/21/05
# by cbagger01 from the DSL forums

# Copy the existing fluxbox menu file and strip out
# the old debmenu submenu entries and save to a temp file
cat $HOME/.fluxbox/menu | grep -v debmenu  > /tmp/oldmenu

# Find the line number directly above the (Apps) submenu
linenum=`awk '/\(Apps\)/ { print NR }' /tmp/oldmenu`
let "prevnum = linenum - 1"

# Create the first part of the new menu file
sed -n '1,'$prevnum'p' /tmp/oldmenu > /tmp/newmenu

# Create the Debian fluxbox submenu entry
echo "   [submenu] (Debian) {} # debmenu" >> /tmp/newmenu

# Collect the Debian Menu titles
# Our Debian friends do not use a consistent delimiter method for the
# title value.  If the title contains spaces, it is enclosed in quotes and
# the delimiters are START: title=" and END: "  but if the title doesn't
# contain spaces, then no quotes are used and the delimiters
# are START: title= and END: blankspace
# This sed script will parse out the title values properly regardless
# of the method used inside each menu file
cat /usr/lib/menu/* 2> /dev/null | \
sed -e 's/.*title=\([^"]*\) .*/title=\1/g' \
-e 's/.*title="\([^"]*\)".*/title=\1/g' \
-n -e 's/title=//p' > /tmp/titles

# Collect the Debian Menu commands
# The same issue exists with the command value because some command strings
# will contain spaces, for example "/bin/ls -al"
cat /usr/lib/menu/* 2> /dev/null | \
sed -e 's/.*command=\([^"]*\) .*/command=\1/g' \
-e 's/.*command="\([^"]*\)".*/command=\1/g' \
-n -e 's/command=//p' > /tmp/commands

# Loop through each title / command pair and build a menu entry
i=1
total=`awk 'END { print NR }' /tmp/titles`
while [ "$i" -le $total ];do
title=`sed -n "$i"p /tmp/titles`
command=`sed -n "$i"p /tmp/commands`
# Create the new fluxbox menu entry
echo "      [exec]  ($title) {$command} # debmenu" >> /tmp/newmenu
let "i+=1"
done

# Close out the Debian fluxbox submenu
echo "   [end] # debmenu" >> /tmp/newmenu

# Add the rest of the old menu to the end of our new menu
sed -n $linenum',$p' /tmp/oldmenu >> /tmp/newmenu

# This script may be running effective as root under sudo
# If so, figure out the real user name
realuser=
if [ -z "$SUDO_USER" ]; then
realuser=$USER
else
realuser=$SUDO_USER
fi

# Change the menu file permissions if real user is not root
if [ "$realuser" != "root" ]; then
chown $realuser:staff /tmp/newmenu
fi

# Replace the fluxbox menu file with our newly built file
mv /tmp/newmenu $HOME/.fluxbox/menu

# Clean up old temp files
rm -rf /tmp/oldmenu
rm -rf /tmp/titles
rm -rf /tmp/commands

exit

Posted by cbagger01 on June 01 2005,03:21
OK,

It's been over a week and after 98 views, no feedback.

Can someone try this thing out and see if it works for them?

I know that there are hd install users out there that would like to use apt-get/Synaptic to install applications, but prefer to use myDSL extensions because newly installed Debian packages don't appear in the DSL Fluxbox menu like the myDSL system works.

This script should solve this, while maintaining the original Fluxbox menu structure (both pre and post myDSL installs).

You don't need to be a hd user in order to give it a try.

If you are a livecd user with 128MB of RAM or more, just "Enable Apt" or choose "Synaptic" from the menu and play around a little bit.

If you don't like it, just reboot and you are back to a fresh livecd desktop.

Either way, please reply with info that it works OK or with info that it does not and exactly what appears to be wrong.

Thanks,

-CB

Posted by ke4nt1 on June 01 2005,05:54
Had I've known before now....

I would have NOT removed all the /usr/lib/menu items
from all the extensions in the past to "trim the fat"..

These files were useless to DSL before this..

...testing

73
ke4nt

Posted by ke4nt1 on June 01 2005,06:10
Seems to work for me..

I installed a few small things from debian unstable..

One was xbubble..
Another was XDigger
Another was vgagamespack
last was xblast-x11

Seems I got some bonus apps when I did..
My Debian menu reads..

pycrust
pyshell
xrced
XBubble
XDigger
High-Speed shoot 'em up game

Seems some of them don't follow the usual debian menu format..
vgagamespack didn't even have an entry..
and you see the lengthy entry for xblast-x11..

But the script works nicely, repeatedly..
Good work, cbagger01..

73
ke4nt

Posted by clivesay on June 01 2005,12:11
I tested also. Not sure if I was doing everything exactly right but after installing circuslinux I had the menu items:

Circus Linux
Circus Linux!

Chris

Posted by cbagger01 on June 01 2005,17:49
Thanks to everyone who is testing and providing information.

I installed circuslinux (Debian Testing) and got the same menu entry.

I then examined the /usr/lib/menu file for further information and found out there is an (optional) variable to a menu entry called "longtitle", in addition to the regular "title" entry, and since both names end with the letters TITLE, it confuses things somewhat.

So I will need to rework the script to ignore "longtitle" and focus on "title".

I'll post the next revision when it is ready for testing.

Thanks again for the feedback.  It is appreciated.

Posted by cbagger01 on June 02 2005,03:11
OK,

Give this revision a try.  It should filter out all of the longtitles and you should see "Circus Linux" in the menu and the one with the exclamation point should no longer be there.

Code Sample
#!/bin/bash
#
# build_debmenu.sh  -   Creates a Fluxbox Debian submenu with menu items for
#                       all Debian packages that add an entry into the
#                       /usr/lib/menu directory
# Rev 1 6/01/05
# by cbagger01 from the DSL forums

# Copy the existing fluxbox menu file and strip out
# the old debmenu submenu entries and save to a temp file
cat $HOME/.fluxbox/menu | grep -v debmenu  > /tmp/oldmenu

# Find the line number directly above the (Apps) submenu
linenum=`awk '/\(Apps\)/ { print NR }' /tmp/oldmenu`
let "prevnum = linenum - 1"

# Create the first part of the new menu file
sed -n '1,'$prevnum'p' /tmp/oldmenu > /tmp/newmenu

# Create the Debian fluxbox submenu entry
echo "   [submenu] (Debian) {} # debmenu" >> /tmp/newmenu

# Collect the Debian Menu titles
# Our Debian friends do not use a consistent delimiter method for the
# title value.  If the title contains spaces, it is enclosed in quotes and
# the delimiters are START: title=" and END: "  but if the title doesn't
# contain spaces, then no quotes are used and the delimiters
# are START: title= and END: blankspace
# This sed script will parse out the title values properly regardless
# of the method used inside each menu file
cat /usr/lib/menu/* 2> /dev/null | \
sed -e 's/.*longtitle//' \
-e 's/.*title=\([^"]*\) .*/title=\1/g' \
-e 's/.*title="\([^"]*\)".*/title=\1/g' \
-n -e 's/title=//p' > /tmp/titles

# Collect the Debian Menu commands
# The same issue exists with the command value because some command strings
# will contain spaces, for example "/bin/ls -al"
cat /usr/lib/menu/* 2> /dev/null | \
sed -e 's/.*command=\([^"]*\) .*/command=\1/g' \
-e 's/.*command="\([^"]*\)".*/command=\1/g' \
-n -e 's/command=//p' > /tmp/commands

# Loop through each title / command pair and build a menu entry
i=1
total=`awk 'END { print NR }' /tmp/titles`
while [ "$i" -le $total ];do
title=`sed -n "$i"p /tmp/titles`
command=`sed -n "$i"p /tmp/commands`
# Create the new fluxbox menu entry
echo "      [exec]  ($title) {$command} # debmenu" >> /tmp/newmenu
let "i+=1"
done

# Close out the Debian fluxbox submenu
echo "   [end] # debmenu" >> /tmp/newmenu

# Add the rest of the old menu to the end of our new menu
sed -n $linenum',$p' /tmp/oldmenu >> /tmp/newmenu

# This script may be running effective as root under sudo
# If so, figure out the real user name
realuser=
if [ -z "$SUDO_USER" ]; then
realuser=$USER
else
realuser=$SUDO_USER
fi

# Change the menu file permissions if real user is not root
if [ "$realuser" != "root" ]; then
chown $realuser:staff /tmp/newmenu
fi

# Replace the fluxbox menu file with our newly built file
mv /tmp/newmenu $HOME/.fluxbox/menu

# Clean up old temp files
rm -rf /tmp/oldmenu
rm -rf /tmp/titles
rm -rf /tmp/commands

exit

Posted by roberts on June 02 2005,04:54
Once this is thoroughly tested it would make a nice addition to the dpkg-restore.dsl
Posted by clivesay on June 02 2005,13:26
You scripters just blow my mind!

If this was in dsl-dpkg we would have mydsl and debian apt dynamic menu building in fluxbox?!! We don't need no stinkin' KDE or Gnome :)

Chris

Posted by friedgold on June 05 2005,15:53
I'm going to try giving this a go today. Definately a big win being able to have the fluxbox menus automatically updated.

Out of interest was there any reason the debian update-menus program (part of the debian menu package) couldn't be used/modified instead of writing a completely new script?

Posted by cbagger01 on June 05 2005,18:04
Debian update menus can be used, but I believe that it would change the basic structure of the DSL menu tree (IE: myDSL dynamic menu and all of the custom DSL static menus).

But then again, I could be wrong.  I have never used it except as already integrated with KNOPPIX and KDE.

I'm sure it is also possible to modify the program so that it plays nice with DSL but what fun is that?

I must admit that it offers superior functionality because it creates an entire submenu structure (Games, Tools, Office, etc) instead of just a single "Debian" submenu.

If I run into an unsolvable (by me) problem with my script, then plan B is to modify debian update-menus but I am not there yet.

I also don't know what the space requirements of debian update-menus are.  Hopefully it is just a script or a simple C program with no weighty dependencies.

Posted by friedgold on June 05 2005,23:11
Just tried this now and it runs great. Just a few points/ideas

-The menu items for text mode programs are not being created properly. For example if I install aptitude the script creates the following menu item:

Code Sample
     [exec]  (aptitude) {/usr/bin/aptitude} # debmenu


Which fails to open aptitude properly (since it is not a X program). What is needed is something like

Code Sample
     [exec]  (aptitude) {rxvt -e /usr/bin/aptitude} # debmenu


The menu file for aptitude is as follows:

Code Sample
 ?package(aptitude):needs="text" section="Apps/System" \
 title="aptitude" command="/usr/bin/aptitude" hints="apt"


I guess the needs="text" is what would normally tell debian's update-menus program it's a text app and should be run in a terminal.

-If you create a symlink from /usr/sbin/update-menus to /home/dsl/build_debmenu.sh (or wherever you've put it) then your script should be automatically called by the post installation scripts of any packages that need menu items. When I did this and used sudo apt-get install prog_name the menu items were added automatically. Similarly I used synaptic to install gaim and it added the menu item automatically with this symlink present. The only problem I encountered was if you use

Code Sample
su
apt-get install prog_name
exit


It doesn't update the user dsl's menu but the /root/.fluxbox/menu instead. While this makes sense it is probably not what the user would want.

Posted by friedgold on June 05 2005,23:26
Quote (cbagger01 @ June 05 2005,14:04)
Debian update menus can be used, but I believe that it would change the basic structure of the DSL menu tree (IE: myDSL dynamic menu and all of the custom DSL static menus).

But then again, I could be wrong.  I have never used it except as already integrated with KNOPPIX and KDE.

I'm sure it is also possible to modify the program so that it plays nice with DSL but what fun is that?

I must admit that it offers superior functionality because it creates an entire submenu structure (Games, Tools, Office, etc) instead of just a single "Debian" submenu.

If I run into an unsolvable (by me) problem with my script, then plan B is to modify debian update-menus but I am not there yet.

I also don't know what the space requirements of debian update-menus are.  Hopefully it is just a script or a simple C program with no weighty dependencies.

The debian menu which includes update-menus package is 400KBs and has no dependecies not already in DSL. Although I'm not hugely familiar with it then menu creation is script based (there's a different script for each wm to create the menu) so it should be possible to modify how it behaves. I would think incorperating the static DSL menu would be fairly straightforward as update-menus already provides a mechanism to specify your own menu items seperate from those in /usr/lib/menu. What would be harder is getting it to work with the dynamic DSL menu.

I just suggested using update-menus as it seems sensible to make use of the pre-existing structure if possible rather than reinvent the wheel. However the update-menus stucture/scripts do seem pretty complicated at a first glance so maybe your way is best.

Posted by cbagger01 on June 06 2005,03:38
friedgold,

Thanks for your feedback.  Assuming the "needs" variable is always included in every menu file item, it should not be too hard to add the rxvt -e part to the appropriate items.

Also, thanks for the /usr/sbin/update-menus information.
It appears that this is the appropriate place to trigger the menu update script, since this is when the "real" menu update tool would get triggered.

400KB is probably too big for DSL, but if the "Fluxbox" script was reasonable in size and could be made to work with DSL, then it would be a good candidate for modification.

Despite my efforts, I am not totally convinced that my way is best.  However, I am convinced that my way is better than no menu updates at all.

Posted by wageslave on June 08 2005,12:47
Hey,

I'm a linux noobie. I've done a hdd install of dsl onto an old laptop for a friend of mine, she's even less savvy than me so I want to make things as straightforward as possible for her. This debian menu sounds like a great way to give her easy access to extra programs i add to dsl. Has anyone run into any problems with it yet?

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.