home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / sbin / update-java-alternatives < prev    next >
Encoding:
Text File  |  2010-08-23  |  2.9 KB  |  154 lines

  1. #! /bin/bash
  2.  
  3. shopt -s dotglob
  4.  
  5. prog=$(basename $0)
  6.  
  7. usage()
  8. {
  9.     rv=$1
  10.     cat >&2 <<-EOF
  11.     usage: $prog [--jre-headless] [--jre] [--plugin] [ -t|--test|-v|--verbose]
  12.                -l|--list [<jname>]
  13.                -s|--set <jname>
  14.                -a|--auto
  15.                -h|-?|--help
  16.     EOF
  17.     exit $rv
  18. }
  19.  
  20. action=
  21. uaopts='--quiet'
  22.  
  23. while [ "$#" -gt 0 ]; do
  24.     case "$1" in
  25.       -a|--auto)
  26.     [ -z "$action" ] || usage 1
  27.     action=auto;;
  28.       -hl|--jre-headless)
  29.     hlonly=yes;;
  30.       -j|--jre)
  31.     jreonly=yes;;
  32.       --plugin)
  33.     pluginonly=yes;;
  34.       -l|--list)
  35.     [ -z "$action" ] || usage 1
  36.     action=list
  37.     if [ "$#" -gt 0 ]; then
  38.         shift
  39.         jname=$1
  40.     fi
  41.     ;;
  42.       -s|--set)
  43.     [ -z "$action" ] || usage 1
  44.     action=set
  45.     shift
  46.     [ "$#" -gt 0 ] || usage 1
  47.     jname=$1
  48.     ;;
  49.       -t|--test)
  50.     dryrun=yes
  51.     uaopts="$uaopts --test";;
  52.       -v|--verbose)
  53.     verbose=yes
  54.     uaopts="${uaopts/--quiet/}";;
  55.       -h|-?|--help)
  56.     usage 0;;
  57.       -*)
  58.     echo "X: $1"
  59.     usage 1;;
  60.       *)
  61.     break;;
  62.     esac
  63.     shift
  64. done
  65.  
  66. [ "$#" -eq 0 ] || usage 1
  67. [ -n "$action" ] || usage 1
  68.  
  69. which='^(hl|jre|jdk|plugin|DUMMY) '
  70. if [ -n "$hlonly$jreonly$pluginonly" ]; then
  71.     which='^('
  72.     [ -n "$hlonly" ] && which="${which}hl|"
  73.     [ -n "$jreonly" ] && [ -n "$hlonly" ] && which="${which}jre|"
  74.     [ -n "$jreonly" ] && [ -z "$hlonly" ] && which="${which}hl|jre|"
  75.     [ -n "$pluginonly" ] && which="${which}plugin|"
  76.     which="${which}DUMMY) "
  77. fi
  78.  
  79. top=/usr/lib/jvm
  80.  
  81. if [ -n "$jname" ]; then
  82.     case "$jname" in
  83.     /*) jdir=$jname; jname=$(basename $jdir);;
  84.     *)  jdir=$top/$jname
  85.     esac
  86.     if [ ! -d $jdir ]; then
  87.     echo >&2 "$prog: directory does not exist: $jdir"
  88.     exit 1
  89.     fi
  90.     if [ -f $top/.$jname.jinfo ]; then
  91.     jinfo=$top/.$jname.jinfo
  92.     elif [ -f $top/$jname.jinfo ]; then
  93.     jinfo=$top/$jname.jinfo
  94.     else
  95.     echo >&2 "$prog: file does not exist: $top/.$jname.jinfo"
  96.     exit 1
  97.     fi
  98. fi
  99.  
  100. vecho()
  101. {
  102.     [ -z "$verbose" ]  || echo >&2 "$@"
  103. }
  104.  
  105. jinfo_files=
  106.  
  107. do_auto()
  108. {
  109.     vecho "resetting java alternatives"
  110.     awk "/$which/ {print \$2}" $top/*.jinfo | sort -u \
  111.     | \
  112.     while read name; do
  113.     update-alternatives $uaopts --auto $name
  114.     done
  115. }
  116.  
  117. do_list()
  118. {
  119.     vecho "listing java alternatives:"
  120.     for i in ${jinfo:-$top/*.jinfo}; do
  121.     alias=$(basename ${i%.jinfo})
  122.     alias=${alias#.}
  123.     prio=$(awk -F= '/priority=/ {print $2}' $i)
  124.     echo $alias $prio $top/$alias
  125.     [ -n "$verbose" ] && egrep "$which" $i
  126.     done
  127. }
  128.  
  129. do_set()
  130. {
  131.     do_auto
  132.  
  133.     awk "/$which/ {print}" $jinfo | sort -u \
  134.     | \
  135.     while read type name location; do
  136.     if [ $type = jdk -a -z "$hlonly$jreonly$pluginonly" -a ! -f $location ]; then
  137.         echo >&2 "$prog: jdk alternative does not exist: $location"
  138.         continue
  139.     fi
  140.     if [ $type = plugin -a -z "$hlonly$jreonly" -a ! -f $location ]; then
  141.         echo >&2 "$prog: plugin alternative does not exist: $location"
  142.         continue
  143.     fi
  144.     update-alternatives $uaopts --set $name $location
  145.     done
  146. }
  147.  
  148. if [ "$action" != list ] && [ "$(id -u)" -ne 0 ]; then
  149.     echo >&2 "$prog: no root privileges"
  150.     exit 1
  151. fi
  152.  
  153. do_$action
  154.