source: client/shared/scripts/configureOs @ 7f83dcb

918-git-images-111dconfigure-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 7f83dcb 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
RevLine 
[f3850507]1#!/bin/bash
2
[7ee2d1a]3#/**
[dbe5122]4#         configureOs
[870619d]5#@brief   Script para realizar la configuracion del sistema operativo restaurado.
[7ee2d1a]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
[78b5dfe7]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
[ab82469]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
[5ccb999]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
[eedf2ce]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
[4ff56c5]26#@version 1.0.5 - Postconfiguración para Mac OS X.
27#@author Ramon Gomez, ETSII Universidad de Sevilla
28#@date   2013-10-11
[f05d952]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
[870619d]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
[20e5aa9e]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)
[30238ab]36#@author Irina Gomez, ETSII Universidad de Sevilla
37#@date   2019-01-08
[f05d952]38#*/ ##
[78b5dfe7]39
[91c9921]40# Carga el configurador del engine y los parámetros de red.
[a4cedda]41[ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg
[91c9921]42[ -f $DEVICECFG ] && source $DEVICECFG
[7ee2d1a]43
[91c9921]44# Si el sistema de archivos no esta extendido, ampliarlo al tamaño de su partición.
[7b9dedd]45PARTSIZE=$(ogGetPartitionSize $1 $2) || exit $?
[f3850507]46FSSIZE=$(ogGetFsSize $1 $2)
47if [ $FSSIZE -lt $PARTSIZE ]; then
[4ff56c5]48    echo "Extender sistema de archivos."
49    ogExtendFs $1 $2
[f3850507]50fi
51
[91c9921]52# Si no existe partición activa, activar este sistema.
[7ee2d1a]53FLAGACTIVE=$(ogGetPartitionActive $1)
54[ -z $FLAGACTIVE ] && ogSetPartitionActive $1 $2
55
[4ff56c5]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
[eedf2ce]66# Post-configuración personalizada para cada tipo de sistema operativo.
[20e5aa9e]67OSTYPE="$(ogGetOsType $1 $2)"
[eedf2ce]68case "$OSTYPE" in
[4ff56c5]69    Windows)    # Postconfiguración de Windows.
[eedf2ce]70        # Cambiar nombre en sistemas Windows.
71        HOST=${HOST:-"pc"}
72        ogSetWindowsName $1 $2 "$HOST"
[a445889]73        # Si es UEFI copio el cargador de arranque a la partición EFI e instalo Grub.
[20e5aa9e]74        if ogIsEfiActive; then
75            ogRestoreEfiBootLoader $1 $2
[a445889]76            ogGrubInstallMbr $(ogGetEsp) TRUE
[20e5aa9e]77        else
78            # Configurar el boot sector de la partición Windows.
79            ogFixBootSector $1 $2
80        fi
[eedf2ce]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
[046004d]85        # Configurar nuevo agente OGAgent.
86        ogConfigureOgagent $1 $2
[1777170]87        # Eliminar el antiguo cliente de Windows.
88        if [ -n "$(ogGetPath $MNTDIR/windows/ogAdmWinClient.exe)$(ogGetPath $MNTDIR/winnt/ogAdmWinClient.exe)" ]; then
[31eb4dd]89            ogInstallMiniSetup $1 $2 postconf.cmd
[1777170]90            ogUninstallWindowsClient $1 $2 postconf.cmd
[31eb4dd]91        fi
[eedf2ce]92        ;;
[4ff56c5]93    Linux)      # Postconfiguración de GNU/Linux.
[20e5aa9e]94        # Configuro fstab: particion de Swap y si es UEFI además la partición EFI.
[7dc06be9]95        ogConfigureFstab $1 $2
[a445889]96        # Si es UEFI instalo Grub en la partición EFI
97        ogIsEfiActive && ogGrubInstallMbr $(ogGetEsp) TRUE
[a86a15b]98        ## Instala (no configura) el codigo de arranque del Grub en la partición (no lo configura, se mantiene el original de la imagen)
[3037c80]99        ogGrubInstallPartition $1 $2
[1777170]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.
[27c67d9]103        ogConfigureOgagent $1 $2
[d7e33cb]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
[eedf2ce]108        ;;
[4ff56c5]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"
[4dea2be]166        rm -f /osxpostconf    # Borrar fichero indicador de psotconfiguración
[4ff56c5]167fi
168EOT
169        # Dar permiso de ejecución.
170        chmod 700 $MNTDIR/var/root/postconfd.sh
[27c67d9]171        # Configurar nuevo agente OGAgent de sistema operativo.
172        ogConfigureOgagent $1 $2
[4ff56c5]173        ;;
[eedf2ce]174esac
[27c67d9]175exit 0
Note: See TracBrowser for help on using the repository browser.