#!/usr/bin/perl # kde-update-menu v 0.1 # # written 17 Nov 2002 by John Lightsey (john@nixnuts.net) # # This script is based on the kde-update-menu script from the # Debian kdebase version: 4:2.2.2-14 package. (Author unknown) # # This script is licensed to you under the terms of the GNU GPL # v 2.0 or, at your option, any later version. This script is free # software and comes with absoloutely NO WARRANTY. # please back up your original /usr/bin/kde-update-menu and # /usr/share/applnk/ directories and files before attempting to use this script. #####HOW IT WORKS##### # This script is intended to be a replacement for kde-update-menu and will # act in a functionally equivalent manner if so configured. This script goes beyond # the functionality of kde-update-menu by allowing you to choose alternate # methods of linking the Debian menu tree into the KDE menu tree. The # standard kde-update-menu works by deleting all the symlinks from the # /usr/share/applnk subdirectories then creating new symlinks from # /usr/share/applnk//Debian to /var/lib/kde/menu/. # This script will allow for two other options. (1) Linking /usr/share/applnk/Debian # to /var/lib/kde/menu (This would creat a single "Debian" item on the KDE menu # which links into all the Debian menus), (2) Linking each individual file from the Debian # menu structure directly into the KDE menu structure (IE: cooledit will be K->Editors-> # cooledit rather than K-Editors->Debian->cooledit). The following declaration controls # this behavior. It would be preferable to set this variable in /etc/menu-methods-kdebase, # but this is not being done because it might affect compatability with the existing # update-menus system. # # John Lightsey ################## ################################ # Set this variable to: # 0 for the standard Debian menu organization # 1 for a single K->Debian menu # 2 to link applications from the Debian menu tree directly into the KDE menu tree use constant MENU_TYPE => 2; ################################# my $kdeprefix = "/usr/share/applnk"; my ($prefix) = @ARGV; if ($prefix && ($prefix == '/var/lib/kde/menu')) { # This is slightly different than the standard way of doing things. # We're removing ALL symlinks. The standard kde-update-menu # only removes "Debian" symlinks. foreach my $lnk (`find /usr/share/applnk -type l`) { chomp $lnk; `rm -f "$lnk"`; } } else { exit 0; } if (MENU_TYPE == 1) { # Single Debian menu `ln -sf $prefix /usr/share/applnk/Debian`; exit 0; } elsif (MENU_TYPE == 0) { # Multiple Debian submenus # this is all pretty much a straight copy of the original kde-update-menu # don't blame me for the way it's organized. If people like my script I'll # clean this up later. if (-d "$prefix/Games") { `cp /etc/kde2/desktop/d-debian.desktop $prefix/Games/.directory`; `rm -f $kdeprefix/Games/Debian`; `ln -sf $prefix/Games $kdeprefix/Games/Debian`; } else { `rm -f $kdeprefix/Games/Debian`; } if (-d "$prefix/Apps") { `cp /etc/kde2/desktop/d-debian.desktop $prefix/Apps/.directory`; `rm -f $kdeprefix/Applications/Debian`; `ln -sf $prefix/Apps $kdeprefix/Applications/Debian`; } else { `rm -f $kdeprefix/Applications/Debian`; } if (-d "$prefix/Help") { `cp /etc/kde2/desktop/d-help.desktop $prefix/Help/.directory`; `rm -f $kdeprefix/System/Debian-Help`; `ln -sf $prefix/Help $kdeprefix/System/Debian-Help`; } else { `rm -f $kdeprefix/System/Debian-Help`; } if (-d "$prefix/Screen") { `cp /etc/kde2/desktop/d-screen.desktop $prefix/Screen/.directory`; `rm -f $kdeprefix/System/Debian-Screen`; `ln -sf $prefix/Screen $kdeprefix/System/Debian-Screen`; } else { `rm -f $kdeprefix/System/Debian-Screen`; } if (-d "$prefix/XShells") { `cp /etc/kde2/desktop/d-xshells.desktop $prefix/XShells/.directory`; `rm -f $kdeprefix/Utilities/Debian-XShells`; `ln -sf $prefix/XShells $kdeprefix/Utilities/Debian-XShells`; } else { `rm -f $kdeprefix/Utilities/Debian-XShells`; } if (-d "$prefix/WindowManagers") { `cp /etc/kde2/desktop/d-window-managers.desktop $prefix/WindowManagers/.directory`; `rm -f $kdeprefix/System/Debian-WM`; `ln -sf $prefix/WindowManagers $kdeprefix/System/Debian-WM`; } else { `rm -f $kdeprefix/System/Debian-WM`; } if (-d "$prefix/Apps/Databases") { `mv $prefix/Apps/Databases $prefix/Databases`; `cp /etc/kde2/desktop/d-databases.desktop $prefix/Databases/.directory`; `rm -f $kdeprefix/Office/DEBIAN`; `ln -sf $prefix/Databases $kdeprefix/Office/DEBIAN`; } else { `rm -f $kdeprefix/Office/Debian`; } if (-d "$prefix/Apps/Editors") { `mv $prefix/Apps/Editors $prefix/Editors`; `cp /etc/kde2/desktop/d-debian.desktop $prefix/Editors/.directory`; `rm -f $kdeprefix/Editors/Debian`; `ln -sf $prefix/Editors $kdeprefix/Editors/Debian`; } else { `rm -f $kdeprefix/Editors/Debian`; } if (-d "$prefix/Apps/Graphics") { `mv $prefix/Apps/Graphics $prefix/Graphics`; `cp /etc/kde2/desktop/d-debian.desktop $prefix/Graphics/.directory`; `rm -f $kdeprefix/Graphics/Debian`; `ln -sf $prefix/Graphics $kdeprefix/Graphics/Debian`; } else { `rm -f $kdeprefix/Graphics/Debian`; } if (-d "$prefix/Apps/Math") { `mv $prefix/Apps/Math $prefix/Math`; `cp /etc/kde2/desktop/d-math.desktop $prefix/Math/.directory`; `rm -f $kdeprefix/Utilities/Debian-Math`; `ln -sf $prefix/Math $kdeprefix/Utilities/Debian-Math`; } else { `rm -f $kdeprefix/Utilities/Debian-Math`; } if (-d "$prefix/Apps/Net") { `mv $prefix/Apps/Net $prefix/Net`; `cp /etc/kde2/desktop/d-debian.desktop $prefix/Net/.directory`; `rm -f $kdeprefix/Internet/Debian`; `ln -sf $prefix/Net $kdeprefix/Internet/Debian`; } else { `rm -f $kdeprefix/Internet/Debian`; } if (-d "$prefix/Apps/Programming") { `mv $prefix/Apps/Programming $prefix/Programming`; `cp /etc/kde2/desktop/d-debian.desktop $prefix/Programming/.directory`; `rm -f $kdeprefix/Development/Debian`; `ln -sf $prefix/Programming $kdeprefix/Development/Debian`; } else { `rm -f $kdeprefix/Development/Debian`; } if (-d "$prefix/Apps/Shells") { `mv $prefix/Apps/Shells $prefix/Shells`; `cp /etc/kde2/desktop/d-shells.desktop $prefix/Shells/.directory`; `rm -f $kdeprefix/Utilities/Debian-Shells`; `ln -sf $prefix/Shells $kdeprefix/Utilities/Debian-Shells`; } else { `rm -f $kdeprefix/Utilities/Debian-Shells`; } if (-d "$prefix/Apps/Sound") { `mv $prefix/Apps/Sound $prefix/Sound`; `cp /etc/kde2/desktop/d-debian.desktop $prefix/Sound/.directory`; `rm -f $kdeprefix/Multimedia/Debian`; `ln -sf $prefix/Sound $kdeprefix/Multimedia/Debian`; } else { `rm -f $kdeprefix/Multimedia/Debian`; } if (-d "$prefix/Apps/System") { `mv $prefix/Apps/System $prefix/System`; `cp /etc/kde2/desktop/d-debian.desktop $prefix/System/.directory`; `rm -f $kdeprefix/System/Debian`; `ln -sf $prefix/System $kdeprefix/System/Debian`; } else { `rm -f $kdeprefix/System/Debian`; } if (-d "$prefix/Apps/Text") { `cp /etc/kde2/desktop/d-text.desktop $prefix/Apps/Text/.directory`; `rm -f $kdeprefix/Utilities/Debian`; `ln -sf $prefix/Tools $kdeprefix/Utilities/Debian`; } else { `rm -f $kdeprefix/Utilities/Debian`; } if (-d "$prefix/Apps/Tools") { `mv $prefix/Apps/Tools $prefix/Tools`; `cp /etc/kde2/desktop/d-debian.desktop $prefix/Tools/.directory`; `rm -f $kdeprefix/Utilities/Debian`; `ln -sf $prefix/Tools $kdeprefix/Utilities/Debian`; } else { `rm -f $kdeprefix/Utilities/Debian`; } if (-d "$prefix/Apps/Viewers") { `mv $prefix/Apps/Viewers $prefix/Viewers`; `cp /etc/kde2/desktop/d-viewers.desktop $prefix/Viewers/.directory`; `rm -f $kdeprefix/Utilities/Debian-Viewers`; `ln -sf $prefix/Viewers $kdeprefix/Graphics/Debian-Viewers`; } else { `rm -f $kdeprefix/Utilities/Debian-Viewers`; } if (-d "$prefix/Apps/Emulators") { `mv $prefix/Apps/Emulators $prefix/Emulators`; `cp /etc/kde2/desktop/d-emulators.desktop $prefix/Emulators/.directory`; `rm -f $kdeprefix/Utilities/Debian-Emulators`; `ln -sf $prefix/Emulators $kdeprefix/Utilities/Debian-Emulators`; } else { `rm -f $kdeprefix/Utilities/Debian-Emulators`; } if (-d "$prefix/Apps/Hamradio") { `mv $prefix/Apps/Hamradio $prefix/Hamradio`; `cp /etc/kde2/desktop/d-hamradio.desktop $prefix/Hamradio/.directory`; `rm -f $kdeprefix/Utilities/Debian-Hamradio`; `ln -sf $prefix/Hamradio $kdeprefix/Utilities/Debian-Hamradio`; } else { `rm -f $kdeprefix/Utilities/Debian-Hamradio`; } if (-d "$prefix/Apps/Technical") { `mv $prefix/Apps/Technical $prefix/Technical`; `cp /etc/kde2/desktop/d-technical.desktop $prefix/Technical/.directory`; `rm -f $kdeprefix/Utilities/Debian-Technical`; `ln -sf $prefix/Technical $kdeprefix/Utilities/Debian-Technical`; } else { `rm -f $kdeprefix/Utilities/Debian-Technical`; } ### Screen submenus ### if (-d "$prefix/Screen/Lock") { `cp /etc/kde2/desktop/d-lock.desktop $prefix/Screen/Lock/.directory`; } if (-d "$prefix/Screen/Save") { `cp /etc/kde2/desktop/d-save.desktop $prefix/Screen/Save/.directory`; } if (-d "$prefix/Screen/Root-window") { `cp /etc/kde2/desktop/d-root-window.desktop $prefix/Screen/Root-window/.directory`; } ### WindowManagers submenus ### if (-d "$prefix/WindowManagers/Modules") { `cp /etc/kde2/desktop/d-modules.desktop $prefix/WindowManagers/Modules/.directory`; } ### Games submenus ### if (-d "$prefix/Games/Adventure") { `cp /etc/kde2/desktop/d-adventure.desktop $prefix/Games/Adventure/.directory`; } if (-d "$prefix/Games/Arcade") { `cp /etc/kde2/desktop/d-arcade.desktop $prefix/Games/Arcade/.directory`; } if (-d "$prefix/Games/Board") { `cp /etc/kde2/desktop/d-board.desktop $prefix/Games/Board/.directory`; } if (-d "$prefix/Games/Card") { `cp /etc/kde2/desktop/d-card.desktop $prefix/Games/Card/.directory`; } if (-d "$prefix/Games/Puzzles") { `cp /etc/kde2/desktop/d-puzzles.desktop $prefix/Games/Puzzles/.directory`; } if (-d "$prefix/Games/Sports") { `cp /etc/kde2/desktop/d-sports.desktop $prefix/Games/Sports/.directory`; } if (-d "$prefix/Games/Strategy") { `cp /etc/kde2/desktop/d-strategy.desktop $prefix/Games/Strategy/.directory`; } if (-d "$prefix/Games/Tetris-like") { `cp /etc/kde2/desktop/d-tetris-like.desktop $prefix/Games/Tetris-like/.directory`; } if (-d "$prefix/Games/Toys") { `cp /etc/kde2/desktop/d-toys.desktop $prefix/Games/Toys/.directory`; } } elsif (MENU_TYPE == 2) { # Apps linked directly # start by clearing out the empty directories foreach my $kdir (`find $kdeprefix -type d`) { chomp $kdir; next if ($kdir = $kdeprefix); unless (`find $kdir -name *.desktop`) { `rm -rf $kdir`; } } # first we'll mimic what's being done above to the directories and move the # Apps/ Directories down a level. We'll leave the Apps/Education # directory where it is. I'm sure there's a better place to put it, but I'd rather # not break anything. (For some reason Debian sticks all the Educational stuff # in Apps. Rather than fighting this, we'll go along with it.) The ultimate goal is # to mimic the standard Debian menus as closely as possible while getting # rid of those damn Debian submenus. foreach my $dir (`find $prefix/Apps -type d -maxdepth 1`) { chomp $dir; next if ($dir =~/^$prefix\/Apps(\/Educational)?$/); my $destdir = $dir; $destdir =~ s/^$prefix\/Apps/$prefix/; `mv "$dir" "$destdir"`; } # Now we'll load the .directory files for all fo the directories mentioned above # that dont have the default .directory file. foreach my $sub ("Adventure", "Arcade", "Board", "Card", "Puzzles", "Sports", "Strategy", "Tetris-like", "Toys") { if (-d "$prefix/Games/$sub") { my $t = lc($sub); `cp /etc/kde2/desktop/d-$t.desktop $prefix/Games/$sub/.directory`; } } if (-d "$prefix/WindowManagers/Modules") { `cp /etc/kde2/desktop/d-modules.desktop $prefix/WindowManagers/Modules/.directory`; } if (-d "$prefix/WindowManagers") { `cp /etc/kde2/desktop/d-window-managers.desktop $prefix/WindowManagers/.directory`; } foreach my $screen ("Lock", "Save", "Root-window") { if (-d "$prefix/Screen/$screen") { my $t = lc($screen); `cp /etc/kde2/desktop/d-$t.desktop $prefix/Screen/$screen/.directory`; } } foreach my $sub ("Help", "Screen", "XShells", "Databases", "Math", "Shells", "Text", "Viewers", "Emulators", "Hamradio", "Technical") { if (-d "$prefix/$sub") { my $t = lc($sub); `cp /etc/kde2/desktop/d-$t.desktop $prefix/$sub/.directory`; } } # now lets link everything in foreach my $src (`find $prefix -name "*.desktop"`) { chomp $src; $src =~ /^($prefix)(.*\/)([^\/]+)$/; my ($submenu, $dest) = ($2, $3); #At this point $src is something like: /var/lib/kde/menu/Games/Arcade/Snake.desktop # $dest is something like: Snake.desktop # $submenu is something like: /Games/Arcade/ # We'll check see if the KDE menu exists, and if so we'll link our app directly into it. # If not, we'll build a symlink to the Debian directory. Duplicate app links will be silently # discarded. I haven't come across an example of this being a problem (IE: The duplicates # have always referred to the same program from what I've seen), but you never know. # let's mimic the mix and match done above with the directory names. $submenu =~ s/^\/Apps\//\/Applications\//; $submenu =~ s/^\/Help\//\/System\/Debian-Help\//; $submenu =~ s/^\/Screen\//\/Utilities\/Debian-Screen\//; $submenu =~ s/^\/XShells\//\/Utilities\/Debian-XShells\//; $submenu =~ s/^\/Shells\//\/Utilities\/Debian-Shells\//; $submenu =~ s/^\/WindowManagers\//\/System\/Debian-WM\//; $submenu =~ s/^\/Databases\//\/Office\/Databases\//; $submenu =~ s/^\/Math\//\/Utilities\/Debian-Math\//; $submenu =~ s/^\/Net\//\/Internet\//; $submenu =~ s/^\/Programming\//\/Development\//; $submenu =~ s/^\/Tools\//\/Utilities\//; $submenu =~ s/^\/Sound\//\/Multimedia\//; $submenu =~ s/^\/Viewers\//\/Graphics\/Debian-Viewers\//; $submenu =~ s/^\/Emulators\//\/Utilities\/Debian-Emulators\//; $submenu =~ s/^\/Hamradio\//\/Utilities\/Debian-Hamradio\//; $submenu =~ s/^\/Technical\//\/Utilities\/Debian-Technical\//; $submenu =~ s/^\/Games\/Strategy\//\/Games\/TacticStrategy\//; $submenu =~ s/^\/Games\/Toys\//\/Toys\//; # create the directory in the regular KDE menu system `mkdir -pv "$kdeprefix$submenu" 2>&1`; my $sdir = $src; $sdir =~ s/[^\/]+$//; if ((!(-s "$kdeprefix$submenu.directory")) && (-s "$sdir.directory")) { `cp "$sdir.directory" "$kdeprefix$submenu.directory"`; } # create our link `ln -s "$src" "$kdeprefix$submenu$dest"`; } # clean up some misc problems if ((-d "$kdeprefix/Utilities/Debian-Screen") && (!( -e "$kdeprefix/Utilities/Debian-Screen/.directory")) && (-e "$prefix/Screen/.directory")) { `cp "$prefix/Screen/.directory" "$kdeprefix/Utilities/Debian-Screen/.directory"`; } }