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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
|
#!/bin/bash
#####################################################################
####### Algunas funciones útiles de propósito general:
#####################################################################
function getDateTime()
{
echo `date +%Y%m%d-%H%M%S`
}
# Escribe a fichero y muestra por pantalla
function echoAndLog()
{
echo $1
FECHAHORA=`getDateTime`
echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE
}
function errorAndLog()
{
echo "ERROR: $1"
FECHAHORA=`getDateTime`
echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE
}
# comprueba si el elemento pasado en $2 esta en el array $1
function isInArray()
{
if [ $# -ne 2 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
echoAndLog "${FUNCNAME}(): checking if $2 is in $1"
local deps
eval "deps=( \"\${$1[@]}\" )"
elemento=$2
local is_in_array=1
# copia local del array del parametro 1
for (( i = 0 ; i < ${#deps[@]} ; i++ ))
do
if [ "${deps[$i]}" = "${elemento}" ]; then
echoAndLog "isInArray(): $elemento found in array"
is_in_array=0
fi
done
if [ $is_in_array -ne 0 ]; then
echoAndLog "${FUNCNAME}(): $elemento NOT found in array"
fi
return $is_in_array
}
#####################################################################
####### Funciones de manejo de paquetes Debian
#####################################################################
function checkPackage()
{
package=$1
if [ -z $package ]; then
errorAndLog "checkPackage(): parameter required"
exit 1
fi
echoAndLog "checkPackage(): checking if package $package exists"
dpkg -s $package | grep Status | grep -qw install &>/dev/null
if [ $? -eq 0 ]; then
echoAndLog "checkPackage(): package $package exists"
return 0
else
echoAndLog "checkPackage(): package $package doesn't exists"
return 1
fi
}
# recibe array con dependencias
# por referencia deja un array con las dependencias no resueltas
# devuelve 1 si hay alguna dependencia no resuelta
function checkDependencies()
{
if [ $# -ne 2 ]; then
errorAndLog "checkDependencies(): invalid number of parameters"
exit 1
fi
echoAndLog "checkDependencies(): checking dependences"
uncompletedeps=0
# copia local del array del parametro 1
local deps
eval "deps=( \"\${$1[@]}\" )"
declare -a local_notinstalled
for (( i = 0 ; i < ${#deps[@]} ; i++ ))
do
checkPackage ${deps[$i]}
if [ $? -ne 0 ]; then
local_notinstalled[$uncompletedeps]=$package
let uncompletedeps=uncompletedeps+1
fi
done
# relleno el array especificado en $2 por referencia
for (( i = 0 ; i < ${#local_notinstalled[@]} ; i++ ))
do
eval "${2}[$i]=${local_notinstalled[$i]}"
done
# retorna el numero de paquetes no resueltos
echoAndLog "checkDependencies(): dependencies uncompleted: $uncompletedeps"
return $uncompletedeps
}
# Recibe un array con las dependencias y lo instala
function installDependencies()
{
if [ $# -ne 1 ]; then
errorAndLog "installDependencies(): invalid number of parameters"
exit 1
fi
echoAndLog "installDependencies(): installing uncompleted dependencies"
# copia local del array del parametro 1
local deps
eval "deps=( \"\${$1[@]}\" )"
local string_deps=""
for (( i = 0 ; i < ${#deps[@]} ; i++ ))
do
string_deps="$string_deps ${deps[$i]}"
done
if [ -z "${string_deps}" ]; then
errorAndLog "installDependencies(): array of dependeces is empty"
exit 1
fi
OLD_DEBIAN_FRONTEND=$DEBIAN_FRONTEND
export DEBIAN_FRONTEND=noninteractive
echoAndLog "installDependencies(): now ${string_deps} will be installed"
apt-get -y install --force-yes ${string_deps}
if [ $? -ne 0 ]; then
errorAndLog "installDependencies(): error installing dependencies"
return 1
fi
DEBIAN_FRONTEND=$OLD_DEBIAN_FRONTEND
echoAndLog "installDependencies(): dependencies installed"
}
# Hace un backup del fichero pasado por parámetro
# deja un -last y uno para el dÃa
function backupFile()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local fichero=$1
local fecha=`date +%Y%m%d`
if [ ! -f $fichero ]; then
errorAndLog "${FUNCNAME}(): file $fichero doesn't exists"
return 1
fi
echoAndLog "${FUNCNAME}(): realizando backup de $fichero"
# realiza una copia de la última configuración como last
cp -p $fichero "${fichero}-LAST"
# si para el dÃa no hay backup lo hace, sino no
if [ ! -f "${fichero}-${fecha}" ]; then
cp -p $fichero "${fichero}-${fecha}"
fi
echoAndLog "${FUNCNAME}(): backup realizado"
}
#####################################################################
####### Funciones para el manejo de bases de datos
#####################################################################
# This function set password to root
function mysqlSetRootPassword()
{
if [ $# -ne 1 ]; then
errorAndLog "mysqlSetRootPassword(): invalid number of parameters"
exit 1
fi
local root_mysql=$1
echoAndLog "mysqlSetRootPassword(): setting root password in MySQL server"
/usr/bin/mysqladmin -u root password ${root_mysql}
if [ $? -ne 0 ]; then
errorAndLog "mysqlSetRootPassword(): error while setting root password in MySQL server"
return 1
fi
echoAndLog "mysqlSetRootPassword(): root password saved!"
return 0
}
# Si el servicio mysql esta ya instalado cambia la variable de la clave del root por la ya existente
function mysqlGetRootPassword(){
local pass_mysql
local pass_mysql2
# Comprobar si MySQL está instalado con la clave de root por defecto.
if mysql -u root -p"$MYSQL_ROOT_PASSWORD" <<<"quit" 2>/dev/null; then
echoAndLog "${FUNCNAME}(): Using default mysql root password."
else
stty -echo
echo "Existe un servicio mysql ya instalado"
read -p "Insertar clave de root de Mysql: " pass_mysql
echo ""
read -p "Confirmar clave:" pass_mysql2
echo ""
stty echo
if [ "$pass_mysql" == "$pass_mysql2" ] ;then
MYSQL_ROOT_PASSWORD=$pass_mysql
echo "La clave es: ${MYSQL_ROOT_PASSWORD}"
return 0
else
echo "Las claves no coinciden no se configura la clave del servidor de base de datos."
echo "las operaciones con la base de datos daran error"
return 1
fi
fi
}
# comprueba si puede conectar con mysql con el usuario root
function mysqlTestConnection()
{
if [ $# -ne 1 ]; then
errorAndLog "mysqlTestConnection(): invalid number of parameters"
exit 1
fi
local root_password="${1}"
echoAndLog "mysqlTestConnection(): checking connection to mysql..."
echo "" | mysql -uroot -p"${root_password}"
if [ $? -ne 0 ]; then
errorAndLog "mysqlTestConnection(): connection to mysql failed, check root password and if daemon is running!"
return 1
else
echoAndLog "mysqlTestConnection(): connection success"
return 0
fi
}
# comprueba si la base de datos existe
function mysqlDbExists()
{
if [ $# -ne 2 ]; then
errorAndLog "mysqlDbExists(): invalid number of parameters"
exit 1
fi
local root_password="${1}"
local database=$2
echoAndLog "mysqlDbExists(): checking if $database exists..."
echo "show databases" | mysql -uroot -p"${root_password}" | grep "^${database}$"
if [ $? -ne 0 ]; then
echoAndLog "mysqlDbExists():database $database doesn't exists"
return 1
else
echoAndLog "mysqlDbExists():database $database exists"
return 0
fi
}
function mysqlCheckDbIsEmpty()
{
if [ $# -ne 2 ]; then
errorAndLog "mysqlCheckDbIsEmpty(): invalid number of parameters"
exit 1
fi
local root_password="${1}"
local database=$2
echoAndLog "mysqlCheckDbIsEmpty(): checking if $database is empty..."
num_tablas=`echo "show tables" | mysql -uroot -p"${root_password}" "${database}" | wc -l`
if [ $? -ne 0 ]; then
errorAndLog "mysqlCheckDbIsEmpty(): error executing query, check database and root password"
exit 1
fi
if [ $num_tablas -eq 0 ]; then
echoAndLog "mysqlCheckDbIsEmpty():database $database is empty"
return 0
else
echoAndLog "mysqlCheckDbIsEmpty():database $database has tables"
return 1
fi
}
function mysqlImportSqlFileToDb()
{
if [ $# -ne 3 ]; then
errorAndLog "${FNCNAME}(): invalid number of parameters"
exit 1
fi
local root_password="${1}"
local database=$2
local sqlfile=$3
if [ ! -f $sqlfile ]; then
errorAndLog "${FUNCNAME}(): Unable to locate $sqlfile!!"
return 1
fi
echoAndLog "${FUNCNAME}(): importing sql file to ${database}..."
perl -pi -e "s/SERVERIP/$SERVERIP/g; s/DEFAULTUSER/$OPENGNSYS_DB_DEFAULTUSER/g; s/DEFAULTPASSWD/$OPENGNSYS_DB_DEFAULTPASSWD/g" $sqlfile
mysql -uroot -p"${root_password}" --default-character-set=utf8 "${database}" < $sqlfile
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while importing $sqlfile in database $database"
return 1
fi
echoAndLog "${FUNCNAME}(): file imported to database $database"
return 0
}
# Crea la base de datos
function mysqlCreateDb()
{
if [ $# -ne 2 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local root_password="${1}"
local database=$2
echoAndLog "${FUNCNAME}(): creating database..."
mysqladmin -u root --password="${root_password}" create $database
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while creating database $database"
return 1
fi
echoAndLog "${FUNCNAME}(): database $database created"
return 0
}
function mysqlCheckUserExists()
{
if [ $# -ne 2 ]; then
errorAndLog "mysqlCheckUserExists(): invalid number of parameters"
exit 1
fi
local root_password="${1}"
local userdb=$2
echoAndLog "mysqlCheckUserExists(): checking if $userdb exists..."
echo "select user from user where user='${userdb}'\\G" |mysql -uroot -p"${root_password}" mysql | grep user
if [ $? -ne 0 ]; then
echoAndLog "mysqlCheckUserExists(): user doesn't exists"
return 1
else
echoAndLog "mysqlCheckUserExists(): user already exists"
return 0
fi
}
# Crea un usuario administrativo para la base de datos
function mysqlCreateAdminUserToDb()
{
if [ $# -ne 4 ]; then
errorAndLog "mysqlCreateAdminUserToDb(): invalid number of parameters"
exit 1
fi
local root_password=$1
local database=$2
local userdb=$3
local passdb=$4
echoAndLog "mysqlCreateAdminUserToDb(): creating admin user ${userdb} to database ${database}"
cat > $WORKDIR/create_${database}.sql <<EOF
GRANT USAGE ON *.* TO '${userdb}'@'localhost' IDENTIFIED BY '${passdb}' ;
GRANT ALL PRIVILEGES ON ${database}.* TO '${userdb}'@'localhost' WITH GRANT OPTION ;
FLUSH PRIVILEGES ;
EOF
mysql -u root --password=${root_password} < $WORKDIR/create_${database}.sql
if [ $? -ne 0 ]; then
errorAndLog "mysqlCreateAdminUserToDb(): error while creating user in mysql"
rm -f $WORKDIR/create_${database}.sql
return 1
else
echoAndLog "mysqlCreateAdminUserToDb(): user created ok"
rm -f $WORKDIR/create_${database}.sql
return 0
fi
}
#####################################################################
####### Funciones para el manejo de Subversion
#####################################################################
function svnExportCode()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local url=$1
echoAndLog "${FUNCNAME}(): downloading subversion code..."
svn export "${url}" opengnsys
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error getting code from ${url}, verify your user and password"
return 1
fi
echoAndLog "${FUNCNAME}(): subversion code downloaded"
return 0
}
############################################################
### Detectar red
############################################################
function getNetworkSettings()
{
# Variables globales definidas:
# - SERVERIP: IP local del servidor.
# - NETIP: IP de la red.
# - NETMASK: máscara de red.
# - NETBROAD: IP de difusión de la red.
# - ROUTERIP: IP del router.
# - DNSIP: IP del servidor DNS.
local MAINDEV
echoAndLog "${FUNCNAME}(): Detecting default network parameters."
MAINDEV=$(ip -o link show up | awk '!/loopback/ {d=d$2} END {sub(/:.*/,"",d); print d}')
if [ -z "$MAINDEV" ]; then
errorAndLog "${FUNCNAME}(): Network device not detected."
exit 1
fi
SERVERIP=$(ip -o addr show dev $MAINDEV | awk '$3~/inet$/ {sub (/\/.*/, ""); print ($4)}')
NETMASK=$(LANG=C ifconfig $MAINDEV | awk '/Mask/ {sub(/.*:/,"",$4); print $4}')
NETBROAD=$(ip -o addr show dev $MAINDEV | awk '$3~/inet$/ {print ($6)}')
NETIP=$(netstat -nr | grep $MAINDEV | awk '$1!~/0\.0\.0\.0/ {if (n=="") n=$1} END {print n}')
ROUTERIP=$(netstat -nr | awk '$1~/0\.0\.0\.0/ {print $2}')
DNSIP=$(awk '/nameserver/ {print $2}' /etc/resolv.conf | head -n1)
if [ -z "$NETIP" -o -z "$NETMASK" ]; then
errorAndLog "${FUNCNAME}(): Network not detected."
exit 1
fi
# Variables de ejecución de Apache
# - APACHE_RUN_USER
# - APACHE_RUN_GROUP
if [ -f /etc/apache2/envvars ]; then
source /etc/apache2/envvars
fi
APACHE_RUN_USER=${APACHE_RUN_USER:-"www-data"}
APACHE_RUN_GROUP=${APACHE_RUN_GROUP:-"www-data"}
}
############################################################
### Esqueleto para el Servicio pxe y contenedor tftpboot ###
############################################################
function tftpConfigure() {
echo "Configurando el servicio tftp"
basetftp=/var/lib/tftpboot
# reiniciamos demonio internet ????? porque ????
/etc/init.d/openbsd-inetd start
# preparacion contenedor tftpboot
cp -pr /usr/lib/syslinux/ ${basetftp}/syslinux
cp /usr/lib/syslinux/pxelinux.0 ${basetftp}
# prepamos el directorio de la configuracion de pxe
mkdir -p ${basetftp}/pxelinux.cfg
cat > ${basetftp}/pxelinux.cfg/default <<EOF
DEFAULT pxe
LABEL pxe
KERNEL linux
APPEND initrd=initrd.gz ip=dhcp ro vga=788 irqpoll acpi=on
EOF
# comprobamos el servicio tftp
sleep 1
testPxe
## damos perfimos de lectura a usuario web.
chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP ${basetftp}
}
function testPxe () {
cd /tmp
echo "comprobando servicio pxe ..... Espere"
tftp -v localhost -c get pxelinux.0 /tmp/pxelinux.0 && echo "servidor tftp OK" || echo "servidor tftp KO"
cd /
}
########################################################################
## Configuracion servicio NFS
########################################################################
# ADVERTENCIA: usa variables globales NETIP y NETMASK!
function nfsConfigure()
{
echoAndLog "${FUNCNAME}(): Config nfs server."
backupFile /etc/exports
nfsAddExport /opt/opengnsys/client ${NETIP}/${NETMASK}:ro,no_subtree_check,no_root_squash,sync
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while adding nfs client config"
return 1
fi
nfsAddExport /opt/opengnsys/images ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync,crossmnt
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while adding nfs images config"
return 1
fi
nfsAddExport /opt/opengnsys/log/clients ${NETIP}/${NETMASK}:rw,no_subtree_check,no_root_squash,sync
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while adding logging client config"
return 1
fi
/etc/init.d/nfs-kernel-server restart
exportfs -va
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while configure exports"
return 1
fi
echoAndLog "${FUNCNAME}(): Added NFS configuration to file \"/etc/exports\"."
return 0
}
# ejemplos:
#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0:ro,no_subtree_check,no_root_squash,sync
#nfsAddExport /opt/opengnsys 192.168.0.0/255.255.255.0
#nfsAddExport /opt/opengnsys 80.20.2.1:ro 192.123.32.2:rw
function nfsAddExport()
{
if [ $# -lt 2 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
if [ ! -f /etc/exports ]; then
errorAndLog "${FUNCNAME}(): /etc/exports don't exists"
return 1
fi
local export="${1}"
local contador=0
local cadenaexport
grep "^${export}" /etc/exports > /dev/null
if [ $? -eq 0 ]; then
echoAndLog "${FUNCNAME}(): $export exists in /etc/exports, omiting"
return 0
fi
cadenaexport="${export}"
for parametro in $*
do
if [ $contador -gt 0 ]
then
host=`echo $parametro | awk -F: '{print $1}'`
options=`echo $parametro | awk -F: '{print $2}'`
if [ "${host}" == "" ]; then
errorAndLog "${FUNCNAME}(): host can't be empty"
return 1
fi
cadenaexport="${cadenaexport}\t${host}"
if [ "${options}" != "" ]; then
cadenaexport="${cadenaexport}(${options})"
fi
fi
let contador=contador+1
done
echo -en "$cadenaexport\n" >> /etc/exports
echoAndLog "${FUNCNAME}(): add $export to /etc/exports"
return 0
}
########################################################################
## Configuracion servicio DHCP
########################################################################
function dhcpConfigure()
{
echoAndLog "${FUNCNAME}(): Sample DHCP Configuration."
backupFile /etc/dhcp3/dhcpd.conf
sed -e "s/SERVERIP/$SERVERIP/g" \
-e "s/NETIP/$NETIP/g" \
-e "s/NETMASK/$NETMASK/g" \
-e "s/NETBROAD/$NETBROAD/g" \
-e "s/ROUTERIP/$ROUTERIP/g" \
-e "s/DNSIP/$DNSIP/g" \
$WORKDIR/opengnsys/server/DHCP/dhcpd.conf > /etc/dhcp3/dhcpd.conf
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while configuring dhcp server"
return 1
fi
/etc/init.d/dhcp3-server restart
echoAndLog "${FUNCNAME}(): Sample DHCP Configured in file \"/etc/dhcp3/dhcpd.conf\"."
return 0
}
#####################################################################
####### Funciones especÃficas de la instalación de Opengnsys
#####################################################################
# Copiar ficheros del OpenGnSys Web Console.
function installWebFiles()
{
echoAndLog "${FUNCNAME}(): Installing web files..."
cp -ar $WORKDIR/opengnsys/admin/WebConsole/* $INSTALL_TARGET/www #*/ comentario para doxigen
if [ $? != 0 ]; then
errorAndLog "${FUNCNAME}(): Error copying web files."
exit 1
fi
find $INSTALL_TARGET/www -name .svn -type d -exec rm -fr {} \; 2>/dev/null
# Cambiar permisos para ficheros especiales.
chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP \
$INSTALL_TARGET/www/includes \
$INSTALL_TARGET/www/comandos/gestores/filescripts \
$INSTALL_TARGET/www/images/iconos
echoAndLog "${FUNCNAME}(): Web files installed successfully."
}
# Configuración especÃfica de Apache.
function openGnsysInstallWebConsoleApacheConf()
{
if [ $# -ne 2 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local path_opengnsys_base=$1
local path_apache2_confd=$2
local path_web_console=${path_opengnsys_base}/www
if [ ! -d $path_apache2_confd ]; then
errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation"
return 1
fi
mkdir -p $path_apache2_confd/{sites-available,sites-enabled}
echoAndLog "${FUNCNAME}(): creating apache2 config file.."
# genera configuración
cat > $path_opengnsys_base/etc/apache.conf <<EOF
# OpenGnSys Web Console configuration for Apache
Alias /opengnsys ${path_web_console}
<Directory ${path_web_console}>
Options -Indexes FollowSymLinks
DirectoryIndex acceso.php
</Directory>
EOF
ln -fs $path_opengnsys_base/etc/apache.conf $path_apache2_confd/sites-available/opengnsys.conf
ln -fs $path_apache2_confd/sites-available/opengnsys.conf $path_apache2_confd/sites-enabled/opengnsys.conf
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation"
return 1
else
echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon"
/etc/init.d/apache2 restart
return 0
fi
}
# Crear documentación Doxygen para la consola web.
function makeDoxygenFiles()
{
echoAndLog "${FUNCNAME}(): Making Doxygen web files..."
$WORKDIR/opengnsys/installer/ogGenerateDoc.sh \
$WORKDIR/opengnsys/client/engine $INSTALL_TARGET/www
if [ ! -d "$INSTALL_TARGET/www/html" ]; then
errorAndLog "${FUNCNAME}(): unable to create Doxygen web files."
return 1
fi
mv "$INSTALL_TARGET/www/html" "$INSTALL_TARGET/www/api"
chown -R $APACHE_RUN_USER:$APACHE_RUN_GROUP $INSTALL_TARGET/www/api
echoAndLog "${FUNCNAME}(): Doxygen web files created successfully."
}
# Crea la estructura base de la instalación de opengnsys
function openGnsysInstallCreateDirs()
{
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local path_opengnsys_base=$1
echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base"
mkdir -p $path_opengnsys_base
mkdir -p $path_opengnsys_base/admin/{autoexec,comandos,menus,usuarios}
mkdir -p $path_opengnsys_base/bin
mkdir -p $path_opengnsys_base/client
mkdir -p $path_opengnsys_base/doc
mkdir -p $path_opengnsys_base/etc
mkdir -p $path_opengnsys_base/lib
mkdir -p $path_opengnsys_base/log/clients
mkdir -p $path_opengnsys_base/sbin
mkdir -p $path_opengnsys_base/www
mkdir -p $path_opengnsys_base/images
ln -fs /var/lib/tftpboot $path_opengnsys_base
ln -fs $path_opengnsys_base/log /var/log/opengnsys
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?"
return 1
fi
echoAndLog "${FUNCNAME}(): directory paths created"
return 0
}
# Copia ficheros de configuración y ejecutables genéricos del servidor.
function openGnsysCopyServerFiles () {
if [ $# -ne 1 ]; then
errorAndLog "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local path_opengnsys_base=$1
local SOURCES=( client/boot/initrd-generator \
client/boot/upgrade-clients-udeb.sh \
client/boot/udeblist.conf \
client/boot/udeblist-jaunty.conf \
client/boot/udeblist-karmic.conf \
client/boot/udeblist-lucid.conf \
server/PXE/pxelinux.cfg/default \
doc )
local TARGETS=( bin/initrd-generator \
bin/upgrade-clients-udeb.sh \
etc/udeblist.conf \
etc/udeblist-jaunty.conf \
etc/udeblist-karmic.conf \
etc/udeblist-lucid.conf \
tftpboot/pxelinux.cfg/default \
doc )
if [ ${#SOURCES[@]} != ${#TARGETS[@]} ]; then
errorAndLog "${FUNCNAME}(): inconsistent number of array items"
exit 1
fi
echoAndLog "${FUNCNAME}(): copying files to server directories"
pushd $WORKDIR/opengnsys
local i
for (( i = 0; i < ${#SOURCES[@]}; i++ )); do
if [ -f "${SOURCES[$i]}" ]; then
echoAndLog "Copying ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
cp -p "${SOURCES[$i]}" "${path_opengnsys_base}/${TARGETS[$i]}"
elif [ -d "${SOURCES[$i]}" ]; then
echoAndLog "Copying content of ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
cp -a "${SOURCES[$i]}"/* "${path_opengnsys_base}/${TARGETS[$i]}"
else
echoAndLog "Warning: Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}"
fi
done
popd
}
####################################################################
### Funciones de compilación de códifo fuente de servicios
####################################################################
# Compilar los servicios de OpenGNsys
function servicesCompilation ()
{
local hayErrores=0
# Compilar OpenGnSys Server
echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Server"
pushd $WORKDIR/opengnsys/admin/Services/ogAdmServer
make && make install
if [ $? -ne 0 ]; then
echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Server"
hayErrores=1
fi
popd
# Compilar OpenGnSys Repository Manager
echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Repository Manager"
pushd $WORKDIR/opengnsys/admin/Services/ogAdmRepo
make && make install
if [ $? -ne 0 ]; then
echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Repository Manager"
hayErrores=1
fi
popd
# Compilar OpenGnSys Client
echoAndLog "${FUNCNAME}(): Compiling OpenGnSys Admin Client"
pushd $WORKDIR/opengnsys/admin/Services/ogAdmClient
make && mv ogAdmClient ../../../client/nfsexport/bin
if [ $? -ne 0 ]; then
echoAndLog "${FUNCNAME}(): error while compiling OpenGnSys Admin Client"
hayErrores=1
fi
popd
return $hayErrores
}
####################################################################
### Funciones instalacion cliente opengnsys
####################################################################
function openGnsysClientCreate()
{
local OSDISTRIB OSCODENAME
local hayErrores=0
echoAndLog "${FUNCNAME}(): Copying OpenGnSys Client files."
cp -ar $WORKDIR/opengnsys/client/nfsexport/* $INSTALL_TARGET/client
find $INSTALL_TARGET/client -name .svn -type d -exec rm -fr {} \; 2>/dev/null
echoAndLog "${FUNCNAME}(): Copying OpenGnSys Cloning Engine files."
mkdir -p $INSTALL_TARGET/client/lib/engine/bin
cp -ar $WORKDIR/opengnsys/client/engine/*.lib $INSTALL_TARGET/client/lib/engine/bin
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while copying engine files"
hayErrores=1
fi
# Cargar Kernel, Initrd y paquetes udeb para la distribución del servidor (o por defecto).
OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
OSCODENAME=$(lsb_release -c | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
if [ "$OSDISTRIB" = "Ubuntu" -a -n "$OSCODENAME" ]; then
echoAndLog "${FUNCNAME}(): Loading Kernel and Initrd files for $OSDISTRIB $OSCODENAME."
$INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot -v "$OSCODENAME"
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
hayErrores=1
fi
echoAndLog "${FUNCNAME}(): Loading udeb files for $OSDISTRIB $OSCODENAME."
$INSTALL_TARGET/bin/upgrade-clients-udeb.sh "$OSCODENAME"
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
hayErrores=1
fi
else
echoAndLog "${FUNCNAME}(): Loading default Kernel and Initrd files."
$INSTALL_TARGET/bin/initrd-generator -t $INSTALL_TARGET/tftpboot/
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while generating initrd OpenGnSys Admin Client"
hayErrores=1
fi
echoAndLog "${FUNCNAME}(): Loading default udeb files."
$INSTALL_TARGET/bin/upgrade-clients-udeb.sh
if [ $? -ne 0 ]; then
errorAndLog "${FUNCNAME}(): error while upgrading udeb files OpenGnSys Admin Client"
hayErrores=1
fi
fi
if [ $hayErrores -eq 0 ]; then
echoAndLog "${FUNCNAME}(): Client generation success."
else
errorAndLog "${FUNCNAME}(): Client generation with errors"
fi
return $hayErrores
}
# Configuración básica de servicios de OpenGnSys
function openGnsysConfigure()
{
echoAndLog "openGnsysConfigure(): Copying init files."
cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.init /etc/init.d/opengnsys
cp -p $WORKDIR/opengnsys/admin/Services/opengnsys.default /etc/default/opengnsys
update-rc.d opengnsys defaults
echoAndLog "openGnsysConfigure(): Creating OpenGnSys config file in \"$INSTALL_TARGET/etc\"."
perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmServer.cfg
perl -pi -e "s/SERVERIP/$SERVERIP/g" $INSTALL_TARGET/etc/ogAdmRepo.cfg
echoAndLog "${FUNCNAME}(): Creating Web Console config file"
OPENGNSYS_CONSOLEURL="http://$SERVERIP/opengnsys"
perl -pi -e "s/SERVERIP/$SERVERIP/g; s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" $INSTALL_TARGET/www/controlacceso.php
sed -e "s/SERVERIP/$SERVERIP/g" -e "s/OPENGNSYSURL/${OPENGNSYS_CONSOLEURL//\//\\/}/g" $WORKDIR/opengnsys/admin/Services/ogAdmClient/ogAdmClient.cfg > $INSTALL_TARGET/client/etc/ogAdmClient.cfg
echoAndLog "openGnsysConfiguration(): Starting OpenGnSys services."
/etc/init.d/opengnsys start
}
#####################################################################
####### Función de resumen informativo de la instalación
#####################################################################
function installationSummary(){
echo
echoAndLog "OpenGnSys Installation Summary"
echo "=============================="
echoAndLog "Project version: $(cat $INSTALL_TARGET/doc/VERSION.txt 2>/dev/null)"
echoAndLog "Installation directory: $INSTALL_TARGET"
echoAndLog "Repository directory: $INSTALL_TARGET/images"
echoAndLog "TFTP configuracion directory: /var/lib/tftpboot"
echoAndLog "DHCP configuracion file: /etc/dhcp3/dhcpd.conf"
echoAndLog "NFS configuracion file: /etc/exports"
echoAndLog "Web Console URL: $OPENGNSYS_CONSOLEURL"
echoAndLog "Web Console admin user: $OPENGNSYS_DB_USER"
echoAndLog "Web Console admin password: $OPENGNSYS_DB_PASSWD"
echoAndLog "Web Console default user: $OPENGNSYS_DB_DEFAULTUSER"
echoAndLog "Web Console default password: $OPENGNSYS_DB_DEFAULTPASSWD"
echo
echoAndLog "Post-Installation Instructions:"
echo "==============================="
echoAndLog "Review or edit all configuration files."
echoAndLog "Insert DHCP configuration data and restart service."
echoAndLog "Log-in as Web Console admin user."
echoAndLog " - Review default Organization data and default user."
echoAndLog "Log-in as Web Console organization user."
echoAndLog " - Insert OpenGnSys data (rooms, computers, etc)."
echo
}
|