Project

General

Profile

root / trunk / sci.sh

1
#!/bin/bash
2
# Linux SCENARI application installer & setup
3
# Copyright (c) 2007-2019 samuel.monsarrat@kelis.fr
4
#
5

    
6
vMyName=`basename $0`
7
vCurrDir=`pwd`
8
vMyVersionMaj=5
9
vMyVersionMed=0
10
vMyVersionMin=0
11
vMyVersion=$vMyVersionMaj.$vMyVersionMed.$vMyVersionMin
12
vSrvUrlSci="https://svn.scenari.org/svn/sci/trunk"
13

    
14
vMyUsage="Usage: $vMyName OPTION -a (builder|chain|client|kit|styler)"
15
vTmpDir="/tmp/"`id -un`".scinstall"
16

    
17
vVersion="5.0"
18
vDefaultLang="en-US"
19
vLang="$vDefaultLang"
20
vSrvUrlPre="https://builds.kelis.fr/job/"
21
vArch="Linux_x86"
22
if [ "$(uname -m)" = "x86_64" ]; then
23
	vArch="Linux_x86_64"
24
fi
25

    
26
vSCApp=""
27
vScAppFullName=""
28

    
29
#===============================================================================
30
xInit () {
31
	# Look for a newer version of sci.
32
	xCheckSciUpdate
33

    
34
	vBashVers=`echo $BASH_VERSION`
35
	if [ -z "$vBashVers" ]; then
36
		echo
37
		echo "WARNING: $vMyName is a BASH script. It seems that the BASH shell is not"
38
		echo "available this system. You may run into problems."
39
		echo -n "Do you want to continue? (y|N): "
40
		read vResponse
41
		vResponse=`echo $vResponse | tr 'A-Z' 'a-z'`
42
		if [ "$vResponse" = "n" ]; then 
43
			echo "Aborting installation."
44
			echo
45
			exit 1
46
		fi
47
	fi
48

    
49
	# Check for dependencies.
50
	vMissingApps=""
51
	wget --version >> /dev/null 2>&1
52
	if [ "$?" -ne "0" ];then
53
		vMissingApps=$vMissingApps" - wget (http://www.gnu.org/software/wget/)
54
		"
55
	fi
56
	if [ "$vMissingApps" != "" ]; then
57
		echo
58
		echo "ERROR: the folowing dependencies are not met:"
59
		echo "$vMissingApps"
60
		echo "Aborting installation."
61
		echo
62
		exit 1
63
  fi
64

    
65
	# This script should not be run as root.
66
	if [ `id -u` -eq "0" ];then
67
		echo
68
		echo "WARNING! you are trying to run $vMyName with root privileges."
69
		echo "This is not currenty supported. Please run $vMyName as a normal user."
70
		echo
71
		echo "$vMyName -h for more details"
72
		exit 1
73
	fi
74

    
75
}
76

    
77
#===============================================================================
78
xHelp () {
79
cat << EOF
80

    
81
$vMyName downloads and installs requested SCENARI applications.
82
$vMyUsage
83

    
84
By default $vMyName will attempt to install applications system-wide and as such
85
requires the current user to be a sudo user that has root access
86
to /opt and /usr. Should this not be the case, either use the -u option to
87
perform a local user installation or the -r option to perform a system-wide
88
installation using the su command requiring the root password.
89

    
90
OPTIONS:
91

    
92
Application name (required):
93
  -a  Provide the name of the application to download and install:
94
      * builder  Download and install SCENARIbuilder.
95
      * chain    Download and install SCENARIchain-desktop.
96
      * client   Download and install SCENARIchain-client.
97
      * kit      Download SCENARIkit to the current directory.
98
      * styler   Download SCENARIstyler to the current directory.
99

    
100
Installation options (optional)
101
  -n  Nightly build: $vMyName will install the latest nightly build of the
102
      application that you request. If this switch is not present $vMyName
103
      will install the latest stable version.
104
  -c  Clean download and install: delete any previously attempted downloads
105
      before starting the download & install process.
106
  -d  Download only, do not install.
107
  -f  'force' mode: the installer does not interact with the user, all default
108
      choices are used. If the application is already installed it will be 
109
      replaced. This is basically equivalent to pressing return for each 
110
      question the the installer normally asks the user.
111
  -u  Local user installation: $vMyName will install the application in the
112
      current user's home directory.
113
  -r  System-wide installation using the su command requiring the root password.
114
      This option should be used if you are not a sudo user but have root access
115
      though the su command.
116
  -v  Version of SCENARI to install: 4.0, 4.1, 4.2 (default 5.0).
117

    
118
Language selection (optional)
119
  -l  Request a specific language.
120
      * en-US  Download and install English versions if possible (default)
121
      * fr-FR  Download and install French versions
122

    
123
Copyright (c) 2007-2019 samuel.monsarrat@kelis.fr
124
EOF
125
}
126

    
127

    
128
#===============================================================================
129
xCheckOptions () {
130
	if [ ! -z "$vUserInst" ] && [ ! -z "$vSUInst" ];then
131
		echo 
132
		echo "ERROR: You cannot use both -u and -r at the same time."
133
		echo "$vMyUsage"
134
		echo 
135
		echo "$vMyName -h for more details"
136
		exit 1
137
	fi
138
}
139

    
140
#===============================================================================
141
xCheckSciUpdate () {
142
	if [ -z "$vSkipCheckUpdate" ];then
143
		echo -n "Looking for updates for $vMyName..."
144
		mkdir $vTmpDir >> /dev/null 2>&1
145
		wget -q --no-cache -O $vTmpDir/latestsciversion.txt $vSrvUrlSci/latestversion.txt
146
		. $vTmpDir/latestsciversion.txt
147
		rm -f $vTmpDir/latestsciversion.txt
148
		if [ -z "$vSciLatestVersionMaj" ];then
149
			echo
150
			echo "WARNING: cannot connect to sci site to search for updates"
151
		else
152
			if [ "$vSciLatestVersionMaj" -gt "$vMyVersionMaj" ];then
153
				xSciUpdateAvailable
154
			elif [ "$vSciLatestVersionMaj" -eq "$vMyVersionMaj" ];then
155
				if [ "$vSciLatestVersionMed" -gt "$vMyVersionMed" ];then
156
					xSciUpdateAvailable
157
				elif [ "$vSciLatestVersionMed" -eq "$vMyVersionMed" ];then
158
					if [ "$vSciLatestVersionMin" -gt "$vMyVersionMin" ];then
159
						xSciUpdateAvailable "warnOnly"
160
					fi
161
				fi
162
			fi
163
			echo "OK"
164
		fi
165
	fi
166
}
167
xSciUpdateAvailable () {
168
	echo
169
	echo "WARNING: a new version (v$vSciLatestVersionMaj.$vSciLatestVersionMed.$vSciLatestVersionMin) of $vMyName exists and is available"
170
	echo "at $vSrvUrlSci/sci.sh"
171
	if [ "$1" = "warnOnly" ];then
172
		echo "You should download an use this version instead."
173
		echo -n "Do you still want to continue with the current version? [y/N]: "
174
		read vUserRes
175
		echo
176
		vUserRes=`echo $vUserRes | tr 'A-Z' 'a-z'`
177
		if [ "$vUserRes" != "y" ];then 
178
			echo
179
	  	exit 1
180
		fi
181
	else
182
		echo "You must download an use this version instead."
183
		echo
184
		exit 1
185
	fi
186
}
187

    
188
#===============================================================================
189
xScInst () {
190
	vAppName=$1
191
	if [ -z "$vNightly" ];then
192
		vInstallType="stable"
193
		vBuild="lastSuccessfulReleaseBuild"
194
	else
195
		vInstallType="nightly"
196
		vBuild="lastSuccessfulBuild"
197
	fi
198
	if [ -z "$vDwnLdOnly" ];then
199
		if [ -z "$vUserInst" ] || [ ! -z "$vSUInst" ];then
200
			echo -n "System-wide install of"
201
		else
202
			echo -n "Local user install of"
203
		fi
204
	else
205
		echo -n "Downloading"
206
	fi
207
	echo " the latest $vInstallType version of $vScAppFullName $vLang"
208
	mkdir $vTmpDir >> /dev/null 2>&1
209

    
210
	vSrvUrl="$vSrvUrlPre$vAppName-$vVersion/$vBuild"
211
	vSrvUrlXml="$vSrvUrl/api/xml?wrapper=root&xpath=/*/artifact/*%5Bcontains(text(),%27$vLang.$vArch.tgz%27)%5D"
212
	vXml=`wget -q "$vSrvUrlXml" -O -`
213
	if [ "$?" -ne "0" ];then
214
		echo
215
		echo "ERROR: a problem occured while connecting to $vSrvUrlPre."
216
		echo "Url $vSrvUrl unreachable."
217
		echo "Aborting installation."
218
		echo
219
		exit 1
220
	fi 
221
	vRelativePath=`echo $vXml | sed -e 's/.*<relativePath>\([^<]*\)<\/relativePath>.*/\1/'`
222
	vAppTgz=`echo $vXml | sed -e 's/.*<displayPath>\([^<]*\)<\/displayPath>.*/\1/'`
223

    
224
	echo "The latest package is:"
225
	echo "$vAppTgz"
226
	echo "Downloading..."
227
	wget -c --no-cache -O $vTmpDir/$vAppTgz $vSrvUrl/artifact/$vRelativePath
228
	if [ "$?" -ne "0" ];then
229
		echo
230
		echo "ERROR: $vMyName was unable to finish downloading $vScAppFullName $vLang."
231
		echo "Please try again."
232
		echo "Aborting installation."
233
		echo
234
		exit 1
235
	fi
236

    
237
	if [ -z "$vDwnLdOnly" ];then
238
		# Start install if not "download only"
239
		echo "Installing..."
240
		rm -f $vLastScAppBinPathFile >> /dev/null 2>&1
241
		touch $vLastScAppBinPathFile
242
		rm -Rf $vTmpDir/tmp >> /dev/null 2>&1
243
		mkdir -p $vTmpDir/tmp
244
		cp $vTmpDir/$vAppTgz $vTmpDir/tmp/$vAppTgz
245
		cd $vTmpDir/tmp >> /dev/null 2>&1
246
		tar xzf $vAppTgz
247
		if [ "$?" -ne "0" ]; then
248
			echo
249
			echo "ERROR: The downloaded copy of $vScAppFullName $vLang seems corrupted."
250
			echo "       Unable to open $vAppTgz."
251
			echo "Please run $vMyName with -c in order to download a fresh copy."
252
			echo
253
			exit 1
254
		fi
255
		if [ -z "$vUserInst" ];then
256
			echo "System-wide installation (defaults to /opt)"
257
			if [ -z "$vSUInst" ];then
258
				echo "$vMyName will use the sudo command that may require your password."
259
				sudo -v >/dev/null
260
				if [ "$?" -eq "0" ]; then
261
					sudo -s ./install.sh -l$vForceMode $vLastScAppBinPathFile
262
					if [ "$?" -ne "0" ]; then
263
						echo
264
						echo "ERROR: $vScAppFullName $vLang installation failed, $vMyName aborting."
265
						echo
266
						exit 1
267
					fi
268
				else
269
					echo
270
					echo "ERROR: Aborting installation."
271
					echo "Please run $vMyName with either:"
272
					echo "  -u for a local user installation"
273
					echo "  -r for a system-wide installation if you have root access."
274
					echo
275
					exit 1
276
				fi
277
			else
278
				echo "$vMyName will use the su command that may require the root password."
279
				su -c "./install.sh -l$vForceMode $vLastScAppBinPathFile"
280
				if [ "$?" -ne "0" ]; then
281
					echo
282
					echo "ERROR: $vScAppFullName $vLang installation failed, $vMyName aborting."
283
					echo
284
					exit 1
285
				fi
286
			fi
287
		else
288
			./install.sh -l$vForceMode $vLastScAppBinPathFile
289
			if [ "$?" -ne "0" ]; then
290
				echo
291
				echo "ERROR: $vScAppFullName $vLang installation failed, $vMyName aborting."
292
				echo
293
				exit 1
294
			fi
295
		fi
296
		cd $vCurrDir >> /dev/null 2>&1
297
		rm -Rf $vTmpDir/tmp >> /dev/null 2>&1
298
	else
299
		echo "Finished downloading $vScAppFullName $vLang to $vTmpDir."
300
	fi
301
	echo
302
}
303

    
304
#===============================================================================
305
xScProjDwnld () {
306
	vAppName=$1
307
	if [ -z "$vNightly" ];then
308
		vInstallType="Stable"
309
		vBuild="lastSuccessfulReleaseBuild"
310
	else
311
		vInstallType="Nightly"
312
		vBuild="lastSuccessfulBuild"
313
	fi
314
	echo "$vInstallType $vAppName downloader"
315
	mkdir $vTmpDir >> /dev/null 2>&1
316

    
317
	vSrvUrl="$vSrvUrlPre$vAppName-$vVersion/$vBuild"
318
	vSrvUrlXml="$vSrvUrl/api/xml?wrapper=root&xpath=/*/artifact/*%5Bcontains(text(),%27$vLang%27)%5D"
319
	vXml=`wget -q "$vSrvUrlXml" -O -`
320
	if [ "$?" -ne "0" ];then
321
		echo
322
		echo "ERROR: a problem occured while connecting to $vSrvUrlPre."
323
		echo "Url $vSrvUrl unreachable."
324
		echo "Aborting installation."
325
		echo
326
		exit 1
327
	fi 
328
	vRelativePath=`echo $vXml | sed -e 's/.*<relativePath>\([^<]*\)<\/relativePath>.*/\1/'`
329
	vAppTgz=`echo $vXml | sed -e 's/.*<displayPath>\([^<]*\)<\/displayPath>.*/\1/'`
330
	echo "The latest $vInstallType $vScAppFullName $vLang package is:"
331
	echo "$vAppTgz"
332
	echo "Downloading..."
333
	wget -c --no-cache -O $vAppTgz $vSrvUrl/artifact/$vRelativePath
334
	if [ "$?" -ne "0" ];then
335
		echo
336
		echo "ERROR: $vMyName was unable to finish downloading $vScAppFullName."
337
		echo "Please try again."
338
		echo "Aborting installation."
339
		echo
340
		exit 1
341
	fi
342
	echo "Finished downloading $vScAppFullName to $vCurrDir."
343
}
344

    
345
#===============================================================================
346
#START
347
echo "Linux SCENARI application installer & setup (version v$vMyVersion)"
348

    
349
# Parse options.
350
while getopts “:a:cdfhl:nruv:z” OPTION
351
do
352
	case $OPTION in
