aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNP-Hardass <np.hardass@gmail.com>2017-03-07 14:54:59 -0500
committerNP-Hardass <np.hardass@gmail.com>2017-03-07 14:54:59 -0500
commit03c60e26d97acaec4337234b4c24b3731dc8d1ca (patch)
tree34c70bfc763f74856bfd992ab3738057235d6660
parentfix typo (diff)
downloadeselect-wine-0.99_rc1.tar.gz
eselect-wine-0.99_rc1.tar.bz2
eselect-wine-0.99_rc1.zip
Overhaul, initial commitv0.99_rc1
-rw-r--r--wine.eselect899
1 files changed, 611 insertions, 288 deletions
diff --git a/wine.eselect b/wine.eselect
index 41e6d8f..3a69218 100644
--- a/wine.eselect
+++ b/wine.eselect
@@ -1,267 +1,275 @@
# -*-eselect-*- vim: ft=eselect
-# Copyright 2005-2014 Gentoo Foundation
+# Copyright 2005-2017 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later
-inherit multilib tests
+inherit config multilib tests
DESCRIPTION="Manage active wine version"
-MAINTAINER=""
-
-VARIANTS=(staging vanilla)
-
-PREFIXDIR=/usr/lib
-BINDIR=/usr/bin
-EXECUTABLES=(msiexec notepad regedit regsvr32 widl wine wine64 wine64-preloader
-wineboot winebuild winecfg wineconsole winecpp winedbg winefile wineg++ winegcc
-winemine winepath wine-preloader wineserver wmc wrc)
-MANDIR=/usr/share/man
-MANPAGES=(man1/widl.1 man1/winebuild.1 man1/winegcc.1 man1/wineg++.1
-man1/winecpp.1 man1/wineserver.1 man1/wine.1 man1/wmc.1 man1/wrc.1
-man1/msiexec.1 man1/notepad.1 man1/regedit.1 man1/regsvr32.1 man1/wineboot.1
-man1/winecfg.1 man1/wineconsole.1 man1/winedbg.1 man1/winefile.1
-man1/winemine.1 man1/winepath.1)
-DESKTOPFILES=(wine.desktop)
-DESKTOPDIR=/usr/share/applications
+MAINTAINER="NP-Hardass@gentoo.org"
-# sort function for versions, to be used in a pipe
-sort_versions() {
- local vsort="sort --version-sort"
- # Test if our sort supports the --version-sort option (posix does)
- ${vsort} </dev/null &>/dev/null || vsort=sort
+CONFIG_DIR="/etc/eselect/wine"
- # We sort versions as follows:
- # 1. Run sed to prepend the version string by the numeric version
- # 1.7.21 wine-1.7.21
- # 1.7.14 wine-compholio-1.7.14
- # 2. sort --version-sort
- # 3. Run sed again to remove the prepended keys from step 1.
- sed -e 's/^\(.\+-\)\([[:digit:].]*\)$/\2 &/' \
- | LC_ALL=C ${vsort} | sed 's/.* //'
-}
+VARIANTS=(
+ d3d9
+ staging
+ vanilla
+)
-# find a list of available wine versions
-find_targets() {
- local f
- for f in "${EROOT}${PREFIXDIR}"/wine-*; do
- [[ -f ${f}/bin/wine ]] && echo "${f##*/}"
- done | sort_versions
-}
+################################################################################
+# Eselect Wine #
+################################################################################
-find_variant_targets() {
- local variant=$1
- [[ -n $variant ]] || die "\$variant is empty :("
- local f
- for f in "${EROOT}${PREFIXDIR}/wine-${variant}-"*; do
- [[ -f ${f}/bin/wine ]] && echo "${f##*/}"
- done | sort_versions
-}
-
-# lifted from fdo-mime.eclass
-desktop_database_update() {
- if [[ -x "${EPREFIX}/usr/bin/update-desktop-database" ]]; then
- echo "Updating desktop mime database ..."
- "${EPREFIX}/usr/bin/update-desktop-database" -q "${EROOT}usr/share/applications"
+# Verify that files exist for specified target
+# Input: ${P}
+is_valid_target(){
+ if [[ $# -ne 1 ]]; then
+ die "Invalid number of parameters"
fi
-}
+
+ local tgt="$1"
-# remove wine symlinks
-remove_symlinks() {
- for exe in "${EXECUTABLES[@]}"; do
- if [[ -L ${EROOT}${BINDIR}/${exe} ]]; then
- rm "${EROOT}${BINDIR}/${exe}" || return 1
- fi
- done
+ set_dir_env
- for page in "${MANPAGES[@]}"; do
- if [[ -L ${EROOT}/${MANDIR}/${page} ]]; then
- rm "${EROOT}/${MANDIR}/${page}" || return 1
- fi
- done
- for d in "${DESKTOPFILES[@]}"; do
- if [[ -L ${EROOT}/${DESKTOPDIR}/${d} ]]; then
- rm "${EROOT}/${DESKTOPDIR}/${d}" || return 1
- fi
- done
- if [[ -L ${EROOT}/usr/include/wine ]]; then
- rm "${EROOT}/usr/include/wine" || return 1
- fi
- for d in $(list_libdirs); do
- local ld=/usr/$d
- [[ -L $ld ]] && continue
- for f in "$ld"/libwine.so*; do
- rm -f "$f" || return 1
- done
- if [[ -L ${ld}/wine ]]; then
- rm -f "${ld}/wine" || return 1
- fi
- done
-
- desktop_database_update
+ if [[ ! -d "${wine_bin}" ]] || \
+ [[ ! "$(ls -A ${wine_bin})" ]] || \
+ [[ ! -e "${wine_bin}/wine" ]]; then
+ return 1
+ elif [[ ! -e "${EPREFIX}/usr/bin/${tgt}" ]]; then
+ return 1
+ else
+ return 0
+ fi
- return 0
+ unset_dir_env
}
-# remove variant wine symlinks
-# usage: remove_variant_symlinks <variant>
-remove_variant_symlinks() {
- local variant=$1
- [[ -n $variant ]] || die "\$variant is empty :("
+# Verify that symlinks are valid
+are_symlinks_valid() {
+ if [[ $# -gt 1 ]]; then
+ die "Invalid number of parameters"
+ fi
+
+ local v="wine"
- for exe in "${EXECUTABLES[@]}"; do
- if [[ -L ${EROOT}${BINDIR}/${exe}-${variant} ]]; then
- rm "${EROOT}${BINDIR}/${exe}-${variant}" || return 1
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die "Invalid variant"
+ fi
+ else
+ die "Invalid parameter"
fi
+ shift
done
- return 0
+ local active=$(load_config "${CONFIG_DIR}/active" ${v})
+ if [[ "${active}" == "(unset)" ]]; then
+ write_error_message "Invalid active config"
+ return 1
+ fi
+
+ set_dir_env
+
+ #TODO check links manually and by config
+ unset_dir_env
}
-# set wine symlinks
-# Usage: set_symlinks <name|number>
-set_symlinks() {
- local target=$1
- if is_number "${target}"; then
- local targets=( $(find_targets) )
- target=${targets[target-1]}
+# print currently selected wine
+get_active() {
+ if [[ $# -gt 1 ]]; then
+ die -q "Invalid number of parameters specified"
fi
- if [[ -z ${target} ]]; then
- die "Target \"$target\" doesn't appear to be valid!"
- elif [[ -f ${EROOT}${PREFIXDIR}/${target}/bin/wine ]]; then
+ local v="wine"
- for exe in "${EXECUTABLES[@]}"; do
- local tgtexe="${exe}"-"${target#wine-}"
- if [[ -f ${EROOT}${BINDIR}/${tgtexe} ]] || [[ -L ${EROOT}${BINDIR}/${tgtexe} ]]; then
- ln -s "${tgtexe}" "${EROOT}${BINDIR}/${exe}" || return 1
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die -q "Invalid variant"
fi
- done
+ else
+ [[ -z $1 ]] || die -q "Invalid parameter"
+ fi
+ shift
+ done
- for page in "${MANPAGES[@]}"; do
- if [[ -f ${EROOT}${PREFIXDIR}/${target}/man/${page} ]]; then
- ln -s "${EROOT}${PREFIXDIR}/${target}/man/${page}" "${EROOT}/${MANDIR}/${page}" || return 1
- fi
- done
+ local active=$(load_config "${CONFIG_DIR}/active" ${v})
- for d in "${DESKTOPFILES[@]}"; do
- if [[ -f ${EROOT}${PREFIXDIR}/${target}/applications/${d} ]]; then
- ln -s "${EROOT}${PREFIXDIR}/${target}/applications/${d}" "${EROOT}/${DESKTOPDIR}/${d}" || return 1
- fi
- done
+ if [[ -z "${active}" ]]; then
+ echo "(unset)"
+ else
+ echo "${active}"
+ fi
+}
- if [[ -d ${EROOT}${PREFIXDIR}/${target}/include/wine ]]; then
- ln -s "${EROOT}${PREFIXDIR}/${target}/include/wine" "${EROOT}/usr/include/wine" || return 1
- fi
+get_installed(){
+ if [[ $# -gt 1 ]]; then
+ die -q "Invalid number of parameters specified"
+ fi
- for d in $(list_libdirs); do
- local ld=/usr/$d
- [[ -L $ld ]] && continue
- local wined=${EROOT}${PREFIXDIR}/${target}/${d}
- for f in "${wined}"/libwine.so*; do
- ln -s "$f" "$ld"/ || return 1
- done
- if [[ -d ${wined}/wine ]]; then
- ln -s "${wined}/wine" "$ld"/wine || return 1
+ local v="wine"
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die -q "Invalid variant"
fi
- done
+ else
+ die -q "Invalid parameter"
+ fi
+ shift
+ done
- else
- die "Target \"$target\" doesn't appear to be valid!"
- fi
+ local installed=$(load_config "${CONFIG_DIR}/installed" ${v})
- desktop_database_update
+ echo $(sort_list ${installed[@]})
+}
- return 0
+### Registration action ##
+describe_register(){
+ echo "Register a new package with the eselect module (Internal use only)"
}
-# set variant wine symlinks
-# usage: set_variant_symlinks <variant> <name|number>
-set_variant_symlinks() {
- local variant=$1
- [[ -n $variant ]] || die "\$variant is empty :("
+describe_register() {
+ echo "<target>"
+}
- local target=$2
+describe_register_options() {
+ for v in ${VARIANTS[@]}; do
+ echo "--${v} : Register a new package with ${v}"
+ done
+ echo "target : A fully qualified variant e.g."
+ echo " : wine-1.9.23, wine-vanilla-2.0, or wine-staging-2.1.1"
+}
- if is_number "${target}"; then
- local targets=( $(find_variant_targets "$variant") )
- target=${targets[target-1]}
+do_register(){
+ if [[ $# -lt 1 ]] || [[ $# -gt 3 ]]; then
+ die -q "Invalid number of parameters specified"
fi
- if [[ -z ${target} ]]; then
- die "Target \"$target\" doesn't appear to be valid!"
- elif [[ -f ${EROOT}${PREFIXDIR}/${target}/bin/wine ]]; then
+ local v="wine"
- for exe in "${EXECUTABLES[@]}"; do
- local tgtexe="${exe}"-"${target#wine-}"
- if [[ -f ${EROOT}${BINDIR}/${tgtexe} || -L ${EROOT}${BINDIR}/${tgtexe} ]]; then
- ln -s "${tgtexe}" "${EROOT}${BINDIR}/${exe}-${variant}" || return 1
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die -q "Invalid flag or variant"
fi
- done
+ else
+ local tgt="$1"
+ fi
+ shift
+ done
- else
- die "Target \"$target\" doesn't appear to be valid!"
+ if [[ -z "${tgt}" ]]; then
+ die -q "Target not specified"
fi
- return 0
-}
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
+ fi
-# print currently selected wine
-get_current() {
- if [[ -L ${EROOT}${BINDIR}/wine ]]; then
- local winefull=$(canonicalise "${EROOT}${BINDIR}/wine")
- local wine="${winefull##*/}"
- [[ -n $wine ]] || return 1
- echo "${wine}"
+ if is_number "${tgt}"; then
+ local tgts=($(get_installed ${v_arg}))
+ tgt=${tgts[${tgt}-1]}
fi
-}
-# print currently selected variant wine
-get_current_variant() {
- local variant=$1
- [[ -n $variant ]] || die "\$variant is empty :("
+ if ! is_valid_target "${tgt}"; then
+ die -q "Target does not exist"
+ fi
- if [[ -L ${EROOT}${BINDIR}/wine-${variant} ]]; then
- local winefull=$(canonicalise "${EROOT}${BINDIR}/wine-${variant}")
- local wine="${winefull##*/}"
- [[ -n $wine ]] || return 1
- echo "${wine}"
+ local list=$(get_installed ${v_arg})
+
+ if ! has ${tgt} ${list}; then
+ list=($(sort_list "${list} ${tgt}"))
+ store_config "${CONFIG_DIR}/installed" ${v} "${list[@]}"
fi
}
-### show action ###
+describe_deregister(){
+ echo "Deregister a package with the eselect module (Internal use only)"
+}
-describe_show() {
- echo "Show the active wine version"
+describe_deregister() {
+ echo "<target>"
}
-describe_show_options() {
+describe_deregister_options() {
for v in ${VARIANTS[@]}; do
- echo "--$v : Show the active 'wine-$v'"
+ echo "--${v} : Deregister a package with ${v}"
done
+ echo "--force : Forcibly remove a package"
+ echo "target : A fully qualified variant e.g."
+ echo " : wine-1.9.23, wine-vanilla-2.0, or wine-staging-2.1.1"
}
-do_show() {
- local variant=""
- if has "${1#--}" "${VARIANTS[@]}" ; then
- variant=${1#--}
+do_deregister(){
+ if [[ $# -lt 1 ]] || [[ $# -gt 3 ]]; then
+ die -q "Invalid number of parameters specified"
fi
- local wine
- if [[ -n $variant ]]; then
- write_list_start "Active wine-${variant} version:"
- wine=$(get_current_variant "$variant")
- else
- write_list_start "Active wine version:"
- wine=$(get_current)
- fi
- if [[ -n ${wine} ]]; then
- write_kv_list_entry "${wine}" ""
- local winedir=${EROOT}${PREFIXDIR}/${wine##*/}
- [[ -f ${winedir}/bin/wine ]] \
- || write_warning_msg "Symlink target doesn't appear to be valid!"
- else
- write_kv_list_entry "(unset)" ""
+ local v="wine"
+ local force=false
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ elif [[ "${flag}" == "force" ]]; then
+ force=true
+ else
+ die -q "Invalid variant"
+ fi
+ else
+ local tgt="$1"
+ fi
+ shift
+ done
+
+ if [[ -z "${tgt}" ]]; then
+ die -q "Target not specified"
+ fi
+
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
+ fi
+
+ if is_number "${tgt}"; then
+ local tgts=($(get_installed ${v_arg}))
+ tgt=${tgts[${tgt}-1]}
+ fi
+
+ if ! is_valid_target "${tgt}" && [[ ${force} == "false" ]]; then
+ die -q "Target does not exist"
fi
+
+ local list=$(get_installed ${v_arg})
+
+ if ! has ${tgt} ${list}; then
+ die -q "${tgt} is not registered for ${v}"
+ fi
+
+ if [[ "${tgt}" == "$(get_active ${v_arg})" ]]; then
+ do_unset ${v_arg}
+ fi
+
+ list=$(list_rm_item ${tgt} "${list}")
+ store_config "${CONFIG_DIR}/installed" ${v} "${list}"
}
### list action ###
@@ -272,38 +280,98 @@ describe_list() {
describe_list_options() {
for v in ${VARIANTS[@]}; do
- echo "--$v : List the available 'wine-$v'"
+ echo "--${v} : List the available 'wine-${v}'"
done
}
do_list() {
- local i
- local variant=""
- local targets
- if has "${1#--}" "${VARIANTS[@]}" ; then
- variant=${1#--}
+ if [[ $# -gt 1 ]]; then
+ die -q "Invalid number of parameters specified"
fi
- if [[ -n $variant ]]; then
- targets=( $(find_variant_targets "$variant") )
- write_list_start "Available wine-$variant versions:"
+ local v="wine"
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die -q "Invalid variant"
+ fi
+ else
+ die -q "Invalid parameter"
+ fi
+ shift
+ done
+
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
+ fi
+
+ write_list_start "Available wine${v_arg#-} versions:"
+ local installed=($(get_installed ${v_arg}))
+ local active=$(get_active ${v_arg})
+
+ if [[ ${#installed} -eq 0 ]]; then
+ unset installed
else
- targets=( $(find_targets) )
- write_list_start "Available wine versions:"
+ for (( i = 0; i < ${#installed[@]}; i++ )); do
+ if [[ ${installed[i]} = ${active} ]]; then
+ installed[i]=$(highlight_marker "${installed[i]}")
+ fi
+ done
+ fi
+
+ write_numbered_list -m "(none found)" "${installed[@]}"
+}
+
+### show action ###
+
+describe_show() {
+ echo "Show the active wine version"
+}
+
+describe_show_options() {
+ for v in ${VARIANTS[@]}; do
+ echo "--$v : Show the active 'wine-$v'"
+ done
+}
+
+do_show() {
+ if [[ $# -gt 1 ]]; then
+ die -q "Invalid number of parameters specified"
fi
- for (( i = 0; i < ${#targets[@]}; i++ )); do
- if [[ -n $variant ]]; then
- if [[ ${targets[i]} = $(get_current_variant "$variant") ]]; then
- targets[i]=$(highlight_marker "${targets[i]}")
+ local v="wine"
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die -q "Invalid variant"
fi
else
- if [[ ${targets[i]} = $(get_current) ]]; then
- targets[i]=$(highlight_marker "${targets[i]}")
- fi
+ die -q "Invalid parameter"
fi
+ shift
done
- write_numbered_list -m "(none found)" "${targets[@]}"
+
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
+ fi
+
+ write_list_start "Active wine${v_arg#-} version:"
+ local active=$(get_active ${v_arg})
+
+ write_kv_list_entry "${active}" ""
+ if [[ "${active}" != "(unset)" ]]; then
+ are_symlinks_valid ${v_arg}
+ fi
}
### unset action ###
@@ -320,23 +388,34 @@ describe_unset_options() {
}
do_unset() {
- local variant=""
- if has --all "$@"; then
- do_unset
- for variant in "${VARIANTS[@]}"; do
- do_unset "--${variant}"
- done
- return 0
+ if [[ $# -gt 1 ]]; then
+ die -q "Invalid number of parameters specified"
fi
- if has "${1#--}" "${VARIANTS[@]}" ; then
- variant=${1#--}
- fi
- if [[ -n $variant ]]; then
- remove_variant_symlinks "$variant" || die -q "Couldn't remove wine-${variant} symlinks"
- else
- remove_symlinks || die -q "Couldn't remove wine symlinks"
+ local v="wine"
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die -q "Invalid variant"
+ fi
+ else
+ die -q "Invalid parameter"
+ fi
+ shift
+ done
+
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
fi
+
+ remove_symlinks ${v_arg} || die -q "Couldn't remove wine${v_arg#-} symlinks"
+
+ store_config "${CONFIG_DIR}/active" "${v}" ""
}
### set action ###
@@ -357,32 +436,51 @@ describe_set_options() {
}
do_set() {
- local variant=""
- if has "${1#--}" "${VARIANTS[@]}" ; then
- variant=${1#--}
- shift
+ if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then
+ die -q "Invalid number of parameters specified"
fi
- [[ -z $1 ]] && die -q "You didn't tell me what version to symlink"
- [[ $# -gt 1 ]] && die "Too many parameters"
-
- local suffix=""
- [[ -n $variant ]] && suffix=-$variant
- for exe in "${EXECUTABLES[@]}"; do
- if [[ -L ${EROOT}${BINDIR}/${exe}${suffix} ]]; then
- continue
- elif [[ -e ${EROOT}${BINDIR}/${exe}${suffix} ]]; then
- # we have something strange
- die "${EROOT}${BINDIR}/${exe}${suffix} exists but is not a symlink"
+
+ local v="wine"
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die -q "Invalid flag or variant"
+ fi
+ else
+ local tgt="$1"
fi
+ shift
done
- if [[ -n $variant ]]; then
- remove_variant_symlinks "$variant"
- set_variant_symlinks "$variant" "$1"
- else
- remove_symlinks || die -q "Couldn't remove existing symlinks"
- set_symlinks "$1" || die -q "Couldn't set a new symlinks"
+ if [[ -z "${tgt}" ]]; then
+ die -q "Target not specified"
fi
+
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
+ fi
+
+ if is_number "${tgt}"; then
+ local tgts=($(get_installed ${v_arg}))
+ tgt=${tgts[${tgt}-1]}
+ fi
+
+ if ! is_valid_target "${tgt}"; then
+ die -q "Target does not exist"
+ fi
+
+ #TODO IF IS_SET
+# are_symlinks_valid ${v_arg} || die -q "Unable to continue, current state invalid"
+# remove_symlinks ${v_arg} || die -q "Couldn't remove wine${v_arg#-} symlinks"
+ do_unset ${v_arg} || die -q "Failed to unset active target"
+ set_symlinks ${v_arg} "${tgt}" || die -q "Couldn't set wine-${v_arg#-} symlinks"
+
+ store_config "${CONFIG_DIR}/active" "${v}" "${tgt}"
}
### update action ###
@@ -400,52 +498,277 @@ describe_update_options() {
}
do_update() {
- local variant=""
- if has --all "$@"; then
- if has --if-unset "$@"; then
- do_update --if-unset
- else
- do_update
- fi
- for variant in "${VARIANTS[@]}"; do
- if has --if-unset "$@"; then
- do_update "--${variant}" --if-unset
+ if [[ $# -gt 3 ]]; then
+ die -q "Invalid number of parameters specified"
+ fi
+
+ local v="wine"
+ local if_unset=false
+ local all=false
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ elif [[ "${flag}" == "if-unset" ]]; then
+ if_unset=true
+ elif [[ "${flag}" == "all" ]]; then
+ all=true
else
- do_update "--${variant}"
+ die -q "Invalid flag or variant"
fi
+ else
+ die -q "Invalid parameter"
+ fi
+ shift
+ done
+
+ if [[ "${v}" != "wine" ]] && ${all}; then
+ die -q "Either specify a specific variant, or all, but not both"
+ fi
+
+ # Run do_update for all variants
+ if ${all}; then
+ local unset_arg
+ if ${if_unset}; then
+ unset_arg="--if-unset"
+ fi
+
+ do_update ${unset_arg}
+ for v in ${VARIANTS[@]}; do
+ do_update "--${v}" ${unset_arg}
done
+
return 0
fi
- local v=0
- local arg
- for arg in "$@"; do
- if has "${arg#--}" "${VARIANTS[@]}" ; then
- variant=${arg#--}
- break
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
+ fi
+
+ # Determine if set and valid
+ # If so, return
+ if ${if_unset}; then
+ local active=$(get_active ${v_arg})
+ if is_valid_target "${active}" && are_symlinks_valid ${v_arg}; then
+ return 0
fi
+ fi
+
+ local installed=($(get_installed ${v_arg}))
+ if [[ ${#installed[@]} -eq 0 ]]; then
+ write_warning_msg "Skipping wine${v_arg#-}. No registered targets found."
+ return 0
+ fi
+ local tgt=${installed[-1]}
+
+ do_set ${v_arg} "${tgt}" || die -q "Couldn't set new wine${v_arg#-} symlinks"
+}
+
+
+# lifted from fdo-mime.eclass
+desktop_database_update() {
+ if [[ -x "${EPREFIX}/usr/bin/update-desktop-database" ]]; then
+ echo "Updating desktop mime database ..."
+ "${EPREFIX}/usr/bin/update-desktop-database" -q "${EROOT}usr/share/applications" || die
+ fi
+}
+
+# sort function for versions, to be used in a pipe
+sort_versions() {
+ local vsort="sort --version-sort"
+ # Test if our sort supports the --version-sort option (posix does)
+ ${vsort} </dev/null &>/dev/null || vsort=sort
+
+ # We sort versions as follows:
+ # 1. Run sed to prepend the version string by the numeric version
+ # 1.7.21 wine-1.7.21
+ # 1.7.14 wine-compholio-1.7.14
+ # 2. sort --version-sort
+ # 3. Run sed again to remove the prepended keys from step 1.
+ sed -e 's/^\(.\+-\)\([[:digit:].]*\)$/\2 &/' \
+ | LC_ALL=C ${vsort} | sed 's/.* //'
+}
+
+# Takes a list of items and returns a sorted version
+sort_list() {
+ list=($@)
+ if [[ ! -z "${list}" ]]; then
+ for i in ${list[@]}; do
+ echo "${i}"
+ done | sort_versions
+ fi
+}
+
+# Returns a list excluding the specified item
+# list_rm_item [rm_this] [list]
+list_rm_item() {
+ if [[ $# -lt 2 ]]; then
+ die "Not enough arguments"
+ fi
+
+ rm_this=$1
+ shift
+ list=($@)
+
+ local i
+ for i in ${!list[@]};do
+ if [ "${list[$i]}" == "${rm_this}" ]; then
+ unset list[$i]
+ fi
done
- if has --if-unset "$@"; then
- local wine
- if [[ -n $variant ]]; then
- wine=$(get_current_variant "$variant")
+
+ echo ${list[@]}
+}
+
+remove_symlinks() {
+ if [[ $# -gt 1 ]]; then
+ die -q "Invalid number of parameters specified"
+ fi
+
+ local v="wine"
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
+ else
+ die -q "Invalid flag or variant"
+ fi
else
- wine=$(get_current)
+ die -q "Invalid parameter"
fi
- if [[ -n ${wine} ]]; then
- v="${wine}"
- else
- if [[ -n $variant ]]; then
- echo "Current wine-${variant} is not valid, will update to newest"
+ shift
+ done
+
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
+ fi
+
+ local active=$(get_active ${v_arg})
+ if [[ "${active}" == "(unset)" ]]; then
+ return 0
+ #die -q "No active links to remove"
+ fi
+
+ if ! are_symlinks_valid ${v_arg}; then
+ die -q "Currently configured symlinks are invalid"
+ fi
+
+ local symlink_vars=$(load_config "${CONFIG_DIR}/links/${v}" symlink_dirs)
+ if [[ -z "${symlink_vars}" ]]; then
+ die -q "Missing listing of configured symlinks"
+ fi
+ local var
+ for var in ${symlink_vars[@]}; do
+ local symlinks=$(load_config "${CONFIG_DIR}/links/${v}" ${var})
+ local symlink
+ if [[ -z "${symlinks}" ]]; then
+ die -q "Missing listing of ${var} symlinks"
+ fi
+ for symlink in ${symlinks[@]}; do
+ if [[ ! -L "${symlink}" ]]; then
+ die -q "${symlink} is not a symlink."
+ fi
+ rm "${symlink}" || die "Failed to rm ${symlink}"
+
+ # remove entry from config file
+ symlinks=$(list_rm_item "${symlink}" "${symlinks}")
+
+ store_config "${CONFIG_DIR}/links/${v}" ${var} "${symlinks}"
+ done
+
+ # remove set from config file
+ symlink_vars=$(list_rm_item "${var}" "${symlink_vars}")
+
+ store_config "${CONFIG_DIR}/links/${v}" symlink_dirs "${symlink_vars}"
+ done
+
+# desktop_database_update || die "Failed to update xorg desktop database"
+}
+
+set_symlinks() {
+ if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then
+ die -q "Invalid number of parameters specified"
+ fi
+
+ local v="wine"
+
+ while [[ $# -gt 0 ]]; do
+ if [[ $1 == --* ]]; then
+ local flag="${1#--}"
+ if has "${flag}" ${VARIANTS[@]}; then
+ v=${flag}
else
- echo "Current wine is not valid, will update to newest"
+ die -q "Invalid flag or variant"
fi
+ else
+ local tgt="$1"
fi
+ shift
+ done
+
+ if [[ -z "${tgt}" ]]; then
+ die -q "Target not specified"
fi
- if [[ -n $variant ]]; then
- do_set "--$variant" "$v" || die -q "Couldn't set a new wine-$variant symlinks"
- else
- do_set "$v" || die -q "Couldn't set a new wine symlinks"
+ local v_arg
+ if [[ ${v} != "wine" ]]; then
+ v_arg="--${v}"
+ fi
+
+ if is_number "${tgt}"; then
+ local tgts=($(get_installed ${v_arg}))
+ tgt=${tgts[${tgt}-1]}
+ fi
+
+ if ! is_valid_target "${tgt}"; then
+ die -q "Target does not exist"
fi
+
+ set_dir_env
+
+ local link
+
+ store_config "${CONFIG_DIR}/links/${v}" symlink_dirs "bin"
+ store_config "${CONFIG_DIR}/links/${v}" "bin" ""
+ for b in "${wine_bin}"/*; do
+ #TODO detect errors and clean up
+ link="${PREFIX}/usr/bin/${b##*/}${v_arg#-}"
+ ln -s "${b}" "${link}"
+ append_config "${CONFIG_DIR}/links/${v}" "bin" "${link}"
+ done
+
+ append_config "${CONFIG_DIR}/links/${v}" symlink_dirs "man"
+ store_config "${CONFIG_DIR}/links/${v}" "man" ""
+ for md in "${wine_man}"/*; do
+ for m in "${md}"/*; do
+ #TODO detect errors and clean up
+ link="${PREFIX}/usr/share/man/${md##*/}/${m##*/}${v_arg#-}"
+ ln -s "${m}" "${link}"
+ append_config "${CONFIG_DIR}/links/${v}" "man" "${link}"
+ done
+ done
+
+ unset_dir_env
+
+# desktop_database_update || die "Failed to update xorg desktop database"
+}
+
+# set env vars for us to work with
+set_dir_env() {
+ wine_bin="${EPREFIX}/usr/lib/${tgt}/bin"
+ wine_include="${EPREFIX}/usr/include/${tgt}/wine"
+ wine_share="${EPREFIX}/usr/share/${tgt}"
+ wine_app="${wine_share}/applications"
+ wine_man="${wine_share}/man"
+}
+
+# unset our env vars
+unset_dir_env() {
+ unset wine_{bin,include,share,app,man}
}