Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Create menu/desktop entries for an application |
| 4 | # This is used by the IShellLink interface |
| 5 | # |
| 6 | # Copyright 2000 Alexandre Julliard |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 7 | # Copyright 2006 Vitaliy Margolen |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 8 | # |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 9 | # This library is free software; you can redistribute it and/or |
| 10 | # modify it under the terms of the GNU Lesser General Public |
| 11 | # License as published by the Free Software Foundation; either |
| 12 | # version 2.1 of the License, or (at your option) any later version. |
| 13 | # |
| 14 | # This library is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | # Lesser General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU Lesser General Public |
| 20 | # License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 21 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 22 | # |
| 23 | |
Bill Medland | d5739ed | 2005-12-19 21:25:52 +0100 | [diff] [blame] | 24 | # Note that the link is a relative unix-style path name. Since the / character |
| 25 | # is not valid in Windows filenames it is an adequate separator to show the |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 26 | # menu structure. |
Bill Medland | d5739ed | 2005-12-19 21:25:52 +0100 | [diff] [blame] | 27 | |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 28 | mode="" |
| 29 | args="" |
| 30 | menu="" |
| 31 | icon="" |
| 32 | descr="" |
| 33 | link="" |
| 34 | path="" |
| 35 | workdir="" |
| 36 | |
| 37 | usage() |
| 38 | { |
| 39 | cat <<EOF |
| 40 | usage: wineshelllink options |
| 41 | |
| 42 | options: |
| 43 | --desktop create a desktop link |
| 44 | --menu create a menu entry |
| 45 | --path xx path to the application |
Bill Medland | d5739ed | 2005-12-19 21:25:52 +0100 | [diff] [blame] | 46 | --link xx name of link to create, including path |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 47 | --args xx command-line arguments for the application |
| 48 | --icon xx icon to display |
| 49 | --workdir xx working directory for the application |
| 50 | --descr xx application description |
| 51 | |
| 52 | EOF |
Francois Gouget | bc4f8f9 | 2003-09-30 00:28:13 +0000 | [diff] [blame] | 53 | exit 2 |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Jeremy White | 8dad1d8 | 2001-01-17 20:17:03 +0000 | [diff] [blame] | 56 | if [ $# -eq 0 ] ; then |
| 57 | usage |
| 58 | fi |
| 59 | |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 60 | while [ $# -gt 0 ] |
| 61 | do |
| 62 | case "$1" in |
Simon Walton | 44b15b18 | 2001-12-14 22:45:06 +0000 | [diff] [blame] | 63 | --desktop) mode="desktop"; shift 1 ;; |
| 64 | --menu) mode="menu"; shift 1 ;; |
| 65 | --path) path="$2"; shift 2 ;; |
| 66 | --link) link="$2"; shift 2 ;; |
| 67 | --args) args="$2"; shift 2 ;; |
| 68 | --icon) icon="$2"; shift 2 ;; |
| 69 | --descr) descr="$2"; shift 2 ;; |
| 70 | --workdir) workdir="$2"; shift 2 ;; |
| 71 | *) usage ;; |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 72 | esac |
| 73 | done |
| 74 | |
Francois Gouget | bc4f8f9 | 2003-09-30 00:28:13 +0000 | [diff] [blame] | 75 | if [ -z "$mode" ] ; then |
| 76 | echo "Either --desktop or --menu required" |
Jeremy White | 8dad1d8 | 2001-01-17 20:17:03 +0000 | [diff] [blame] | 77 | usage |
| 78 | fi |
| 79 | |
Francois Gouget | bc4f8f9 | 2003-09-30 00:28:13 +0000 | [diff] [blame] | 80 | if [ -z "$link" ] ; then |
| 81 | echo "You must specify a link name with --link" |
Jeremy White | 8dad1d8 | 2001-01-17 20:17:03 +0000 | [diff] [blame] | 82 | usage |
| 83 | fi |
| 84 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 85 | desktop_entry() |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 86 | { |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 87 | cat <<EOF |
| 88 | [Desktop Entry] |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 89 | Name=$linkname |
Marcus Meissner | cb54fe6 | 2004-09-27 20:32:50 +0000 | [diff] [blame] | 90 | Exec=wine "$path" $args |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 91 | Type=Application |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 92 | EOF |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 93 | [ -z "$descr" ] || echo "Comment=$descr" |
Vitaly Lipatov | 5072fd4 | 2006-03-26 19:06:54 +0400 | [diff] [blame] | 94 | [ -z "$workdir" ] || echo "Path=$workdir" |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 95 | [ -z "$xpmicon" ] || echo "Icon=$xpmicon" |
| 96 | } |
| 97 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 98 | directory_entry() |
Dusan Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 99 | { |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 100 | cat <<EOF |
| 101 | [Desktop Entry] |
| 102 | Type=Directory |
| 103 | EOF |
| 104 | if [ "$1" == "wine" ] ; then |
| 105 | echo "Name=Wine" |
| 106 | echo "Icon=wine" |
| 107 | else |
| 108 | echo "Name=$1" |
| 109 | echo "Icon=folder" |
| 110 | fi |
Dusan Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 113 | # copy the icon file to a specified dir and set xpmicon to the resulting path |
| 114 | copy_icon() |
| 115 | { |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 116 | if [ -f "$icon" ] |
| 117 | then |
| 118 | xpmicon=`basename "$icon" .xpm` |
| 119 | |
| 120 | mkdir -p "$1" |
| 121 | cp "$icon" "$1/$xpmicon.xpm" |
| 122 | else |
| 123 | xpmicon="" |
| 124 | fi |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 127 | # XDG |
Dusan Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 128 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 129 | xdg_config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/menus/applications-merged" |
| 130 | xdg_data_dir="${XDG_DATA_HOME:-$HOME/.local/share}" |
Dusan Lacko | 8e44ba1 | 2001-11-20 18:53:33 +0000 | [diff] [blame] | 131 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 132 | # Create common directories |
| 133 | mkdir -p "$xdg_config_dir" |
| 134 | mkdir -p "$xdg_data_dir/desktop-directories" |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 135 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 136 | get_menu_entries() |
| 137 | { |
| 138 | tmp="$xdg_config_dir/$1.menu" |
Jeremy White | 8dad1d8 | 2001-01-17 20:17:03 +0000 | [diff] [blame] | 139 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 140 | if [ -r "$tmp" ] ; then |
| 141 | awk ' |
| 142 | BEGIN { RS="<" } |
| 143 | /^Filename/ { |
| 144 | if (match($0,/>/)) { |
| 145 | print substr($0,RSTART+1) |
| 146 | } |
| 147 | }' $tmp |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 148 | fi |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 149 | } |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 150 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 151 | # Input |
| 152 | # menu file name |
| 153 | # new item |
| 154 | write_menu_file() |
| 155 | { |
| 156 | tmpfile=`mktemp` |
| 157 | ( |
| 158 | echo '<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"' |
| 159 | echo '"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">' |
| 160 | echo '<Menu>' |
| 161 | echo ' <Name>Applications</Name>' |
Dustin Navea | 35ba7b9 | 2002-04-29 19:33:09 +0000 | [diff] [blame] | 162 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 163 | IFS="-" |
Marcus Meissner | b686a90 | 2001-03-08 01:12:52 +0000 | [diff] [blame] | 164 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 165 | fullname='wine' |
| 166 | for i in $1; do |
| 167 | echo " <Menu>" |
| 168 | echo " <Name>$fullname-$i</Name>" |
| 169 | echo " <Directory>$fullname-$i.directory</Directory>" |
Dustin Navea | 9df2e56 | 2002-05-23 16:31:22 +0000 | [diff] [blame] | 170 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 171 | dir_file_name="$xdg_data_dir/desktop-directories/$fullname-$i.directory" |
| 172 | if [ ! -f "$dir_file_name" ] ; then |
| 173 | directory_entry "$i" > "$dir_file_name" |
| 174 | fi |
| 175 | test "$i" = "wine" || fullname="$fullname-$i" |
| 176 | done |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 177 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 178 | echo " <Include>" |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 179 | |
Vitaliy Margolen | da36762 | 2006-11-24 13:53:29 -0700 | [diff] [blame^] | 180 | IFS=" |
| 181 | " |
| 182 | for i in $(get_menu_entries "$1"); do |
| 183 | test "$i" = "$2" && continue |
| 184 | echo " <Filename>$i</Filename>" |
| 185 | done |
| 186 | |
| 187 | # New record |
| 188 | echo " <Filename>$2</Filename>" |
| 189 | echo " </Include>" |
| 190 | |
| 191 | IFS='-' |
| 192 | for i in $1; do |
| 193 | echo " </Menu>" |
| 194 | done |
| 195 | echo '</Menu>' |
| 196 | ) > $tmpfile |
| 197 | chmod 0600 $tmpfile |
| 198 | |
| 199 | mv -f $tmpfile "$xdg_config_dir/$1.menu" |
| 200 | } |
| 201 | |
| 202 | |
| 203 | copy_icon "$xdg_data_dir/icons" |
| 204 | |
| 205 | linkname=`basename "$link"` |
| 206 | |
| 207 | if [ $mode = "menu" ] ; then |
| 208 | mkdir -p "$xdg_data_dir/applications/wine/`dirname "$link"`" |
| 209 | |
| 210 | linkpath=`dirname "$link" | sed 's!/!-!g'` |
| 211 | if [ "$linkpath" == "." ] ; then |
| 212 | linkpath="" |
| 213 | else |
| 214 | linkpath="-$linkpath" |
| 215 | fi |
| 216 | |
| 217 | desktop_entry > "$xdg_data_dir/applications/wine/$link.desktop" |
| 218 | write_menu_file "wine$linkpath" "wine$linkpath-$linkname.desktop" |
| 219 | else |
| 220 | desktop_entry > "$HOME/Desktop/$linkname.desktop" |
Alexandre Julliard | e2b4efb | 2000-11-02 20:22:07 +0000 | [diff] [blame] | 221 | fi |
| 222 | |
| 223 | exit 0 |