353
		a)
354
			vSCApp=$OPTARG
355
			;;
356
		c)
357
			vPurge="true"
358
			;;
359
		d)
360
			vDwnLdOnly="true"
361
			;;
362
		f)
363
			vForceMode="f"
364
			;;
365
		h)
366
			xHelp
367
			exit 0
368
			;;
369
		l)
370
			vLang=$OPTARG
371
			;;
372
		n)
373
			vNightly="true"
374
			;;
375
		r)
376
			vSUInst="true"
377
			;;
378
		u)
379
			vUserInst="true"
380
			;;
381
		v)
382
			vVersion=$OPTARG
383
			;;
384
		z)
385
			vSkipCheckUpdate="true"
386
			;;
387
		?)
388
			xHelp
389
			exit 1
390
			;;
391
	esac
392
done
393
xCheckOptions
394

    
395
# Run init script
396
xInit
397

    
398
if [ ! -z "$vPurge" ];then
399
	echo -n "Purging temp directory..."
400
	rm -Rf $vTmpDir >> /dev/null 2>&1
401
	echo "OK"
402
fi
403

    
404
# Just do it.
405
case "$vSCApp" in
406
builder)
407
	vLang="fr-FR"
408
	vScAppFullName="SCENARIbuilder$vVersion"
409
	xScInst SCbuilder
410
 ;;
411
chain)
412
	vScAppFullName="SCENARIchain$vVersion"
413
	xScInst SCchain
414
 ;;
415
client)
416
	vScAppFullName="SCENARIclient$vVersion"
417
	xScInst SCclient
418
 ;;
419
demo)
420
	vScAppFullName="SCENARIdemoServer$vVersion"
421
	xScInst SCdemoServer
422
 ;;
423
kit)
424
	vScAppFullName="SCENARIkit$vVersion"
425
	vLang=""
426
	xScProjDwnld SCkit
427
 ;;
428
styler)
429
	vScAppFullName="SCENARIstyler$vVersion"
430
	xScProjDwnld SCstyler
431
 ;;
432
*)
433
	echo 
434
	echo "ERROR: Missing or unknown SCENARI application name."
435
	echo "$vMyUsage"
436
	echo 
437
	echo "$vMyName -h for more details"
438
	exit 1
439
esac
(2-2/2)