summaryrefslogtreecommitdiff
blob: d749184ccaf7ee10e92d8bbeeade42ced686c030 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/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.

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

	if [ -z "${1}" ]; then
		return 0
	fi

	# set new profile as default
	new=${1}
	files=""
	# libs
	for file in `ls /usr/@@LIBDIR@@/${new}/ | grep lib`; do
		files="${files} /usr/@@LIBDIR@@/${file}"
		rm -f /usr/@@LIBDIR@@/${file}
		ln -s /usr/@@LIBDIR@@/${new}/${file} /usr/@@LIBDIR@@/${file}
	done
	# includes
	for file in `ls /usr/include/${new}/`; do
		files="${files} /usr/include/${file}"
		rm -f /usr/include/${file}
		ln -s /usr/include/${new}/${file} /usr/include/${file}
	done
	# binaries
	for file in `ls /usr/@@LIBDIR@@/${new} | grep -v lib`; do
		files="${files} /usr/bin/${file}"
		rm -f /usr/bin/${file}
		ln -s /usr/@@LIBDIR@@/${new}/${file} /usr/bin/${file}
	done
	# man pages
	for file in `find /usr/share/man -regex ".*-${new}\..x?.gz"`; do
		files="${files} ${file/-${new}/}"
		rm -f ${file/-${new}/}
		ln -s ${file} ${file/-${new}/}
	done

	cat ${PROFILE_PATH}/${new} > ${CONFIG_FILE}
	echo "FILES='${files}'" >> ${CONFIG_FILE}

	return $?
}

_deactivate_profile() {
	_check_root

	source ${CONFIG_FILE} 2>/dev/null
	current=${PROFILE}

	if [ -z "$current" ]; then
		return 0
	fi

	for file in ${FILES}; do
		rm -f ${file}
	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
		source ${CONFIG_FILE} 2> /dev/null
		_deactivate_profile
		if [ -z "${PROFILE}" -o ! -f ${PROFILE_PATH}/${PROFILE} ]; then
			for y in `ls ${PROFILE_PATH} | grep -v removed | grep -v current | sort -r`; do
				_activate_profile ${y}
				break
			done
			if [ -z "${y}" ]; then
				eerror "$0: no profile to activate"
			fi
		else
			_activate_profile ${PROFILE}
		fi
	fi

	source ${CONFIG_FILE} 2>/dev/null
	einfo "$0: New default Profile is: ${PROFILE}"

	return $?
}

get_current_profile() {
	source ${CONFIG_FILE} 2> /dev/null
	echo ${PROFILE}
}

list_profiles() {
	i=1
	source ${CONFIG_FILE} 2> /dev/null
	current=${PROFILE}
	for y in `ls ${PROFILE_PATH} | grep -v current | grep -v removed`; do
		source ${PROFILE_PATH}/${y}
		output="[${i}] ${PROFILE}";
		if [ "${y}" = "${current}" ]; then
			output="${output} *"
		fi
		echo "$output"
		i=$((i + 1))
	done
	exit $?
}

get_lib_path() {
	if [ "$1" != "" ]; then
		file=${1}
	else
		file="current"
	fi
	source ${PROFILE_PATH}/${file}
	if [ $? -eq 1 ]; then
		eerror "$0: No such profile: $profile"
	else
		echo "/usr/@@LIBDIR@@/${PROFILE}/"
		exit 0
	fi
}

get_inc_path() {
	if [ "$1" != "" ]; then
		file=${1}
	else
		file="current"
	fi
	source ${PROFILE_PATH}/${file}
	if [ $? -eq 1 ]; then
		eerror "$0: No such profile: $profile"
	else
		echo "/usr/include/${PROFILE}/"
		exit 0
	fi
}

get_cflags() {
	if [ "$1" != "" ]; then
		file=${1}
	else
		file="current"
	fi
	source ${PROFILE_PATH}/${file}
	if [ $? -eq 1 ]; then
		eerror "$0: No such profile: $profile"
	else
		echo "-I/usr/include/${PROFILE}/"
		exit 0
	fi
}

get_libs() {
	if [ "$1" != "" ]; then
		file=${1}
	else
		file="current"
	fi
	source ${PROFILE_PATH}/${file}
	if [ $? -eq 1 ]; then
		eerror "$0: No such profile: $profile"
	else
		echo "-L/usr/@@LIBDIR@@/${PROFILE}/"
		exit 0
	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)
			[[ $# -gt 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
		;;

		-h|--help)
			usage 0
		;;

		-v|--version)
			echo "motif-config-0.9"
			exit 0
		;;

		-*)
			usage 1
		;;

		*)
			usage 1
		;;

	esac
done