#!/bin/sh
# (c) Copyright 2001-2012. CodeWeavers, Inc.
kde_on=0
kde_version=""
kde_user_menu=""
kde_user_alt_menu=""
kde_user_mime=""
kde_global_menu=""
kde_global_alt_menu=""
kde_global_mime=""
kde_preferred_menu=""
kde_preferred_alt_menu=""
kde_preferred_mime=""
kde_mime_path=""
xdg_menu_on=0
xdg_user_data=""
xdg_global_data=""
xdg_preferred_data=""
xdg_data_dirs=""
xdg_mime_on=0
dtop_on=0
dtop_user_desktop=""
dtop_user_alt_desktop=""
dtop_global_desktop=""
dtop_global_alt_desktop=""
dtop_preferred_desktop=""
dtop_preferred_alt_desktop=""
debian_menu_on=0
debian_user_menu=""
debian_global_menu=""
debian_old_global_menu=""
debian_preferred_menu=""
debian_old_preferred_menu=""
debian_mime_on=0
debian_global_assoc=""
debian_preferred_assoc=""
cde_on=0
cde_user_dt=""
cde_user_wm=""
cde_global_dt=""
cde_global_wm=""
cde_preferred_dt=""
cde_preferred_wm=""
macosx_on=0
mailcap_on=0
mailcap_user_mailcap=""
mailcap_user_mime=""
mailcap_global_mailcap=""
mailcap_global_mime=""
mailcap_preferred_mailcap=""
mailcap_preferred_mime=""
desktop_assoc_ignore_list=""
desktop_menu_ignore_list=""
# Directories where to look for KDE.
kde_global_dirs="/usr /opt/kde4 /opt/kde3 /opt/kde2 /opt/kde /usr/kde/4 /usr/kde/3 /usr/kde"
kde_user_dirs="$HOME/.kde $HOME/.kde4 $HOME/.kde3 $HOME/.kde2"
# ----- Options ------
# Portable which(1) implementation
cxwhich()
{
case "$1" in
/*)
if [ -x "$1" -a -f "$1" ]
then
echo "$1"
return 0
fi
;;
*/*)
if [ -x "`pwd`/$1" -a -f "`pwd`/$1" ]
then
echo "`pwd`/$1"
return 0
fi
;;
*)
saved_ifs="$IFS"
IFS=":"
for d in $PATH
do
IFS="$saved_ifs"
if [ -n "$d" -a -x "$d/$1" -a -f "$d/$1" ]
then
echo "$d/$1"
return 0
fi
done
;;
esac
return 1
}
error()
{
name0=`basename "$0"`
echo "$name0:error: " "$@" >&2
}
usage=""
quiet=0
scope="private"
menu=0
assoc=0
while [ $# -gt 0 ]
do
case "$1" in
--quiet)
quiet=1
shift
;;
--scope)
scope="$2"
shift 2
;;
--menu)
menu=1
shift
;;
--assoc)
assoc=1
shift
;;
--help|-h|-\?)
usage=0
shift
;;
*)
error "unknown option '$1'"
usage=2
shift
;;
esac
done
if [ $menu -eq 0 -a $assoc -eq 0 ]
then
menu=1
assoc=1
fi
if [ "$scope" != "managed" -a "$scope" != "private" ]
then
error "unknown scope '$scope'"
usage=2
fi
# Check that we can use $HOME and if not, unset it so buggy applications,
# like Ubuntu's kde-config, don't try to write to it
if [ -n "$HOME" ]
then
if [ ! -d "$HOME" -o ! -w "$HOME" ]
then
unset HOME
elif perl -e 'exit(($> == 0 and !-o $ARGV[0]) ? 0 : 1)' "$HOME"
then
# Probably an 'su' that did not update $HOME
unset HOME
fi
fi
if [ "$scope" != "managed" -a -z "$HOME" ]
then
error "\$HOME must be set correctly and be writable for --scope private"
usage=2
fi
if [ -n "$usage" ]
then
name0=`basename "$0"`
if [ $usage -ne 0 ]
then
error "try '$name0 --help' for more information"
exit $usage
fi
cat <<EOF
Usage: $name0 [--quiet] [--scope SCOPE] [--menu|--assoc]
Scans for menu and association systems and returns their locations.
Options:
--quiet Don't print the shell commands that set all the variables
--scope SCOPE If set to 'managed' return the system wide locations as the
preferred location, otherwise return the per-user location
--menu Only scan for menuing systems
--assoc Only scan for association systems
EOF
exit 0
fi
# ----- KDE ------
safe_kde_config()
{
decoy=""
if [ -z "$HOME" ]
then
decoy="/tmp/decoy.$$"
HOME="$decoy"
touch "$decoy"
fi
"$KDE_CONFIG" "$@"
rc=$?
[ -z "$decoy" ] || rm "$decoy"
return $rc
}
# kde-config is not in $PATH when installing an RPM package on SuSE
# And it is not in root's $PATH on Solaris
PATH="$PATH:/opt/kde3/bin:/opt/sfw/kde/bin"
KDE_CONFIG=""
cxwhich kde4-config >/dev/null && KDE_CONFIG="kde4-config"
cxwhich kde-config >/dev/null && KDE_CONFIG="kde-config"
# First try to use kde-config.
if [ -n "$KDE_CONFIG" ]
then
kde_apps=`safe_kde_config --path apps 2>/dev/null`
rc=$?
kde_user_prefix=`safe_kde_config --localprefix 2>/dev/null`
rc=`expr $rc + $?`
kde_global_prefix=`safe_kde_config --prefix 2>/dev/null`
rc=`expr $rc + $?`
kde_user_config=`safe_kde_config --path config 2>/dev/null`
rc=`expr $rc + $?`
if [ $assoc -ne 0 ]
then
kde_mime_path=`safe_kde_config --path mime 2>/dev/null`
rc=`expr $rc + $?`
kde_mime_path=`echo "$kde_mime_path" | sed -e 's%/:%:%g' -e 's%/$%%'`
fi
if [ $rc -eq 0 -a -n "$kde_user_prefix" -a -n "$kde_global_prefix" ]
then
kde_on=1
# Many kde-config commands return multiple paths so we have to pick
# the right one (user/global).
kde_user_config=`echo "$kde_user_config" | tr ':' '\n' | egrep "^$kde_user_prefix" | head -n 1`
if [ -z "$kde_user_config" ]
then
# kde-config --localprefix is broken on Gentoo so that we don't
# find any match. Use $HOME instead.
kde_user_prefix="$HOME/.kde"
kde_user_config=`echo "$kde_user_config" | tr ':' '\n' | egrep "^$kde_user_prefix" | head -n 1`
fi
# We need these for the KDE MIME types too
kde_user_menu=`echo "$kde_apps" | tr ':' '\n' | egrep "^$kde_user_prefix" | sed -e '2,$ d' -e 's%/$%%'`
kde_global_menu=`echo "$kde_apps" | tr ':' '\n' | egrep "^$kde_global_prefix" | sed -e '2,$ d' -e 's%/$%%'`
if [ $assoc -ne 0 ]
then
kde_user_mime=""
kde_local_mime=""
kde_global_mime=""
kde_other_mime=""
original_ifs="$IFS"
IFS=":"
for dir in $kde_mime_path
do
IFS="$original_ifs"
if [ -z "$kde_user_mime" ] && echo "$dir" | egrep "^$kde_user_prefix" >/dev/null
then
kde_user_mime="$dir"
elif [ -z "$kde_local_mime" ] && echo "$dir" | egrep "^/usr/local/" >/dev/null
then
kde_local_mime="$dir"
elif [ -z "$kde_global_mime" ] && echo "$dir" | egrep "^$kde_global_prefix" >/dev/null
then
kde_global_mime="$dir"
else
kde_other_mime="$dir"
fi
done
if [ -z "$kde_global_mime" ]
then
if [ -n "$kde_local_mime" ]
then
kde_global_mime="$kde_local_mime"
else
kde_global_mime="$kde_other_mime"
fi
fi
fi
fi
fi
# kde-config isn't installed.
if [ $kde_on = 0 ]
then
# So, try to find the global KDE directory.
for dir in $kde_global_dirs
do
if [ -d "$dir/share/mimelnk" ]
then
kde_global_prefix="$dir"
kde_on=1
break
fi
done
# We found KDE global directory.
if [ $kde_on = 1 ]
then
# Try to find the user KDE dir.
for dir in $kde_user_dirs
do
if [ -d "$dir/share/mimelnk" ]
then
kde_user_prefix="$dir"
break
fi
done
# If no KDE user dir found, use $HOME/.kde as default.
if [ -z "$kde_user_prefix" ]
then
kde_user_prefix="$HOME/.kde"
fi
# We need these for the KDE MIME types too
kde_user_menu="$kde_user_prefix/share/applnk"
kde_global_menu="$kde_global_prefix/share/applnk"
if [ $assoc -ne 0 ]
then
kde_user_mime="$kde_user_prefix/share/mimelnk"
kde_global_mime="$kde_global_prefix/share/mimelnk"
Loading ...