diff options
Diffstat (limited to 'x11-libs/motif-config/files/motif-config-0.7')
-rwxr-xr-x | x11-libs/motif-config/files/motif-config-0.7 | 369 |
1 files changed, 369 insertions, 0 deletions
diff --git a/x11-libs/motif-config/files/motif-config-0.7 b/x11-libs/motif-config/files/motif-config-0.7 new file mode 100755 index 000000000000..0db2ad946308 --- /dev/null +++ b/x11-libs/motif-config/files/motif-config-0.7 @@ -0,0 +1,369 @@ +#!/bin/bash +# Copyright 1999-2004 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# based on gcc-config by Martin Schlemmer <azarah@gentoo.org +# Author: Heinrich Wendel <lanius@gentoo.org> + +umask 022 + +PROFILE_PATH=/usr/@@LIBDIR@@/motif +CONFIG_FILE=${PROFILE_PATH}/current + +usage() { +cat << "USAGE_END" +Usage: motif-config [option] [profile] +Change the current motif profile, or give info about profiles. + +Options: + + -c, --get-current-profile Print current used motif profile. + + -l, --list-profiles Print a list of available profiles. + + -s, --set-profile Set the current profile. + + -L, --get-lib-path Print path where libraries of the given/current + profile are located. + + -I, --get-inc-path Print path where includes of the given/current + profile are located. + + --libs Print link flags for the given/current + profile. + + --cflags Print compilation flags for the given/current + profile. + + --install Install the given profile. + + --uninstall Uninstall the given profile. + + --start-install Start installation of new Motif version + + --finish-install Finish installation of new Motif version + +USAGE_END + exit $1 +} +[[ $# -lt 1 ]] && usage 1 +[[ $# -gt 2 ]] && usage 1 + +# redefine eerror/einfo to remove baselayout dep +# to make ppc-macos people happy +eerror() { + echo -e " \e[31;01m*\e[0m $*"; + exit 1 +} +einfo() { + echo -e " \e[32;01m*\e[0m $*"; +} + +_check_root() { + if [[ "$(id -u)" -ne 0 ]] ; then + eerror "$0: Must be root." + exit 1 + fi +} + +_activate_profile() { + _check_root + + new=${1} + # libs + for file in `ls /usr/@@LIBDIR@@/${new}/ | grep lib`; do + ln -s /usr/@@LIBDIR@@/${new}/${file} /usr/@@LIBDIR@@/${file} + done + # includes + for file in `ls /usr/include/${new}/`; do + ln -s /usr/include/${new}/${file} /usr/include/${file} + done + # binaries + for file in `ls /usr/@@LIBDIR@@/${new} | grep -v lib`; do + ln -s /usr/@@LIBDIR@@/${new}/${file} /usr/bin/${file} + done + # man pages + for file in `find /usr/share/man -regex ".*-${new}\..x?.gz"`; do + ln -s ${file} ${file/-${new}/} + done + + # set new profile as default + cat ${PROFILE_PATH}/${new} > ${CONFIG_FILE} + + return $? +} + +_deactivate_profile() { + _check_root + + current=`cat ${CONFIG_FILE} 2>/dev/null` + + if [ -z "$current" ]; then + return 0 + fi + + # libs + for file in `ls /usr/@@LIBDIR@@/${current} | grep lib`; do + rm -f /usr/@@LIBDIR@@/${file} + done + # includes + for file in `ls /usr/include/${current}/`; do + rm -f /usr/include/${file} + done + # binaries + for file in `ls /usr/@@LIBDIR@@/${current} | grep -v lib`; do + rm -f /usr/bin/${file} + done + # man pages + for file in `find /usr/share/man -regex ".*-${current}\..x?.gz"`; do + rm -f ${file/-${current}/} + done + + rm -f ${CONFIG_FILE} + + return $? +} + +switch_profile() { + _check_root + + if [ -n "$1" ]; then + if [ ! -e ${PROFILE_PATH}/${1} ]; then + eerror "$0: no such profile ${1}" + else + _deactivate_profile + _activate_profile $1 + fi + else + for y in `ls ${PROFILE_PATH} | grep -v removed | grep -v current | sort -r`; do + _deactivate_profile + _activate_profile ${y} + break + done + if [ -z "${y}" ]; then + _deactivate_profile + eerror "$0: no profile to activate" + fi + fi + + einfo "$0: New default Profile is: `cat ${CONFIG_FILE}`" + + return $? +} + +get_current_profile() { + cat ${CONFIG_FILE} 2> /dev/null +} + +list_profiles() { + i=1 + current=`cat ${CONFIG_FILE} 2>/dev/null` + for x in `ls ${PROFILE_PATH} | grep -v current | grep -v removed`; do + output=`cat ${PROFILE_PATH}/${y}`; + output="[${i}] $output"; + if [ "${y}" = "${current}" ]; then + output="${output} *" + fi + echo "$output" + i=$((i + 1)) + done + exit $? +} + +get_lib_path() { + if [ "$1" != "" ]; then + profile=${1} + else + profile="current" + fi + name=`cat ${PROFILE_PATH}/${profile} 2> /dev/null` + if [ $? -eq 1 ]; then + eerror "$0: No such profile: $profile" + else + echo "/usr/@@LIBDIR@@/${name}/" + exit 0 + fi +} + +get_inc_path() { + if [ "$1" != "" ]; then + profile=${1} + else + profile="current" + fi + name=`cat ${PROFILE_PATH}/${profile} 2> /dev/null` + if [ $? -eq 1 ]; then + eerror "$0: No such profile: $profile" + else + echo "/usr/include/${name}/" + exit 0 + fi +} + +get_cflags() { + if [ "$1" != "" ]; then + profile=${1} + else + profile="current" + fi + name=`cat ${PROFILE_PATH}/${profile} 2> /dev/null` + if [ $? -eq 1 ]; then + eerror "$0: No such profile: $profile" + else + echo "-I/usr/include/${name}/" + exit 0 + fi +} + +get_libs() { + if [ "$1" != "" ]; then + profile=${1} + else + profile="current" + fi + name=`cat ${PROFILE_PATH}/${profile} 2> /dev/null` + if [ $? -eq 1 ]; then + eerror "$0: No such profile: $profile" + else + echo "-L/usr/@@LIBDIR@@/${name}/" + exit 0 + fi +} + +install_profile() { + _check_root + + # give info + einfo "$0: Installing Profile: ${1}" + + # create profile + echo ${1} > ${PROFILE_PATH}/${1} + + # create env.d entry + echo "LDPATH=/usr/lib/${1}" > /etc/env.d/15${1} + + # make it default if no profile is activated + if [ ! -e $CONFIG_FILE ]; then + switch_profile ${1} + fi + + exit $? +} + +uninstall_profile() { + _check_root + + # give info + einfo "$0: Uninstalling Profile: ${1}" + + # remove profile + rm -f ${PROFILE_PATH}/${1} 2> /dev/null + + # remove env.d entry + rm -f /etc/env.d/15${1} + + # activate next profile if non is activated + if [ "`cat $CONFIG_FILE`" == "${1}" ]; then + switch_profile + fi + + exit $? +} + +start_installation() { + einfo "Starting installation of a new motif version." + einfo "Note: You can't use any motif app during this process." + + if [ -f ${CONFIG_FILE} ]; then + cat ${CONFIG_FILE} > ${PROFILE_PATH}/removed + + _deactivate_profile + fi +} + +finish_installation() { + einfo "Finishing installation." + einfo "Note: You can now use your motif apps again." + + if [ -f ${PROFILE_PATH}/removed ]; then + _activate_profile `cat ${PROFILE_PATH}/removed` + rm -f ${PROFILE_PATH}/removed + fi +} + +for x in "$@"; do + case "${x}" in + -c|--get-current-profile) + [[ $# -ne 1 ]] && usage 1 + get_current_profile + ;; + + -l|--list-profiles) + [[ $# -ne 1 ]] && usage 1 + list_profiles + ;; + + -s|--set-profile) + [[ $# -ne 2 ]] && usage 1 + switch_profile $2 + exit $? + ;; + + -L|--get-lib-path) + [[ $# -gt 2 ]] && usage 1 + get_lib_path $2 + ;; + + -I|--get-inc-path) + [[ $# -gt 2 ]] && usage 1 + get_inc_path $2 + ;; + + --cflags) + [[ $# -gt 2 ]] && usage 1 + get_cflags $2 + ;; + + --libs) + [[ $# -gt 2 ]] && usage 1 + get_libs $2 + ;; + + --install) + [[ $# -ne 2 ]] && usage 1 + install_profile $2 + ;; + + --uninstall) + [[ $# -ne 2 ]] && usage 1 + uninstall_profile $2 + ;; + + --start-install) + [[ $# -ne 1 ]] && usage 1 + start_installation + ;; + + --finish-install) + [[ $# -ne 1 ]] && usage 1 + finish_installation + ;; + + -h|--help) + usage 0 + ;; + + -v|--version) + echo "motif-config-0.7" + exit 0 + ;; + + -*) + usage 1 + ;; + + *) + usage 1 + ;; + + esac +done |