aboutsummaryrefslogtreecommitdiff
path: root/scripts/cbc_functions.inc
blob: 6713d819c2a97f02b57addc0d49fcf48c296e83e (plain) (blame)
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
if [[ -n $BASH_VERSION ]] &&     [[ "$(basename "$0" 2> /dev/null)" == "cbc_functions.inc" ]]; then
        echo "$(basename "$0") is designed to be sourced not executed."
        exit 1 
fi
function success {
    echo $?
}; export -f success

function program_exists {
    PROGRAM="$1"
    which $PROGRAM &>/dev/null
    if [ `success` -ne 0 ]; then
        echo 1
    fi
    echo 0
}

function user_choice {
    local yn=
    read yn

    while true
    do
        case "$yn" in
            Y|y)
                echo 0
                break
            ;;
            *)
                echo 1
                break
            ;;
        esac
    done

}

function get_conda_build {
    _OK=`program_exists conda`
    if [ ! $_OK ]; then
        echo ''
    fi
    echo $( echo $( readlink -f $(dirname `which conda`)/../conda-bld ) )
}

function get_conda_repo {
    _OK=`program_exists conda`
    if [ ! $_OK ]; then
        echo "Cannot locate local conda repository."
        exit 1
    fi

    get_os_info
    echo "$(echo $(get_conda_build)/$OS-$ARCH)"
}

function get_os_info {
    OS=
    ARCH=
    _OS=`uname -s`
    _ARCH=`uname -m`

    case "$_OS" in
        Darwin)
            OS=osx
        ;;
        Linux)
            OS=linux
        ;;
        *)
            echo "Unsupported operating system"
            exit 1
        ;;
    esac

    case "$_ARCH" in
        i3*|i6*|x86)
            ARCH=32
        ;;
        x86_64)
            ARCH=64
        ;;
        *)
            echo "Unknown architecture"
            exit 1
        ;;
    esac

    export OS
    export ARCH
}