File: setup-centos.sh

package info (click to toggle)
python-muranoclient 2.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,324 kB
  • sloc: python: 10,663; sh: 231; makefile: 27
file content (178 lines) | stat: -rw-r--r-- 5,374 bytes parent folder | download | duplicates (2)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/sh
#    Copyright (c) 2013 Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
#    CentOS script.

LOGLVL=1
SERVICE_CONTENT_DIRECTORY=`cd $(dirname "$0") && pwd`
PREREQ_PKGS="wget make git python-pip python-devel"
PIPAPPS="pip python-pip pip-python"
PIPCMD=""
SERVICE_SRV_NAME="python-muranoclient"
GIT_CLONE_DIR=`echo $SERVICE_CONTENT_DIRECTORY | sed -e "s/$SERVICE_SRV_NAME//"`
# Functions
# Loger function
log()
{
        MSG=$1
        if [ $LOGLVL -gt 0 ]; then
                echo "LOG:> $MSG"
        fi
}

# Check or install package
in_sys_pkg()
{
        PKG=$1
        rpm -q $PKG > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            log "Package \"$PKG\" already installed"
        else
                log "Installing \"$PKG\"..."
                yum install $PKG --assumeyes > /dev/null 2>&1
                if [ $? -ne 0 ];then
                        log "installation fails, exiting!!!"
                        exit
                fi
        fi
}

# find pip
find_pip()
{
        for cmd in $PIPAPPS
        do
                _cmd=$(which $cmd 2>/dev/null)
                if [ $? -eq 0 ];then
                        break
                fi
        done
        if [ -z $_cmd ];then
                echo "Can't find \"pip\" in system, please install it first, exiting!"
                exit 1
        else
                PIPCMD=$_cmd
        fi
}

# git clone
gitclone()
{
        FROM=$1
        CLONEROOT=$2
        log "Cloning from \"$FROM\" repo to \"$CLONEROOT\""
        cd $CLONEROOT && git clone $FROM > /dev/null 2>&1
        if [ $? -ne 0 ];then
            log "cloning from \"$FROM\" fails, exiting!!!"
            exit
        fi
}

# install
inst()
{
CLONE_FROM_GIT=$1
# Checking packages
        for PKG in $PREREQ_PKGS
        do
                in_sys_pkg $PKG
        done
# Find python pip
        find_pip
# If clone from git set
        if [ ! -z $CLONE_FROM_GIT ]; then
# Preparing clone root directory
        if [ ! -d $GIT_CLONE_DIR ];then
                log "Creating $GIT_CLONE_DIR directory..."
                mkdir -p $GIT_CLONE_DIR
                if [ $? -ne 0 ];then
                        log "Can't create $GIT_CLONE_DIR, exiting!!!"
                        exit
                fi
        fi
# Cloning from GIT
                GIT_WEBPATH_PRFX="https://opendev.org/openstack/"
                gitclone "$GIT_WEBPATH_PRFX$SERVICE_SRV_NAME.git" $GIT_CLONE_DIR
# End clone from git section
        fi
# Setupping...
        log "Running setup.py"
        MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
        if [ -e $MRN_CND_SPY ]; then
                chmod +x $MRN_CND_SPY
                log "$MRN_CND_SPY output:_____________________________________________________________"
## Setup through pip
                # Creating tarball
                rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
                cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
                if [ $? -ne 0 ];then
                        log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
                        exit 1
                fi
                rm -rf $SERVICE_CONTENT_DIRECTORY/dist/*
                cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY sdist
                if [ $? -ne 0 ];then
                        log "\"$MRN_CND_SPY\" tarball creation FAILS, exiting!!!"
                        exit 1
                fi
                # Running tarball install
                TRBL_FILE=$(basename `ls $SERVICE_CONTENT_DIRECTORY/dist/*.tar.gz`)
                $PIPCMD install $SERVICE_CONTENT_DIRECTORY/dist/$TRBL_FILE
                if [ $? -ne 0 ];then
                        log "$PIPCMD install \"$TRBL_FILE\" FAILS, exiting!!!"
                        exit 1
                fi
        else
                log "$MRN_CND_SPY not found!"
        fi
}

# uninstall
uninst()
{
        # Uninstall trough  pip
        find_pip
        # looking up for python package installed
        PYPKG="muranoclient"
        _pkg=$($PIPCMD freeze | grep $PYPKG)
        if [ $? -eq 0 ]; then
                log "Removing package \"$PYPKG\" with pip"
                $PIPCMD uninstall $_pkg --yes
        else
                log "Python package \"$PYPKG\" not found"
        fi
}
# Command line args'
COMMAND="$1"
case $COMMAND in
        install )
                inst
                ;;

        installfromgit )
                inst "yes"
                ;;

        uninstall )
                log "Uninstalling muranoclient \"$SERVICE_SRV_NAME\" from system..."
                uninst
                ;;

        * )
                echo -e "Usage: $(basename "$0") command \nCommands:\n\tinstall - Install $SERVICE_SRV_NAME software\n\tuninstall - Uninstall $SERVICE_SRV_NAME software"
                exit 1
                ;;
esac