summaryrefslogtreecommitdiffstats
path: root/helper_scrips/download_and_install.sh
blob: afbffda6837a3835bd8e0fe8fd1d94424664c570 (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
#!/bin/bash

#set -x;

function _init ()
{
 #   echo $0;
 #   echo $#;
 #   echo $1;
    set -u;
    if [ $# -lt 1 ]; then
            echo "usage: download_and_install <glusterfs-version> [install prefix]";
            exit 1;
    fi

    version=$1;
    echo $version;
    echo $version | grep "glusterfs" 2>/dev/null 1>/dev/null;
    if [ $? -ne 0 ]; then
        echo "given argument is not glusterfs";
        exit 1;
    fi

    check_if_qa_release $version;
    op_ret=$?;

    if [ $op_ret -eq 0 ]; then
        download_address="http://bits.gluster.com/pub/gluster/glusterfs/src/"$version".tar.gz";
    else
        echo $version | grep "3.2" 2>/dev/null 1>/dev/null;
        if [ $? -eq 0 ]; then
            version_number=$(echo $version | cut -f 2 -d "-");
            download_address="http://ftp.gluster.com/pub/gluster/glusterfs/3.2/$version_number/"$version".tar.gz";
        else
            grep "3.1" $version 2>/dev/null 1>/dev/null;
            echo "haha yes"
            if [ $? -eq 0 ]; then
                version_number=$(echo $version | cut -f 2 -d "-");
                download_address="http://ftp.gluster.com/pub/gluster/glusterfs/3.1/$version_number/"$version".tar.gz";
            else
                grep "3.0" $version 2>/dev/null 1>/dev/null;
                if [ $? -eq 0 ]; then
                    version_number=$(cut -f 2 -d "-" $version);
                    download_address="http://ftp.gluster.com/pub/gluster/glusterfs/3.2/$version_number/"$version".tar.gz";
                fi
            fi
        fi
    fi

echo "KK: $download_address"
#       ls -l "$version".tar.gz 2>/dev/null 1>/dev/null
#       if [ $? -ne 0 ]; then
}

function check_if_qa_release ()
{
    glusterfs_version=$1;

    echo $glusterfs_version | grep "qa" 2>/dev/null 1>/dev/null;
    if [ $? -ne 0 ]; then
	echo $glusterfs_version | grep "beta" 2>/dev/null 1>/dev/null;
    fi
    ret=$?;

    return $ret;
}

function download_tarball ()
{
    address=$1;

    wget $address;
}

function untar_tarball ()
{
    gluster_version=$1;

    tar xzf $PWD/"$gluster_version".tar.gz;
}

function configure ()
{
    if [ $# -eq 1 ]; then
            prefix_dir=$1;
    else
        prefix_dir="default";
    fi

    old_pwd=$PWD;

    cd $PWD/$version;
    check_if_qa_release $version;

    if [ $? -eq 0 ]; then
        export CFLAGS="-g -O0 -DDEBUG";
    else
        export CFLAGS="-g -O0";
    fi

    if [ ! -d build ]; then
        mkdir build;
    fi

    cd build;

    echo "KKKKK: $prefix_dir"
    sleep 1;
    if [ $prefix_dir != "default" ]; then
        ../configure --prefix=$prefix_dir --quiet;
    else
        ../configure --quiet;
    fi

    cd $old_pwd;
}

function build_install ()
{
    cd $PWD/$version;

    cd build;
    make -j 32 >/dev/null && make -j 32 install >/dev/null;

    cd /root;
}

main ()
{
    if [ ! -e $version.tar.gz ]; then
        echo $download_address;
        download_tarball $download_address;
    else
        echo "tarball already present in the directory";
    fi

    if [ ! -d $version ]; then
        untar_tarball $version;
    else
        echo "Source directory already present in the directory";
    fi

    install_prefix="default";
    if [ $# -eq 2 ]; then
            install_prefix=$2;
    fi

    if [ $install_prefix != "default" ]; then
        configure $install_prefix;
    else
        configure;
    fi

    build_install;
}

_init "$@" && main "$@"