| @@ -1,16 +1,16 @@ | | | @@ -1,16 +1,16 @@ |
1 | #!@SH@ | | 1 | #!@SH@ |
2 | # | | 2 | # |
3 | # $NetBSD: pkg_alternatives.sh,v 1.6 2007/01/15 02:50:06 rillig Exp $ | | 3 | # $NetBSD: pkg_alternatives.sh,v 1.7 2012/06/13 15:35:32 jperkin Exp $ |
4 | # | | 4 | # |
5 | # pkg_alternatives - Generic wrappers for programs with similar interfaces | | 5 | # pkg_alternatives - Generic wrappers for programs with similar interfaces |
6 | # Copyright (c) 2005 Julio M. Merino Vidal <jmmv@NetBSD.org> | | 6 | # Copyright (c) 2005 Julio M. Merino Vidal <jmmv@NetBSD.org> |
7 | # | | 7 | # |
8 | # Redistribution and use in source and binary forms, with or without | | 8 | # Redistribution and use in source and binary forms, with or without |
9 | # modification, are permitted provided that the following conditions | | 9 | # modification, are permitted provided that the following conditions |
10 | # are met: | | 10 | # are met: |
11 | # 1. Redistributions of source code must retain the above copyright | | 11 | # 1. Redistributions of source code must retain the above copyright |
12 | # notice, this list of conditions and the following disclaimer. | | 12 | # notice, this list of conditions and the following disclaimer. |
13 | # 2. Redistributions in binary form must reproduce the above copyright | | 13 | # 2. Redistributions in binary form must reproduce the above copyright |
14 | # notice, this list of conditions and the following disclaimer in | | 14 | # notice, this list of conditions and the following disclaimer in |
15 | # the documentation and/or other materials provided with the | | 15 | # the documentation and/or other materials provided with the |
16 | # distribution. | | 16 | # distribution. |
| @@ -46,29 +46,29 @@ Verbose=yes | | | @@ -46,29 +46,29 @@ Verbose=yes |
46 | # ------------------------------------------------------------------------- | | 46 | # ------------------------------------------------------------------------- |
47 | | | 47 | |
48 | # action_auto_package package | | 48 | # action_auto_package package |
49 | # | | 49 | # |
50 | # Configures the given package to be in automatic mode. I.e., it removes | | 50 | # Configures the given package to be in automatic mode. I.e., it removes |
51 | # local customizations for all related wrappers, so that only the files in | | 51 | # local customizations for all related wrappers, so that only the files in |
52 | # the database are taken into account. | | 52 | # the database are taken into account. |
53 | # | | 53 | # |
54 | action_auto_package() { | | 54 | action_auto_package() { |
55 | validate_args auto ${#} -eq 1 | | 55 | validate_args auto ${#} -eq 1 |
56 | validate_package ${1} | | 56 | validate_package ${1} |
57 | pkg=${PKG_DBDIR}/${1}*/+ALTERNATIVES | | 57 | pkg=${PKG_DBDIR}/${1}*/+ALTERNATIVES |
58 | | | 58 | |
59 | set -- $(cat ${pkg} | tr ' ' '¬') | | 59 | set -- $(cat ${pkg} | sed -e 's# #__dE/lImIt/Er__#g') |
60 | while [ ${#} -gt 0 ]; do | | 60 | while [ ${#} -gt 0 ]; do |
61 | action_auto_wrapper $(echo ${1} | cut -d '¬' -f 1) | | 61 | action_auto_wrapper ${1%%__dE/lImIt/Er__*} |
62 | shift | | 62 | shift |
63 | done | | 63 | done |
64 | } | | 64 | } |
65 | | | 65 | |
66 | # ------------------------------------------------------------------------- | | 66 | # ------------------------------------------------------------------------- |
67 | | | 67 | |
68 | # action_auto_wrapper wrapper | | 68 | # action_auto_wrapper wrapper |
69 | # | | 69 | # |
70 | # Configures the given wrapper to be in automatic mode. I.e., it removes | | 70 | # Configures the given wrapper to be in automatic mode. I.e., it removes |
71 | # local customizations so that only the files in the database are taken | | 71 | # local customizations so that only the files in the database are taken |
72 | # into account. | | 72 | # into account. |
73 | # | | 73 | # |
74 | # wrapper is a path relative to prefix. | | 74 | # wrapper is a path relative to prefix. |
| @@ -151,29 +151,29 @@ action_list_wrapper() { | | | @@ -151,29 +151,29 @@ action_list_wrapper() { |
151 | | | 151 | |
152 | # ------------------------------------------------------------------------- | | 152 | # ------------------------------------------------------------------------- |
153 | | | 153 | |
154 | # action_manual_package package | | 154 | # action_manual_package package |
155 | # | | 155 | # |
156 | # Configures the given package to be the preferred alternative for all the | | 156 | # Configures the given package to be the preferred alternative for all the |
157 | # wrappers associated to it. | | 157 | # wrappers associated to it. |
158 | # | | 158 | # |
159 | action_manual_package() { | | 159 | action_manual_package() { |
160 | validate_args manual ${#} -eq 1 | | 160 | validate_args manual ${#} -eq 1 |
161 | validate_package ${1} | | 161 | validate_package ${1} |
162 | pkg=${PKG_DBDIR}/${1}*/+ALTERNATIVES | | 162 | pkg=${PKG_DBDIR}/${1}*/+ALTERNATIVES |
163 | | | 163 | |
164 | set -- $(cat ${pkg} | tr ' ' '¬') | | 164 | set -- $(cat ${pkg} | sed -e 's# #__dE/lImIt/Er__#g') |
165 | while [ ${#} -gt 0 ]; do | | 165 | while [ ${#} -gt 0 ]; do |
166 | action_manual_wrapper $(echo ${1} | tr '¬' ' ') | | 166 | action_manual_wrapper $(echo ${1} | sed -e 's#__dE/lImIt/Er__# #g') |
167 | shift | | 167 | shift |
168 | done | | 168 | done |
169 | } | | 169 | } |
170 | | | 170 | |
171 | # ------------------------------------------------------------------------- | | 171 | # ------------------------------------------------------------------------- |
172 | | | 172 | |
173 | # action_manual_wrapper wrapper alternative arguments | | 173 | # action_manual_wrapper wrapper alternative arguments |
174 | # | | 174 | # |
175 | # Configures the given wrapper to use the specified alternative. | | 175 | # Configures the given wrapper to use the specified alternative. |
176 | # If running as the administrator, the system-wide settings are changed; | | 176 | # If running as the administrator, the system-wide settings are changed; |
177 | # otherwise, the user-specific settings are affected. | | 177 | # otherwise, the user-specific settings are affected. |
178 | # | | 178 | # |
179 | # wrapper is a path relative to prefix. | | 179 | # wrapper is a path relative to prefix. |
| @@ -221,29 +221,29 @@ action_rebuild_wrapper() { | | | @@ -221,29 +221,29 @@ action_rebuild_wrapper() { |
221 | } | | 221 | } |
222 | | | 222 | |
223 | # ------------------------------------------------------------------------- | | 223 | # ------------------------------------------------------------------------- |
224 | | | 224 | |
225 | # action_register_package file | | 225 | # action_register_package file |
226 | # | | 226 | # |
227 | # Registers all wrapper/alternative pairs listed in the file. This is | | 227 | # Registers all wrapper/alternative pairs listed in the file. This is |
228 | # supposed to be an +ALTERNATIVES file found inside a package in PKG_DBDIR. | | 228 | # supposed to be an +ALTERNATIVES file found inside a package in PKG_DBDIR. |
229 | # Each line should follow the semantics expected by action_register_wrapper. | | 229 | # Each line should follow the semantics expected by action_register_wrapper. |
230 | # | | 230 | # |
231 | action_register_package() { | | 231 | action_register_package() { |
232 | validate_args register ${#} -eq 1 | | 232 | validate_args register ${#} -eq 1 |
233 | | | 233 | |
234 | set -- $(cat ${1} | tr ' ' '¬') | | 234 | set -- $(cat ${1} | sed -e 's# #__dE/lImIt/Er__#g') |
235 | while [ ${#} -gt 0 ]; do | | 235 | while [ ${#} -gt 0 ]; do |
236 | action_register_wrapper $(echo ${1} | tr '¬' ' ') | | 236 | action_register_wrapper $(echo ${1} | sed -e 's#__dE/lImIt/Er__# #g') |
237 | shift | | 237 | shift |
238 | done | | 238 | done |
239 | } | | 239 | } |
240 | | | 240 | |
241 | # ------------------------------------------------------------------------- | | 241 | # ------------------------------------------------------------------------- |
242 | | | 242 | |
243 | # action_register_wrapper wrapper alternative arguments | | 243 | # action_register_wrapper wrapper alternative arguments |
244 | # | | 244 | # |
245 | # Registers a new alternative for the given wrapper in the database. | | 245 | # Registers a new alternative for the given wrapper in the database. |
246 | # The wrapper and its manual page are created if they do not exist. | | 246 | # The wrapper and its manual page are created if they do not exist. |
247 | # | | 247 | # |
248 | action_register_wrapper() { | | 248 | action_register_wrapper() { |
249 | validate_args register ${#} -ge 2 | | 249 | validate_args register ${#} -ge 2 |
| @@ -266,27 +266,28 @@ action_register_wrapper() { | | | @@ -266,27 +266,28 @@ action_register_wrapper() { |
266 | mkdir_p ${dbconf%/*} | | 266 | mkdir_p ${dbconf%/*} |
267 | touch ${dbconf%/*} | | 267 | touch ${dbconf%/*} |
268 | fi | | 268 | fi |
269 | info "registering alternative \`${alt}' for wrapper \`${wbase}'" | | 269 | info "registering alternative \`${alt}' for wrapper \`${wbase}'" |
270 | if [ -n "${args}" ]; then | | 270 | if [ -n "${args}" ]; then |
271 | echo "${alt} ${args}" >>${dbconf} | | 271 | echo "${alt} ${args}" >>${dbconf} |
272 | else | | 272 | else |
273 | echo "${alt}" >>${dbconf} | | 273 | echo "${alt}" >>${dbconf} |
274 | fi | | 274 | fi |
275 | | | 275 | |
276 | if [ ! -f ${wabs} ]; then | | 276 | if [ ! -f ${wabs} ]; then |
277 | info "creating wrapper \`${wbase}'" | | 277 | info "creating wrapper \`${wbase}'" |
278 | mkdir_p ${wabs%/*} | | 278 | mkdir_p ${wabs%/*} |
279 | sed -e "s|__SH__|@SH@|g" \ | | 279 | sed -e "s|__ID__|@ID@|g" \ |
| | | 280 | -e "s|__SH__|@SH@|g" \ |
280 | -e "s|__CONF_FILE__|${sysconf}|g" \ | | 281 | -e "s|__CONF_FILE__|${sysconf}|g" \ |
281 | -e "s|__CREATOR__|${Prog_Name}|g" \ | | 282 | -e "s|__CREATOR__|${Prog_Name}|g" \ |
282 | -e "s|__DB_FILE__|${dbconf}|g" \ | | 283 | -e "s|__DB_FILE__|${dbconf}|g" \ |
283 | -e "s|__ROOT_USER__|@ROOT_USER@|g" \ | | 284 | -e "s|__ROOT_USER__|@ROOT_USER@|g" \ |
284 | -e "s|__WRAPPER__|${wabs}|g" \ | | 285 | -e "s|__WRAPPER__|${wabs}|g" \ |
285 | <${Data_Dir}/wrapper.sh >${wabs} | | 286 | <${Data_Dir}/wrapper.sh >${wabs} |
286 | chmod +x ${wabs} | | 287 | chmod +x ${wabs} |
287 | mkdir_p ${manpage%/*} | | 288 | mkdir_p ${manpage%/*} |
288 | sed -e "s|__CONF_FILE__|${sysconf}|g" \ | | 289 | sed -e "s|__CONF_FILE__|${sysconf}|g" \ |
289 | -e "s|__CREATOR__|${Prog_Name}|g" \ | | 290 | -e "s|__CREATOR__|${Prog_Name}|g" \ |
290 | -e "s|__DB_FILE__|${dbconf}|g" \ | | 291 | -e "s|__DB_FILE__|${dbconf}|g" \ |
291 | -e "s|__PREFIX__|${Prefix}|g" \ | | 292 | -e "s|__PREFIX__|${Prefix}|g" \ |
292 | -e "s|__SECTION__|$(get_manpage_sect ${wbase})|g" \ | | 293 | -e "s|__SECTION__|$(get_manpage_sect ${wbase})|g" \ |
| @@ -298,83 +299,83 @@ action_register_wrapper() { | | | @@ -298,83 +299,83 @@ action_register_wrapper() { |
298 | } | | 299 | } |
299 | | | 300 | |
300 | # ------------------------------------------------------------------------- | | 301 | # ------------------------------------------------------------------------- |
301 | | | 302 | |
302 | # action_status_package package | | 303 | # action_status_package package |
303 | # | | 304 | # |
304 | # Shows the status of each wrapper associated to the given package. | | 305 | # Shows the status of each wrapper associated to the given package. |
305 | # | | 306 | # |
306 | action_status_package() { | | 307 | action_status_package() { |
307 | validate_args status ${#} -eq 1 | | 308 | validate_args status ${#} -eq 1 |
308 | validate_package ${1} | | 309 | validate_package ${1} |
309 | pkg=${PKG_DBDIR}/${1}*/+ALTERNATIVES | | 310 | pkg=${PKG_DBDIR}/${1}*/+ALTERNATIVES |
310 | | | 311 | |
311 | set -- $(cat ${pkg} | tr ' ' '¬') | | 312 | set -- $(cat ${pkg} | sed -e 's# #__dE/lImIt/Er__#g') |
312 | while [ ${#} -gt 0 ]; do | | 313 | while [ ${#} -gt 0 ]; do |
313 | action_status_wrapper $(echo ${1} | cut -d '¬' -f 1) | | 314 | action_status_wrapper ${1%%__dE/lImIt/Er__*} |
314 | shift | | 315 | shift |
315 | done | | 316 | done |
316 | } | | 317 | } |
317 | | | 318 | |
318 | # ------------------------------------------------------------------------- | | 319 | # ------------------------------------------------------------------------- |
319 | | | 320 | |
320 | # action_status_wrapper wrapper | | 321 | # action_status_wrapper wrapper |
321 | # | | 322 | # |
322 | # Shows the current status for the given wrapper. | | 323 | # Shows the current status for the given wrapper. |
323 | # | | 324 | # |
324 | action_status_wrapper() { | | 325 | action_status_wrapper() { |
325 | validate_args status ${#} -eq 1 | | 326 | validate_args status ${#} -eq 1 |
326 | validate_wrapper ${1} yes | | 327 | validate_wrapper ${1} yes |
327 | | | 328 | |
328 | wbase=${1} | | 329 | wbase=${1} |
329 | dbconf=${Db_Dir}/${wbase} | | 330 | dbconf=${Db_Dir}/${wbase} |
330 | sysconf=${Conf_Dir}/${wbase} | | 331 | sysconf=${Conf_Dir}/${wbase} |
331 | userconf=~/.pkg_alternatives${Prefix}/${wbase} | | 332 | userconf=~/.pkg_alternatives${Prefix}/${wbase} |
332 | | | 333 | |
333 | [ $(id -un) = @ROOT_USER@ ] && userconf= | | 334 | [ $(@ID@ -un) = @ROOT_USER@ ] && userconf= |
334 | alts=$(cat ${userconf} ${sysconf} ${dbconf} 2>/dev/null | grep -v '^#' | \ | | 335 | alts=$(cat ${userconf} ${sysconf} ${dbconf} 2>/dev/null | grep -v '^#' | \ |
335 | tr ' ' '¬') | | 336 | sed -e 's# #__dE/lImIt/Er__#g') |
336 | | | 337 | |
337 | found= | | 338 | found= |
338 | for a in ${alts}; do | | 339 | for a in ${alts}; do |
339 | prog=$(echo ${a} | cut -d '¬' -f 1) | | 340 | prog=${a%%__dE/lImIt/Er__*} |
340 | if [ -x ${prog} ]; then | | 341 | if [ -x ${prog} ]; then |
341 | found=$(echo ${a} | tr '¬' ' ') | | 342 | found=$(echo ${a} | sed -e 's#__dE/lImIt/Er__# #g') |
342 | break | | 343 | break |
343 | fi | | 344 | fi |
344 | done | | 345 | done |
345 | | | 346 | |
346 | [ -n "${found}" ] || | | 347 | [ -n "${found}" ] || |
347 | err "the wrapper \`${wbase}' exists but has no valid alternatives" | | 348 | err "the wrapper \`${wbase}' exists but has no valid alternatives" |
348 | | | 349 | |
349 | echo "\`${wbase}' points to \`${found}'" | | 350 | echo "\`${wbase}' points to \`${found}'" |
350 | for a in $(echo ${alts} | tr ' ' '\n' | sort | uniq); do | | 351 | for a in $(echo ${alts} | tr ' ' '\n' | sort | uniq); do |
351 | echo " candidate: $(echo ${a} | tr '¬' ' ')" | | 352 | echo " candidate: $(echo ${a} | sed -e 's#__dE/lImIt/Er__# #g')" |
352 | done | | 353 | done |
353 | } | | 354 | } |
354 | | | 355 | |
355 | # ------------------------------------------------------------------------- | | 356 | # ------------------------------------------------------------------------- |
356 | | | 357 | |
357 | # action_unregister_package file | | 358 | # action_unregister_package file |
358 | # | | 359 | # |
359 | # Unregisters the given package (given by its +ALTERNATIVES file) and | | 360 | # Unregisters the given package (given by its +ALTERNATIVES file) and |
360 | # removes all associated alternatives from their respective wrappers. | | 361 | # removes all associated alternatives from their respective wrappers. |
361 | # | | 362 | # |
362 | action_unregister_package() { | | 363 | action_unregister_package() { |
363 | validate_args unregister ${#} -eq 1 | | 364 | validate_args unregister ${#} -eq 1 |
364 | | | 365 | |
365 | set -- $(cat ${1} | tr ' ' '¬') | | 366 | set -- $(cat ${1} | sed -e 's# #__dE/lImIt/Er__#g') |
366 | while [ ${#} -gt 0 ]; do | | 367 | while [ ${#} -gt 0 ]; do |
367 | action_unregister_wrapper $(echo ${1} | tr '¬' ' ') | | 368 | action_unregister_wrapper $(echo ${1} | sed -e 's#__dE/lImIt/Er__# #g') |
368 | shift | | 369 | shift |
369 | done | | 370 | done |
370 | } | | 371 | } |
371 | | | 372 | |
372 | # ------------------------------------------------------------------------- | | 373 | # ------------------------------------------------------------------------- |
373 | | | 374 | |
374 | # action_unregister_wrapper wrapper alternative arguments | | 375 | # action_unregister_wrapper wrapper alternative arguments |
375 | # | | 376 | # |
376 | # Unregisters an alternative for the given wrapper. The lookup is done | | 377 | # Unregisters an alternative for the given wrapper. The lookup is done |
377 | # based on the alternative name and its arguments. I.e., there must be | | 378 | # based on the alternative name and its arguments. I.e., there must be |
378 | # an exact match. If no alternatives remain after the removal, the wrapper | | 379 | # an exact match. If no alternatives remain after the removal, the wrapper |
379 | # and its manpage are removed. | | 380 | # and its manpage are removed. |
380 | # | | 381 | # |
| @@ -421,68 +422,68 @@ err() { | | | @@ -421,68 +422,68 @@ err() { |
421 | } | | 422 | } |
422 | | | 423 | |
423 | # ------------------------------------------------------------------------- | | 424 | # ------------------------------------------------------------------------- |
424 | | | 425 | |
425 | # filter wrapper | | 426 | # filter wrapper |
426 | # | | 427 | # |
427 | # Reads the configuration filter from CONFDIR/filter.conf and, for the | | 428 | # Reads the configuration filter from CONFDIR/filter.conf and, for the |
428 | # given wrapper, returns whether it is accepted or ignored. | | 429 | # given wrapper, returns whether it is accepted or ignored. |
429 | # | | 430 | # |
430 | filter() { | | 431 | filter() { |
431 | [ ! -f @CONFDIR@/filter.conf ] && return 0 | | 432 | [ ! -f @CONFDIR@/filter.conf ] && return 0 |
432 | | | 433 | |
433 | if [ ${Filter_Read} = no ]; then | | 434 | if [ ${Filter_Read} = no ]; then |
434 | Filter=$(cat @CONFDIR@/filter.conf | grep -v '^#' | tr ' ' '¬') | | 435 | Filter=$(cat @CONFDIR@/filter.conf | grep -v '^#' | sed -e 's# #__dE/lImIt/Er__#g') |
435 | Filter_Read=yes | | 436 | Filter_Read=yes |
436 | fi | | 437 | fi |
437 | | | 438 | |
438 | [ -z "${Filter}" ] && return 0 | | 439 | [ -z "${Filter}" ] && return 0 |
439 | | | 440 | |
440 | for f in ${Filter}; do | | 441 | for f in ${Filter}; do |
441 | what=$(echo ${f} | cut -d '¬' -f 1) | | 442 | what=${f%%__dE/lImIt/Er__*} |
442 | case ${what} in | | 443 | case ${what} in |
443 | accept) | | 444 | accept) |
444 | name=$(echo ${f} | cut -d '¬' -f 2- | tr '¬' ' ') | | 445 | name=$(echo ${f#*__dE/lImIt/Er__} | sed -e 's#__dE/lImIt/Er__# #g') |
445 | if echo ${1} | grep "${name}" >/dev/null; then | | 446 | if echo ${1} | grep "${name}" >/dev/null; then |
446 | info "filter accepts \`${1}'" | | 447 | info "filter accepts \`${1}'" |
447 | return 0 | | 448 | return 0 |
448 | fi | | 449 | fi |
449 | ;; | | 450 | ;; |
450 | ignore) | | 451 | ignore) |
451 | name=$(echo ${f} | cut -d '¬' -f 2- | tr '¬' ' ') | | 452 | name=$(echo ${f#*__dE/lImIt/Er__} | sed -e 's#__dE/lImIt/Er__# #g') |
452 | if echo ${1} | grep "${name}" >/dev/null; then | | 453 | if echo ${1} | grep "${name}" >/dev/null; then |
453 | info "filter ignores \`${1}'" | | 454 | info "filter ignores \`${1}'" |
454 | return 1 | | 455 | return 1 |
455 | fi | | 456 | fi |
456 | ;; | | 457 | ;; |
457 | *) | | 458 | *) |
458 | warn "unknown filter type \`${what}'; ignoring" | | 459 | warn "unknown filter type \`${what}'; ignoring" |
459 | ;; | | 460 | ;; |
460 | esac | | 461 | esac |
461 | done | | 462 | done |
462 | | | 463 | |
463 | true | | 464 | true |
464 | } | | 465 | } |
465 | | | 466 | |
466 | # ------------------------------------------------------------------------- | | 467 | # ------------------------------------------------------------------------- |
467 | | | 468 | |
468 | # get_my_config | | 469 | # get_my_config |
469 | # | | 470 | # |
470 | # Prints the configuration directory for the current user. If root, this | | 471 | # Prints the configuration directory for the current user. If root, this |
471 | # is the system-wide configuration directory. Otherwise, it is the user's | | 472 | # is the system-wide configuration directory. Otherwise, it is the user's |
472 | # personal directory. | | 473 | # personal directory. |
473 | # | | 474 | # |
474 | get_my_config() { | | 475 | get_my_config() { |
475 | if [ $(id -un) = @ROOT_USER@ ]; then | | 476 | if [ $(@ID@ -un) = @ROOT_USER@ ]; then |
476 | echo ${Conf_Dir} | | 477 | echo ${Conf_Dir} |
477 | else | | 478 | else |
478 | echo ~/.pkg_alternatives${Prefix} | | 479 | echo ~/.pkg_alternatives${Prefix} |
479 | fi | | 480 | fi |
480 | } | | 481 | } |
481 | | | 482 | |
482 | # ------------------------------------------------------------------------- | | 483 | # ------------------------------------------------------------------------- |
483 | | | 484 | |
484 | # get_manpage wrapper | | 485 | # get_manpage wrapper |
485 | # | | 486 | # |
486 | # Prints the absolute path to the manual page associated to wrapper. | | 487 | # Prints the absolute path to the manual page associated to wrapper. |
487 | # Does no error checking; validate_wrapper has to be called before this | | 488 | # Does no error checking; validate_wrapper has to be called before this |
488 | # function to ensure wrapper is a valid name. | | 489 | # function to ensure wrapper is a valid name. |