File: install.sh

package info (click to toggle)
senlin 6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 6,872 kB
  • sloc: python: 66,932; sh: 588; makefile: 196
file content (121 lines) | stat: -rwxr-xr-x 3,177 bytes parent folder | download | duplicates (3)
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
#!/bin/bash

if [[ $EUID -ne 0 ]]; then
    echo "This script must be run as root" >&2
    exit 1
fi

# Install prefix for config files (e.g. "/usr/local").
# Leave empty to install into /etc
CONF_PREFIX=""
LOG_DIR=/var/log/senlin


install -d $LOG_DIR

detect_rabbit() {
   PKG_CMD="rpm -q"
   RABBIT_PKG="rabbitmq-server"
   QPID_PKG="qpid-cpp-server"

    # Detect OS type
    # Ubuntu has an lsb_release command which allows us to detect if it is Ubuntu
    if lsb_release -i 2>/dev/null | grep -iq ubuntu
    then
        PKG_CMD="dpkg -s"
        QPID_PKG="qpidd"
    fi
    if $PKG_CMD $RABBIT_PKG > /dev/null 2>&1
    then
        if ! $PKG_CMD $QPID_PKG > /dev/null 2>&1
        then
            return 0
        fi
    fi
    return 1
}

# Determinate is the given option present in the INI file
# ini_has_option config-file section option
function ini_has_option() {
    local file=$1
    local section=$2
    local option=$3
    local line
    line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file")
    [ -n "$line" ]
}

# Set an option in an INI file
# iniset config-file section option value
function iniset() {
    local file=$1
    local section=$2
    local option=$3
    local value=$4
    if ! grep -q "^\[$section\]" "$file"; then
        # Add section at the end
        echo -e "\n[$section]" >>"$file"
    fi
    if ! ini_has_option "$file" "$section" "$option"; then
        # Add it
        sed -i -e "/^\[$section\]/ a\\
$option = $value
" "$file"
    else
        # Replace it
        sed -i -e "/^\[$section\]/,/^\[.*\]/ s|^\($option[ \t]*=[ \t]*\).*$|\1$value|" "$file"
    fi
}

basic_configuration() {
    conf_path=$1
    if echo $conf_path | grep ".conf$" >/dev/null 2>&1
    then
        iniset $target DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/random`
        iniset $target database connection "mysql+pymysql://senlin:senlin@localhost/senlin?charset=utf8"

        BRIDGE_IP=127.0.0.1

        if detect_rabbit
        then
            echo "rabbitmq detected, configuring $conf_path for rabbit" >&2
            iniset $conf_path DEFAULT rpc_backend kombu
            iniset $conf_path oslo_messaging_rabbit rabbit_password guest
        else
            echo "qpid detected, configuring $conf_path for qpid" >&2
            iniset $conf_path DEFAULT rpc_backend qpid
        fi
    fi
}

install_dir() {
    local dir=$1
    local prefix=$2

    for fn in $(ls $dir); do
        f=$dir/$fn
        target=$prefix/$f
        if [ $fn = 'senlin.conf.sample' ]; then
            target=$prefix/$dir/senlin.conf
        fi
        if [ -d $f ]; then
            [ -d $target ] || install -d $target
            install_dir $f $prefix
        elif [ -f $target ]; then
            echo "NOT replacing existing config file $target" >&2
            diff -u $target $f
        else
            echo "Installing $fn in $prefix/$dir" >&2
            install -m 664 $f $target
            if [ $fn = 'senlin.conf.sample' ]; then
                basic_configuration $target
            fi
        fi
    done
}

install_dir etc $CONF_PREFIX

python setup.py install >/dev/null
rm -rf build senlin.egg-info