2000-11-02 21:22:07 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Create menu/desktop entries for an application
|
|
|
|
# This is used by the IShellLink interface
|
|
|
|
#
|
|
|
|
# Copyright 2000 Alexandre Julliard
|
2006-11-24 21:53:29 +01:00
|
|
|
# Copyright 2006 Vitaliy Margolen
|
2000-11-02 21:22:07 +01:00
|
|
|
#
|
2002-03-10 00:29:33 +01:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
#
|
|
|
|
|
2005-12-19 21:25:52 +01:00
|
|
|
# Note that the link is a relative unix-style path name. Since the / character
|
|
|
|
# is not valid in Windows filenames it is an adequate separator to show the
|
2006-11-24 21:53:29 +01:00
|
|
|
# menu structure.
|
2005-12-19 21:25:52 +01:00
|
|
|
|
2000-11-02 21:22:07 +01:00
|
|
|
mode=""
|
|
|
|
args=""
|
|
|
|
menu=""
|
|
|
|
icon=""
|
|
|
|
descr=""
|
|
|
|
link=""
|
|
|
|
path=""
|
|
|
|
workdir=""
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
cat <<EOF
|
|
|
|
usage: wineshelllink options
|
|
|
|
|
|
|
|
options:
|
|
|
|
--desktop create a desktop link
|
|
|
|
--menu create a menu entry
|
|
|
|
--path xx path to the application
|
2005-12-19 21:25:52 +01:00
|
|
|
--link xx name of link to create, including path
|
2000-11-02 21:22:07 +01:00
|
|
|
--args xx command-line arguments for the application
|
|
|
|
--icon xx icon to display
|
|
|
|
--workdir xx working directory for the application
|
|
|
|
--descr xx application description
|
|
|
|
|
|
|
|
EOF
|
2003-09-30 02:28:13 +02:00
|
|
|
exit 2
|
2000-11-02 21:22:07 +01:00
|
|
|
}
|
|
|
|
|
2001-01-17 21:17:03 +01:00
|
|
|
if [ $# -eq 0 ] ; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2000-11-02 21:22:07 +01:00
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case "$1" in
|
2001-12-14 23:45:06 +01:00
|
|
|
--desktop) mode="desktop"; shift 1 ;;
|
|
|
|
--menu) mode="menu"; shift 1 ;;
|
|
|
|
--path) path="$2"; shift 2 ;;
|
|
|
|
--link) link="$2"; shift 2 ;;
|
|
|
|
--args) args="$2"; shift 2 ;;
|
|
|
|
--icon) icon="$2"; shift 2 ;;
|
|
|
|
--descr) descr="$2"; shift 2 ;;
|
|
|
|
--workdir) workdir="$2"; shift 2 ;;
|
|
|
|
*) usage ;;
|
2000-11-02 21:22:07 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2003-09-30 02:28:13 +02:00
|
|
|
if [ -z "$mode" ] ; then
|
|
|
|
echo "Either --desktop or --menu required"
|
2001-01-17 21:17:03 +01:00
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2003-09-30 02:28:13 +02:00
|
|
|
if [ -z "$link" ] ; then
|
|
|
|
echo "You must specify a link name with --link"
|
2001-01-17 21:17:03 +01:00
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
desktop_entry()
|
2000-11-02 21:22:07 +01:00
|
|
|
{
|
|
|
|
cat <<EOF
|
|
|
|
[Desktop Entry]
|
2006-11-24 21:53:29 +01:00
|
|
|
Name=$linkname
|
2007-02-14 00:01:26 +01:00
|
|
|
Exec=env WINEPREFIX="${WINEPREFIX:-$HOME/.wine}" wine "$path" $args
|
2000-11-02 21:22:07 +01:00
|
|
|
Type=Application
|
2007-07-21 17:18:46 +02:00
|
|
|
StartupWMClass=Wine
|
2000-11-02 21:22:07 +01:00
|
|
|
EOF
|
2006-11-24 21:53:29 +01:00
|
|
|
[ -z "$descr" ] || echo "Comment=$descr"
|
2006-03-26 17:06:54 +02:00
|
|
|
[ -z "$workdir" ] || echo "Path=$workdir"
|
2000-11-02 21:22:07 +01:00
|
|
|
[ -z "$xpmicon" ] || echo "Icon=$xpmicon"
|
|
|
|
}
|
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
directory_entry()
|
2001-11-20 19:53:33 +01:00
|
|
|
{
|
2006-11-24 21:53:29 +01:00
|
|
|
cat <<EOF
|
|
|
|
[Desktop Entry]
|
|
|
|
Type=Directory
|
|
|
|
EOF
|
2007-02-08 15:32:44 +01:00
|
|
|
if [ "$1" = "wine" ] ; then
|
2006-11-24 21:53:29 +01:00
|
|
|
echo "Name=Wine"
|
|
|
|
echo "Icon=wine"
|
|
|
|
else
|
|
|
|
echo "Name=$1"
|
|
|
|
echo "Icon=folder"
|
|
|
|
fi
|
2001-11-20 19:53:33 +01:00
|
|
|
}
|
|
|
|
|
2000-11-02 21:22:07 +01:00
|
|
|
# copy the icon file to a specified dir and set xpmicon to the resulting path
|
|
|
|
copy_icon()
|
|
|
|
{
|
2006-11-24 21:53:29 +01:00
|
|
|
if [ -f "$icon" ]
|
|
|
|
then
|
2008-03-23 21:16:30 +01:00
|
|
|
xpmicon=`basename "$icon"`
|
|
|
|
xpmicon=${xpmicon%.*}
|
2006-11-24 21:53:29 +01:00
|
|
|
|
|
|
|
mkdir -p "$1"
|
2008-03-23 21:16:30 +01:00
|
|
|
cp "$icon" "$1"
|
2006-11-24 21:53:29 +01:00
|
|
|
else
|
|
|
|
xpmicon=""
|
|
|
|
fi
|
2000-11-02 21:22:07 +01:00
|
|
|
}
|
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
# XDG
|
2001-11-20 19:53:33 +01:00
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
xdg_config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/menus/applications-merged"
|
|
|
|
xdg_data_dir="${XDG_DATA_HOME:-$HOME/.local/share}"
|
2000-11-02 21:22:07 +01:00
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
# Create common directories
|
|
|
|
mkdir -p "$xdg_config_dir"
|
|
|
|
mkdir -p "$xdg_data_dir/desktop-directories"
|
2001-01-17 21:17:03 +01:00
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
get_menu_entries()
|
|
|
|
{
|
|
|
|
tmp="$xdg_config_dir/$1.menu"
|
|
|
|
|
|
|
|
if [ -r "$tmp" ] ; then
|
|
|
|
awk '
|
|
|
|
BEGIN { RS="<" }
|
|
|
|
/^Filename/ {
|
2007-05-01 04:23:29 +02:00
|
|
|
RSTART=index($0,">")
|
|
|
|
if (RSTART>0) {
|
2006-11-24 21:53:29 +01:00
|
|
|
print substr($0,RSTART+1)
|
|
|
|
}
|
|
|
|
}' $tmp
|
2002-04-29 21:33:09 +02:00
|
|
|
fi
|
2006-11-24 21:53:29 +01:00
|
|
|
}
|
2002-04-29 21:33:09 +02:00
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
# Input
|
|
|
|
# menu file name
|
|
|
|
# new item
|
|
|
|
write_menu_file()
|
|
|
|
{
|
2007-02-25 04:34:21 +01:00
|
|
|
menu=`echo "$1" | sed 's!/!-!g'`
|
|
|
|
filename=`echo "$2" | sed 's!/!-!g'`
|
2007-02-08 15:33:00 +01:00
|
|
|
|
2007-02-09 18:31:18 +01:00
|
|
|
tmpfile=`mktemp /tmp/wine.XXXXXX`
|
2006-11-24 21:53:29 +01:00
|
|
|
(
|
|
|
|
echo '<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"'
|
|
|
|
echo '"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">'
|
|
|
|
echo '<Menu>'
|
|
|
|
echo ' <Name>Applications</Name>'
|
|
|
|
|
2007-02-08 15:33:00 +01:00
|
|
|
IFS="/"
|
2006-11-24 21:53:29 +01:00
|
|
|
|
|
|
|
fullname='wine'
|
|
|
|
for i in $1; do
|
|
|
|
echo " <Menu>"
|
|
|
|
echo " <Name>$fullname-$i</Name>"
|
|
|
|
echo " <Directory>$fullname-$i.directory</Directory>"
|
|
|
|
|
|
|
|
dir_file_name="$xdg_data_dir/desktop-directories/$fullname-$i.directory"
|
|
|
|
if [ ! -f "$dir_file_name" ] ; then
|
|
|
|
directory_entry "$i" > "$dir_file_name"
|
|
|
|
fi
|
|
|
|
test "$i" = "wine" || fullname="$fullname-$i"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo " <Include>"
|
|
|
|
|
|
|
|
IFS="
|
|
|
|
"
|
2007-05-01 04:23:29 +02:00
|
|
|
for i in `get_menu_entries "$menu"`
|
|
|
|
do
|
2007-02-08 15:33:00 +01:00
|
|
|
test "$i" = "$filename" && continue
|
2006-11-24 21:53:29 +01:00
|
|
|
echo " <Filename>$i</Filename>"
|
|
|
|
done
|
|
|
|
|
|
|
|
# New record
|
2007-02-08 15:33:00 +01:00
|
|
|
echo " <Filename>$filename</Filename>"
|
2006-11-24 21:53:29 +01:00
|
|
|
echo " </Include>"
|
|
|
|
|
2007-02-08 15:33:00 +01:00
|
|
|
IFS='/'
|
2006-11-24 21:53:29 +01:00
|
|
|
for i in $1; do
|
|
|
|
echo " </Menu>"
|
|
|
|
done
|
|
|
|
echo '</Menu>'
|
|
|
|
) > $tmpfile
|
|
|
|
chmod 0600 $tmpfile
|
|
|
|
|
2007-02-08 15:33:00 +01:00
|
|
|
mv -f $tmpfile "$xdg_config_dir/$menu.menu"
|
2006-11-24 21:53:29 +01:00
|
|
|
}
|
2002-04-29 21:33:09 +02:00
|
|
|
|
2001-03-08 02:12:52 +01:00
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
copy_icon "$xdg_data_dir/icons"
|
2002-05-23 18:31:22 +02:00
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
linkname=`basename "$link"`
|
|
|
|
|
|
|
|
if [ $mode = "menu" ] ; then
|
|
|
|
mkdir -p "$xdg_data_dir/applications/wine/`dirname "$link"`"
|
|
|
|
|
2007-02-08 15:33:00 +01:00
|
|
|
linkpath=`dirname "$link"`
|
2007-02-08 15:32:44 +01:00
|
|
|
if [ "$linkpath" = "." ] ; then
|
2006-11-24 21:53:29 +01:00
|
|
|
linkpath=""
|
|
|
|
else
|
2007-02-08 15:33:00 +01:00
|
|
|
linkpath="/$linkpath"
|
2002-05-23 18:31:22 +02:00
|
|
|
fi
|
2000-11-02 21:22:07 +01:00
|
|
|
|
2006-11-24 21:53:29 +01:00
|
|
|
desktop_entry > "$xdg_data_dir/applications/wine/$link.desktop"
|
2007-02-08 15:33:00 +01:00
|
|
|
write_menu_file "wine$linkpath" "wine$linkpath/$linkname.desktop"
|
2006-11-24 21:53:29 +01:00
|
|
|
else
|
2007-04-21 01:58:49 +02:00
|
|
|
if [ -d "$HOME/Desktop" ]
|
|
|
|
then
|
|
|
|
desktop_target="$HOME/Desktop/$linkname.desktop"
|
|
|
|
else
|
|
|
|
desktop_target="$HOME/$linkname.desktop"
|
|
|
|
fi
|
|
|
|
desktop_entry > "$desktop_target"
|
2000-11-02 21:22:07 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|