#!/bin/bash # Distributed under the terms of the GNU General Public License v2 # Author: David Gümbel # Based on Gentoo's gcc-config by Martin Schlemmer source /etc/init.d/functions.sh || { echo "$0: Could not source /etc/init.d/functions.sh!" exit 1 } usage() { cat << "USAGE_END" Usage: wine-config [options] [wine Profile] Change the current wine profile, or give info about profiles. Options: -c, --get-current-profile Print current used wine profile. -l, --list-profiles Print a list of available profiles. -E, --print-environ Print environment that can be used to setup the current wine profile, or a specified one. -B, --get-bin-path Print path where binaries of the given/current profile are located. -L, --get-lib-path Print path where libraries of the given/current profile are located. -X, --get-wine-incdir Print path where wine include files of the given/current profile are located. Profile names are of the form: - For example: wine-20041019 crossover-office-3.0.1 USAGE_END exit 1 } if [ "$#" -lt 1 ] then usage fi find_path() { [ -z "$1" ] && return 0 local fullpath="$(type -P $1)" if [ -x "${fullpath}" ] then echo "${fullpath}" return 0 fi for x in /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin do if [ -x "${x}/$1" -a -r "${x}/$1" ] then echo "${x}/$1" return 0 fi done return 0 } cmd_setup() { # Sourcing /etc/env.d/wine/${WINE} is going to mess up # PATH among things... CP="$(find_path cp)" RM="$(find_path rm)" MV="$(find_path mv)" LN="$(find_path ln)" CAT="$(find_path cat)" AWK="$(find_path gawk)" GREP="$(find_path grep)" FIND="$(find_path find)" CHMOD="$(find_path chmod)" TOUCH="$(find_path touch)" ENV_UPDATE="$(find_path env-update)" } switch_profile() { local MY_LDPATH= local WINE_PROFILES= local OLD_WINE= local WINE_BIN_PATH= if [ -r /etc/env.d/wine/config ] then source /etc/env.d/wine/config if [ -n "${CURRENT}" ] then OLD_WINE="${CURRENT}" fi fi if [ "$(id -u)" -ne 0 ] then eerror "$0: Must be root." exit 1 fi ebegin "Switching to wine profile ${WINE}" # Sourcing /etc/env.d/wine/${WINE} is going to mess up # PATH among things... cmd_setup # Setup things properly again for this profile source "/etc/env.d/wine/${WINE}" MY_LDPATH=${LDPATH} # Setup /etc/env.d/99wine ${AWK} '!/^WINE_INCDIR=|^LDPATH=/ {print $0}' \ "/etc/env.d/wine/${WINE}" > /etc/env.d/99wine # Add our custom LDPATH echo "LDPATH=\"${MY_LDPATH}\"" >> /etc/env.d/99wine echo "CURRENT=${WINE}" > /etc/env.d/wine/config # Fix environment source /etc/profile ${ENV_UPDATE} &> /dev/null eend 0 if [ "${OLD_WINE}" != "${WINE}" ] then echo ewarn "If you intend to use the wine from the new profile in an already" ewarn "running shell, please remember to do:" echo ewarn " # source /etc/profile" echo fi return 0 } get_current_profile() { if [ ! -f /etc/env.d/wine/config ] then eerror "$0: No wine profile is active!" return 1 fi source /etc/env.d/wine/config if [ -z "${CURRENT}" ] then eerror "$0: No wine profile is active!" return 1 fi echo "${CURRENT}" return 0 } list_profiles() { local i=1 if [ ! -f /etc/env.d/wine/config ] then eerror "$0: No wine profile is active!" return 1 fi get_current_profile > /dev/null for x in /etc/env.d/wine/* do if [ -f "${x}" -a "${x}" != "/etc/env.d/wine/config" ] then x="${x##*/}" [ "${x}" == "${CURRENT}" ] && x="${x} *" echo "[${i}] ${x}" i=$((i + 1)) fi done } print_environ() { local OLDPATH="${PATH}" local ENV_CMD= local SET_ELEMENT= source "/etc/env.d/wine/${WINE}" case ${SHELL} in */csh|*/tsch) ENV_CMD="setenv" SET_ELEMENT=" " ;; *) ENV_CMD="export" SET_ELEMENT="=" ;; esac echo "${ENV_CMD} PATH${SET_ELEMENT}\"${PATH}:${OLDPATH}\"" # if [ -z "${LD_LIBRARY_PATH}" ] # then # echo "${ENV_CMD} LD_LIBRARY_PATH${SET_ELEMENT}\"${LDPATH}\"" # else # echo "${ENV_CMD} LD_LIBRARY_PATH${SET_ELEMENT}\"${LDPATH}:${LD_LIBRARY_PATH}\"" # fi # no, we don't actually need to print this here (?) #echo "${ENV_CMD} LDPATH${SET_ELEMENT}\"${LDPATH}\"" } get_bin_path() { if [ -e /etc/env.d/wine/${WINE} ] ; then source "/etc/env.d/wine/${WINE}" echo "${PATH}" else echo "no-config" echo "/etc/env.d/wine/${WINE} doesnt exist" 1>&2 fi return 0 } get_lib_path() { if [ -e /etc/env.d/wine/${WINE} ] ; then source "/etc/env.d/wine/${WINE}" echo "${LDPATH}" else echo "no-config" echo "/etc/env.d/wine/${WINE} doesnt exist" 1>&2 fi return 0 } get_wine_incdir() { if [ -e /etc/env.d/wine/${WINE} ] ; then source "/etc/env.d/wine/${WINE}" echo "${WINE_ROOT_GENTOO}/include/${WINE_INCDIR}" else echo "no-config" echo "/etc/env.d/wine/${WINE} doesnt exist" 1>&2 fi return 0 } NEED_ACTION="yes" DOIT="switch_profile" CHECK_CHOST="no" for x in "$@" do case "${x}" in # Only use specified compiler if one is not already selected. # -O|--use-old) # if get_current_profile &> /dev/null # then # WINE="$(get_current_profile)" # fi # ;; -c|--get-current-profile) if [ "${NEED_ACTION}" = "yes" ] then NEED_ACTION="no" DOIT="get_current_profile" fi ;; -l|--list-profiles) if [ "${NEED_ACTION}" = "yes" ] then NEED_ACTION="no" DOIT="list_profiles" fi ;; -E|--print-environ) if [ "${NEED_ACTION}" = "yes" ] then NEED_ACTION="no" DOIT="print_environ" fi ;; -B|--get-bin-path) if [ "${NEED_ACTION}" = "yes" ] then NEED_ACTION="no" DOIT="get_bin_path" fi ;; -L|--get-lib-path) if [ "${NEED_ACTION}" = "yes" ] then NEED_ACTION="no" DOIT="get_lib_path" fi ;; -X|--get-wine-incdir) if [ "${NEED_ACTION}" = "yes" ] then NEED_ACTION="no" DOIT="get_wine_incdir" fi ;; -h|--help) usage exit 0 ;; -v|--version) echo "wine-config-0.1" exit 0 ;; -*) eerror "$0: Invalid switch! Run $0 without parameters for help." exit 1 ;; *) if [ -z "${WINE}" ] then if [ -n "`echo ${x} | gawk '/^[[:digit:]]*$/ { print }'`" ] then i=1 for y in /etc/env.d/wine/* do [ "${y}" = "/etc/env.d/wine/config" ] && continue if [ -f "${y}" -a "${x}" -eq "${i}" ] then WINE="${y##*/}" break else i=$((i + 1)) fi done else WINE="${x}" fi fi ;; esac done if [ "${DOIT}" = "switch_profile" -a -z "${WINE}" ] then usage fi if [ -z "${WINE}" ] then if get_current_profile &> /dev/null then WINE="$(get_current_profile)" else eerror "$0: No default profile setup!" exit 1 fi fi WINE_NO_SPECS=$(echo ${WINE} | awk -F- '{ print $1"-"$2"-"$3"-"$4"-"$5 }') #if [ ! -d "/usr/lib/gcc-lib/${WINE_NO_SPECS%-*}/${WINE_NO_SPECS##*-}" -o \ if [ ! -f "/etc/env.d/wine/${WINE}" ] then eerror "$0: Profile does not exist or invalid setting for /etc/env.d/wine/${WINE}" #exit 1 fi eval ${DOIT} # vim:ts=4