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

Last change on this file since 5d05b06 was a445889, checked in by Irina Gómez <irinagomez@…>, 5 years ago

#802 #888 On UEFI computers, OpenGnsys installs grub to boot from the hard drive. You can use the rEFInd template example for computers without SecureBoot?.

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