]> Creatis software - creaToolsTools.git/blob - Linux/scripts/LocalFunctions.sh
#3405 creaToolsTools Feature New Normal - vtk8itk5wx3-macos
[creaToolsTools.git] / Linux / scripts / LocalFunctions.sh
1 # ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
4 #                        pour la Santé)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 #
7 #  This software is governed by the CeCILL-B license under French law and 
8 #  abiding by the rules of distribution of free software. You can  use, 
9 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
10 #  license as circulated by CEA, CNRS and INRIA at the following URL 
11 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
12 #  or in the file LICENSE.txt.
13 #
14 #  As a counterpart to the access to the source code and  rights to copy,
15 #  modify and redistribute granted by the license, users are provided only
16 #  with a limited warranty  and the software's author,  the holder of the
17 #  economic rights,  and the successive licensors  have only  limited
18 #  liability. 
19 #
20 #  The fact that you are presently reading this means that you have had
21 #  knowledge of the CeCILL-B license and that you accept its terms.
22 # ------------------------------------------------------------------------  
23
24 #!/bin/bash -e
25
26
27
28 ##########################################
29 # check that $1 is one of $2, $3, ...
30 function checkVal  {
31     local val=$1
32     shift
33     for x in $* ; do
34         if [ "$val" == "$x" ] ; then
35             echo "true"
36             return
37         fi
38     done
39     echo "false"
40 }
41
42 ###########################################
43 function bigDisplay {
44     echo " ================================================================================================"
45     echo " ================================================================================================"
46     echo " ======= $1"                                       
47     echo " ================================================================================================"
48     echo " ================================================================================================"
49 }
50
51 ###########################################
52 function checkDistrib {
53     local OS=$1
54     if [ "`checkVal $OS MacOS Fedora Ubuntu Mandriva CentOS`" == "false" ] ; then
55         echo "Operating System not supported: $OS"
56         echo "Currently supported system: Fedora Ubuntu MacOS"
57         exit 1
58     fi
59 }
60
61 ###########################################
62 function getDistrib {
63     local OS=`uname`
64
65         if [ "$OS" == Darwin ] ; then OS=MacOS;
66 ##EED2016-10-15    
67 ##    elif [ "$OS" == Linux  ] ; then OS=$(lsb_release -i | awk '{print $3}')
68         elif [ "$OS" == Linux  ] ; then 
69                 OS=`awk 'NR==1{print $1}' /etc/system-release`
70                 if [ "$OS" == "" ] ; then 
71                         OS=$(lsb_release -i | awk '{print $3}')
72                 fi
73     else OS=""
74     fi
75 # checkDistrib $OS
76     echo $OS
77 }
78
79 ###########################################
80 function getDistribVersion {
81     local DISTRIB=`getDistrib`
82
83       if [ "$DISTRIB" == MacOS ] ; then OSVesion=VOID_Darwin_EED;
84     elif [ "$DISTRIB" == Fedora  ] ; then OSVersion=`awk 'NR==1{print $3}' /etc/system-release`
85     elif [ "$DISTRIB" == Ubuntu  ] ; then OSVersion=`awk 'NR==1{print $2}' /etc/issue`
86     elif [ "$DISTRIB" == CentOS  ] ; then OSVersion=`awk 'NR==1{print $3}' /etc/issue`
87     else OSVersion="VOID_EED"
88     fi
89     echo $OSVersion
90 }
91
92 ###########################################
93 function getKernelVersion {
94     local DISTRIB=`getDistrib`
95
96       if [ "$DISTRIB" == MacOS ] ; then KernelVesion=VOID_Darwin_EED;
97     elif [ "$DISTRIB" == Fedora  ] ; then KernelVersion=$(uname -a | awk '{print $3}')
98     elif [ "$DISTRIB" == Ubuntu  ] ; then KernelVersion=$(uname -a | awk '{print $3}')
99     elif [ "$DISTRIB" == CentOS  ] ; then KernelVersion=$(uname -a | awk '{print $3}')
100     else KernelVersion="VOID_EED"
101     fi
102     echo $KernelVersion
103 }
104
105
106
107
108 ###########################################
109 function getDownloadCommand {
110     local DISTRIB=`getDistrib`
111
112       if [ "$DISTRIB" == MacOS ] ; then downloadCommand=curl;
113     elif [ "$DISTRIB" == Fedora  ] ; then downloadCommand='aria2c -x 16'
114     elif [ "$DISTRIB" == CentOs  ] ; then downloadCommand='aria2c -x 16'
115     elif [ "$DISTRIB" == Ubuntu  ] ; then downloadCommand=wget
116     else downloadCommand="VOID_EED"
117     fi
118     echo $downloadCommand
119 }
120
121 ###########################################
122 function getncore {
123     if [ `uname` == Darwin ] ; then # MacOS
124 #EED 2018-08-26
125 #        system_profiler | grep Processor | awk '$1=="Number" {print $4}'
126         sysctl hw.physicalcpu hw.logicalcpu | grep logicalcpu | awk '{print $2}'
127     else
128         cat /proc/cpuinfo | grep processor | wc -l
129     fi
130 }
131
132 ###########################################
133 function getbashrc {
134     if [ ! -f $HOME/.bashrc ] ; then
135         touch $HOME/.bashrc
136     fi
137     echo $HOME/.bashrc
138
139
140 #    # Do it, while we are under user, not under root! # JPR
141 #    if [ -f $HOME/.bashrc ] ; then
142 #        echo $HOME/.bashrc
143 #    else
144 #        if [ -f $HOME/.profile ] ; then
145 #            echo $HOME/.profile
146 #        else
147 #            echo "=============== BIG TROUBLE : neither $HOME/.bashrc nor $HOME/.profile file found" > /dev/stderr
148 #            echo "=============== You'd better abort the program and (try to) fix the issue" > /dec/stderr
149 #            read a # just to let the user time enough to read the message...
150 #        fi
151 #    fi
152 }
153
154
155 ###########################################
156 function printconfig {
157     echo
158     echo "Current Configuration:"
159     echo "  Operating System                           : $OperatingSystem"
160     echo "  Number of Cores                            : $corenumber"   
161     echo "  Name of the Generation Directory           : $generationdir"
162     echo "  Install Prefix for Third Party Libraries   : $installPrefixThird"   
163     echo "  Install Prefix for CreaTools               : $installPrefix"
164     echo "  Boolean for Doc Generation                 : $docgeneration"
165     echo "  Where do you want to get source files from : $sourcesFrom"
166     echo "  Login User Name                            : $loginUserName"
167     echo "  Login Group Name                           : $loginGroupName"
168     echo "  Build type                                 : $buildType"          
169     echo "  Gdcm version                               : $gdcmVersion"
170     echo "  ITK version                                : $ITKVersion"
171     echo
172 }
173
174