source: client/shared/scripts/configureOs @ 2ab002c2

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 2ab002c2 was 20e5aa9e, checked in by Irina Gómez <irinagomez@…>, 6 years ago

#802 #889 configureOs can relocale Windows in different partition. ogWindowsBootParameters: include the bootpartition to configure BCD

  • Property mode set to 100755
File size: 6.7 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            # Configurar el boot sector de la partición Windows.
77            ogFixBootSector $(ogGetEsp)
78        else
79            # Configurar el boot sector de la partición Windows.
80            ogFixBootSector $1 $2
81        fi
82        # Configurar el gestor de arranque de Windows XP/Vista/7.
83        ogWindowsBootParameters $1 $2
84        # Registrar en Windows que la partición indicada es su nueva unidad C:\
85        ogWindowsRegisterPartition $1 $2 C $1 $2
86        # Configurar nuevo agente OGAgent.
87        ogConfigureOgagent $1 $2
88        # Eliminar el antiguo cliente de Windows.
89        if [ -n "$(ogGetPath $MNTDIR/windows/ogAdmWinClient.exe)$(ogGetPath $MNTDIR/winnt/ogAdmWinClient.exe)" ]; then
90            ogInstallMiniSetup $1 $2 postconf.cmd
91            ogUninstallWindowsClient $1 $2 postconf.cmd
92        fi
93        ;;
94    Linux)      # Postconfiguración de GNU/Linux.
95        # Configuro fstab: particion de Swap y si es UEFI además la partición EFI.
96        ogConfigureFstab $1 $2
97        ## Instala (no configura) el codigo de arranque del Grub en la partición (no lo configura, se mantiene el original de la imagen)
98        ogGrubInstallPartition $1 $2
99        # Eliminar el antiguo cliente de Linux.
100        [ -n "$(find $MNTDIR/usr/sbin $MNTDIR/sbin $MNTDIR/usr/local/sbin -name ogAdmLnxClient -print)" ] && ogUninstallLinuxClient $1 $2
101        # Configurar nuevo agente OGAgent.
102        ogConfigureOgagent $1 $2
103        ;;
104    MacOS)      # Postconfiguración de Mac OS X.
105        # Fichero indicador de activación de postconfiguración.
106        touch $MNTDIR/osxpostconf
107
108        # Crear fichero de configuración del servicio de arranque.
109        cat << EOT >$MNTDIR/Library/LaunchDaemons/es.opengnsys.postconfd.plist
110<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
111<plist version="1.0">
112        <dict>
113                <key>Label</key>
114                <string>es.opengnsys.postconfd.sh</string>
115                <key>ProgramArguments</key>
116                <array>
117                        <string>/var/root/postconfd.sh</string>
118                </array>
119                <key>RunAtLoad</key>
120                <true/>
121                <key>StandardOutPath</key>
122                <string>/var/log/postconfd.log</string>
123                <key>StandardErrorPath</key>
124                <string>/var/log/postconfd.err</string>
125                <key>Debug</key>
126                <true/>
127        </dict>
128</plist>
129EOT
130
131        # Programa de inicio que será ejecutado en el arranque de Mac OS X.
132        cat << EOT >$MNTDIR/var/root/postconfd.sh
133#!/bin/bash
134# postconfd - ejecución de scripts de inicio.
135
136# Ejecutar postconfiguración si existe el fichero indicador.
137if [ -e /osxpostconf ]; then
138        # Tomar nombre del equipo.
139        HOST="$HOST"
140        if [ -z "\$HOST" ]; then
141                # Si no hay nombre asociado, activar la red para obtener datos del DHCP.
142                source /etc/rc.common
143                CheckForNetwork
144                while [ "\$NETWORKUP" != "-YES-" ]; do
145                        sleep 5
146                        NETWORKUP=
147                        CheckForNetwork
148                done
149                # Componer nombre del equipo a partir de datos del DHCP.
150                IP=\$(ifconfig en0 inet | awk '{if (\$1=="inet") print \$2}')
151                HOST="mac-\$(echo \${IP//./-} | cut -f3-4 -d-)"
152        fi
153        # Asignar nombre del equipo.
154        scutil --set ComputerName "\$HOST"
155        scutil --set LocalHostName "\$HOST"
156        scutil --set HostName "\$HOST"
157        hostname "\$HOST"
158        # Descromprimir ficheros de versión para obtener inventario de aplicaciones.
159        find /Applications -type d -name "*.app" -prune -exec \
160             ditto --nopreserveHFSCompression "{}/Contents/version.plist" "{}/Contents/version.plist.uncompress"
161        rm -f /osxpostconf    # Borrar fichero indicador de psotconfiguración
162fi
163EOT
164        # Dar permiso de ejecución.
165        chmod 700 $MNTDIR/var/root/postconfd.sh
166        # Configurar nuevo agente OGAgent de sistema operativo.
167        ogConfigureOgagent $1 $2
168        ;;
169esac
170exit 0
171
Note: See TracBrowser for help on using the repository browser.