summaryrefslogtreecommitdiff
path: root/src/tools/default-jvm.sh
blob: 56c427c5bf89073eb2666409cfb1ff4d94369e55 (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
#!/bin/sh
JVM_DIR=/usr/lib/jvm
JAVA_BIN=/bin/java

usage () {
    cat << EOF 
xilinux-java 
    Print the name of the currently linked jvm
    non-zero exit code if none is linked
        
xilinux-java [name]
    create symlinks to /usr/lib/jvm/[name]/bin to /bin

xilinux-java [-l]
    list installed JVMs
EOF
}

get () {
    [ -h "$JAVA_BIN" ] && {
        path=$(readlink "$JAVA_BIN")
        path=${path%%/bin/java}
        path=${path##*/}
        echo $path
    } 
}

link ()  {
    [ -d "$1" ] && for bin in $1/bin/*; do 
        ln -sf $bin /bin/${bin##*/}
    done
}


[ "$#" = "0" ] && {
    get || return 1
} || {
    case "$1" in
        "-l"|"--list")
            ls -1 $JVM_DIR
            ;;
        "-h"|"--help")
            usage
            ;;
        *)
            link $1 \
            || link $JVM_DIR/$1 \
            || get
            ;;
    esac
}