source: client/shared/scripts/configureOs @ 5fd45d1

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since 5fd45d1 was 5fd45d1, checked in by Irina Gómez <irinagomez@…>, 6 years ago

#802 #889 #890 Fix UEFI postconf: configureOs does not use ogFixBootSector for Windows. ogGrubInstall does not change boot order in NVRAM.

  • Property mode set to 100755
File size: 6.6 KB
Line 
1#!/bin/bash
2
3#/**
4#         configureOs
5#@brief   Script para realizar la configuracion del sistema operativo restaurado.
6#@param 1 disco
7#@param 2 particion
8#@return 
9#@TODO  comprobar que el tipo de particion corresponde con el sistema de archivos.
10#@exception OG_ERR_FORMAT     # 1 formato incorrecto.
11#@version 1.0.1 - Integracion cambio de nombre, extender fs, chequear particion activa
12#@author 
13#@date   2011-05-11
14#@version 1.0.1 - Configura el sector de la particion y el gestor de windows para iniciarse desde cualquier particion. 
15#@author Antonio J. Doblas Viso.    Universidad de Malaga.
16#@date   2011-05-20
17#@version 1.0.2 - Configura el sector de la particion y el gestor de linux para iniciarse desde cualquier particion. 
18#@author Antonio J. Doblas Viso.    Universidad de Malaga.
19#@date   2011-11-22
20#@version 1.0.3 - Configura el chkdisk en el arranque de windows, segun variable OGWINCHKDISK del engine.cfg. 
21#@author Antonio J. Doblas Viso.    Universidad de Malaga.
22#@date   2011-12-23
23#@version 1.0.4 - Inyecta el cliente para gestión del sistema operativo.
24#@author Ramon Gomez, ETSII Universidad de Sevilla
25#@date   2012-04-11
26#@version 1.0.5 - Postconfiguración para Mac OS X.
27#@author Ramon Gomez, ETSII Universidad de Sevilla
28#@date   2013-10-11
29#@version 1.1.0 - Postconfiguración para agente de sistema operativo basado en REST.
30#@author Ramon Gomez, ETSII Universidad de Sevilla
31#@date   2016-08-16
32#@version 1.0.6b - llamadas opcionales para mejoras varias. Descomentar la instruccion para su activacion. ogConfigureFstab 
33#@author Antonio J. Doblas Viso.    Universidad de Malaga.
34#@date   2016-11-03
35#@version 1.1.1 - Equipos UEFI: para Windows copia cargador de arranque a partición UEFI, para linux configura particion ESP en fstab. (ticket #802 #889 #890)
36#@author Irina Gomez, ETSII Universidad de Sevilla
37#@date   2019-01-08
38#*/ ##
39
40# Carga el configurador del engine y los parámetros de red.
41[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
42[ -f $DEVICECFG ] && source $DEVICECFG
43
44# Si el sistema de archivos no esta extendido, ampliarlo al tamaño de su partición.
45PARTSIZE=$(ogGetPartitionSize $1 $2) || exit $?
46FSSIZE=$(ogGetFsSize $1 $2)
47if [ $FSSIZE -lt $PARTSIZE ]; then
48    echo "Extender sistema de archivos."
49    ogExtendFs $1 $2
50fi
51
52# Si no existe partición activa, activar este sistema.
53FLAGACTIVE=$(ogGetPartitionActive $1)
54[ -z $FLAGACTIVE ] && ogSetPartitionActive $1 $2
55
56# Si el sistema de archivos es de solo lectura, no hacer la post-configuración.
57MNTDIR=$(ogMount $1 $2)
58if ! ogIsWritable $1 $2; then
59    echo "AVISO: sistema de archivos de solo lectura, no se ejecuta postconfiguración."
60    exit
61fi
62
63# Nombre del cliente.
64HOST="$(ogGetHostname)"
65
66# Post-configuración personalizada para cada tipo de sistema operativo.
67OSTYPE="$(ogGetOsType $1 $2)"
68case "$OSTYPE" in
69    Windows)    # Postconfiguración de Windows.
70        # Cambiar nombre en sistemas Windows.
71        HOST=${HOST:-"pc"}
72        ogSetWindowsName $1 $2 "$HOST"
73        # Si es UEFI copio el cargador de arranque a la partición EFI
74        if ogIsEfiActive; then
75            ogRestoreEfiBootLoader $1 $2
76        else
77            # Configurar el boot sector de la partición Windows.
78            ogFixBootSector $1 $2
79        fi
80        # Configurar el gestor de arranque de Windows XP/Vista/7.
81        ogWindowsBootParameters $1 $2
82        # Registrar en Windows que la partición indicada es su nueva unidad C:\
83        ogWindowsRegisterPartition $1 $2 C $1 $2
84        # Configurar nuevo agente OGAgent.
85        ogConfigureOgagent $1 $2
86        # Eliminar el antiguo cliente de Windows.
87        if [ -n "$(ogGetPath $MNTDIR/windows/ogAdmWinClient.exe)$(ogGetPath $MNTDIR/winnt/ogAdmWinClient.exe)" ]; then
88            ogInstallMiniSetup $1 $2 postconf.cmd
89            ogUninstallWindowsClient $1 $2 postconf.cmd
90        fi
91        ;;
92    Linux)      # Postconfiguración de GNU/Linux.
93        # Configuro fstab: particion de Swap y si es UEFI además la partición EFI.
94        ogConfigureFstab $1 $2
95        ## Instala (no configura) el codigo de arranque del Grub en la partición (no lo configura, se mantiene el original de la imagen)
96        ogGrubInstallPartition $1 $2
97        # Eliminar el antiguo cliente de Linux.
98        [ -n "$(find $MNTDIR/usr/sbin $MNTDIR/sbin $MNTDIR/usr/local/sbin -name ogAdmLnxClient -print)" ] && ogUninstallLinuxClient $1 $2
99        # Configurar nuevo agente OGAgent.
100        ogConfigureOgagent $1 $2
101        ;;
102    MacOS)      # Postconfiguración de Mac OS X.
103        # Fichero indicador de activación de postconfiguración.
104        touch $MNTDIR/osxpostconf
105
106        # Crear fichero de configuración del servicio de arranque.
107        cat << EOT >$MNTDIR/Library/LaunchDaemons/es.opengnsys.postconfd.plist
108<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
109<plist version="1.0">
110        <dict>
111                <key>Label</key>
112                <string>es.opengnsys.postconfd.sh</string>
113                <key>ProgramArguments</key>
114                <array>
115                        <string>/var/root/postconfd.sh</string>
116                </array>
117                <key>RunAtLoad</key>
118                <true/>
119                <key>StandardOutPath</key>
120                <string>/var/log/postconfd.log</string>
121                <key>StandardErrorPath</key>
122                <string>/var/log/postconfd.err</string>
123                <key>Debug</key>
124                <true/>
125        </dict>
126</plist>
127EOT
128
129        # Programa de inicio que será ejecutado en el arranque de Mac OS X.
130        cat << EOT >$MNTDIR/var/root/postconfd.sh
131#!/bin/bash
132# postconfd - ejecución de scripts de inicio.
133
134# Ejecutar postconfiguración si existe el fichero indicador.
135if [ -e /osxpostconf ]; then
136        # Tomar nombre del equipo.
137        HOST="$HOST"
138        if [ -z "\$HOST" ]; then
139                # Si no hay nombre asociado, activar la red para obtener datos del DHCP.
140                source /etc/rc.common
141                CheckForNetwork
142                while [ "\$NETWORKUP" != "-YES-" ]; do
143                        sleep 5
144                        NETWORKUP=
145                        CheckForNetwork
146                done
147                # Componer nombre del equipo a partir de datos del DHCP.
148                IP=\$(ifconfig en0 inet | awk '{if (\$1=="inet") print \$2}')
149                HOST="mac-\$(echo \${IP//./-} | cut -f3-4 -d-)"
150        fi
151        # Asignar nombre del equipo.
152        scutil --set ComputerName "\$HOST"
153        scutil --set LocalHostName "\$HOST"
154        scutil --set HostName "\$HOST"
155        hostname "\$HOST"
156        # Descromprimir ficheros de versión para obtener inventario de aplicaciones.
157        find /Applications -type d -name "*.app" -prune -exec \
158             ditto --nopreserveHFSCompression "{}/Contents/version.plist" "{}/Contents/version.plist.uncompress"
159        rm -f /osxpostconf    # Borrar fichero indicador de psotconfiguración
160fi
161EOT
162        # Dar permiso de ejecución.
163        chmod 700 $MNTDIR/var/root/postconfd.sh
164        # Configurar nuevo agente OGAgent de sistema operativo.
165        ogConfigureOgagent $1 $2
166        ;;
167esac
168exit 0
169
Note: See TracBrowser for help on using the repository browser.