pkgcheck-centos.sh

Brau-Nogué Sylvie, 03/07/2017 02:48 PM

Download (6.76 KB)

 
1
#!/bin/bash
2
# ==========================================================================
3
# ctools CentOS package validation
4
#
5
# Copyright (C) 2017 Sylvie Brau-Nogué
6
#
7
# This program is free software: you can redistribute it and/or modify
8
# it under the tesudo rms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
#
20
# -------------------------------------------------------------------------
21
#
22
# This script checks the ctools CentOS package by installing it into the
23
# /usr/local/gamma directory and running the Python tests.
24
#
25
# ==========================================================================
26

    
27
if [ $# -ne 2 ] ;  then
28
echo "Please specify package name and version in the form 'package x.y.z'"
29
exit 1
30
fi
31
PACKNAME=$1
32
VERSION=$2
33
# TODO : next step to fix RELEASE is not updated for now
34
RELEASE=1
35

    
36

    
37
# =============================== #
38
# Set software component versions #
39
# =============================== #
40
PACKAGE=$PACKNAME-$VERSION-$RELEASE
41

    
42

    
43
# ============== #
44
# Set parameters #
45
# ============== #
46
INSTALLDIR=/usr/local/gamma
47
WRKDIR=$HOME/pkg_check
48
LOCALINSTALL=$WRKDIR$INSTALLDIR
49
#
50
PKGDIR=$HOME/rpmbuild/RPMS/noarch
51
RPMFILE=$PKGDIR/$PACKAGE.noarch.rpm
52
#
53
LOGFILE=$WRKDIR/pkg_check.log
54
LOGRPMFILE=$WRKDIR/pkg_check_rpm.log
55

    
56

    
57
# ============================= #
58
# Secure installation directory #
59
# ============================= #
60
# SBN : pas besoin              #
61
# ============================= #
62

    
63
#if [ -d "$LOCALINSTALL/ctools" ]; then
64
#    mv $LOCALINSTALL/ctools $LOCALINSTALL/ctools.backup
65
#fi
66

    
67

    
68
# ======================= #
69
# Clean working directory #
70
# ======================= #
71
sudo rm -rf $WRKDIR
72

    
73
# ====================================== #
74
# Create and step into working directory #
75
# ====================================== #
76
mkdir -p $WRKDIR
77
cd $WRKDIR
78

    
79
# ========================================================================= #
80
# Install package in local directory                                        #
81
# ========================================================================= #
82
# 2 options with rpm                                                        #
83
#  --relocate <old>=<new>    relocate files from path <old> to <new>        #
84
#sudo rpm -U --relocate=$INSTALLDIR=$LOCALINSTALL $RPMFILE &>  $LOGRPMFILE  #
85
# or                                                                        #
86
#  --prefix=<dir>            relocate the package to <dir>, if relocatable  #
87
# ========================================================================= #
88

    
89

    
90
if ! rpm -qa | grep -q gammalib ;  then
91
   echo "================================================================================================="
92
   echo " ERROR : gammalib (gammalib >= 1.2.0.dev1) need to be installed"
93
   echo "   "
94
   echo "================================================================================================="
95
   exit
96
fi
97
# Check gammalib version
98
v=$(rpm --qf '%{VERSION}\n' -q gammalib)
99
echo "gammalib $v checked"
100

    
101
if ! rpm -qa | grep -q ncurses; then
102
   echo "ncurses need to be installed"
103
   sudo yum install ncurses
104
   if ! rpm -qa | grep -q ncurses; then
105
      echo "================================================================================================="
106
      echo "ERROR : ncurses need to be installed manually"
107
      echo "   "
108
      echo "================================================================================================="
109
      exit
110
   fi
111
fi
112
# Check ncurses version
113
v=$(rpm --qf '%{VERSION}\n' -q ncurses)
114
echo "ncurses $v checked"
115

    
116
if ! rpm -qa | grep -q readline; then
117
   echo "readline need to be installed"
118
   sudo yum install readline
119
   if ! rpm -qa | grep -q readline; then
120
      echo "================================================================================================="
121
      echo "ERROR : readline need to be installed manually"
122
      echo "   "
123
      echo "================================================================================================="
124
      exit
125
   fi
126
fi
127
# Check readline version
128
v=$(rpm --qf '%{VERSION}\n' -q readline)
129
echo "readline $v checked"
130

    
131
if ! rpm -qa | grep -q cfitsio; then
132
   echo "readline need to be installed"
133
   sudo yum install cfitsio-devel
134
   if ! rpm -qa | grep -q cfitsio; then
135
      echo "================================================================================================="
136
      echo " ERROR : cfitsio need to be installed"
137
      echo "================================================================================================="
138
      echo "You can download the latest version of CFITSIO on http://heasarc.gsfc.nasa.gov/fitsio/fitsio.html"
139
      echo "   "
140
      echo "or "
141
      echo "   "
142
      echo "cfitsio rpm can be found in the epel-release repository ; Try : sudo yum install cfitsio-devel"
143
      echo "   "
144
      echo "================================================================================================="
145
      exit
146
   fi
147
fi
148
# Check cfitsio version
149
v=$(rpm --qf '%{VERSION}\n' -q cfitsio)
150
echo "cfitsio $v checked"
151

    
152
if ! sudo rpm -U --prefix=$LOCALINSTALL $RPMFILE &>  $LOGRPMFILE ; then
153
   echo "================================================================================================="
154
   echo "ERROR : Cannot install ctools package"
155
   echo "================================================================================================="
156
   cat  $LOGRPMFILE
157
   echo "   "
158
   echo "================================================================================================="
159
   exit
160
fi
161

    
162

    
163
# ================= #
164
# Configure package #
165
# ================= #
166
export GAMMALIB=$INSTALLDIR/gammalib
167
source $GAMMALIB/bin/gammalib-init.sh
168
export CTOOLS=$LOCALINSTALL/$PACKNAME
169
source $CTOOLS/bin/$PACKNAME-init.sh
170

    
171

    
172

    
173
# ============ #
174
# Test package #
175
# ============ #
176
python -c 'import gammalib; gammalib.test()' | tee -a $LOGFILE
177
python -c 'import ctools; ctools.test()' | tee -a $LOGFILE
178
python -c 'import cscripts; cscripts.test()' | tee -a $LOGFILE
179

    
180

    
181
# ======================= #
182
# Uninstall package       #
183
# ======================= #
184
sudo yum remove $PACKNAME
185

    
186
# ======================= #
187
# Clean package directory #
188
# ======================= #
189
sudo rm -rf $LOCALINSTALL
190

    
191
# ============================== #
192
# Recover installation directory #
193
# ============================== #
194
# SBN : pas besoin              #
195
# ============================= #
196

    
197
#if [ -d "$LOCALINSTALL/ctools.backup" ]; then
198
#    mv $LOCALINSTALL/ctools.backup $LOCALINSTALL/ctools
199
#fi