[dcddace] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | # bootOsCustom |
---|
| 4 | #@brief Plantilla para script de configuración personalizada de sistema operativo restaurado. |
---|
| 5 | #@param $1 nº de disco |
---|
| 6 | #@param $2 nº de partición |
---|
| 7 | #@warning Renombrar este fichero como "bootOsCustom" para personalizar el script estándar "bootOs". |
---|
[6963f42] | 8 | #@note La partición a inicializar debe estar montada |
---|
[b96fd67] | 9 | #@version 1.1.1 Soporta varios discos |
---|
| 10 | #@date 2019/08/26 |
---|
[dcddace] | 11 | #**/ |
---|
[b96fd67] | 12 | # CONFIGURAR: Partición de datos de Windows que no queremos ocultar (valor por defecto '0' no oculta nada) |
---|
| 13 | DISKDATA=0 |
---|
[dcddace] | 14 | PARTDATA=0 |
---|
| 15 | |
---|
| 16 | PROG="$(basename $0)" |
---|
[6963f42] | 17 | # Control de errores |
---|
[dcddace] | 18 | if [ $# -lt 2 ]; then |
---|
| 19 | ogRaiseError $OG_ERR_FORMAT "Formato: $PROG ndisco nparticion" |
---|
| 20 | exit $? |
---|
| 21 | fi |
---|
| 22 | |
---|
[6963f42] | 23 | # Parámetros obligatorios. |
---|
| 24 | DISK="$1" # Nº de disco. |
---|
| 25 | PART="$2" # Nº de partición. |
---|
| 26 | |
---|
| 27 | # Paso 0: Añadir código para realizar control de errores de los parámetros de entrada (recomendado). |
---|
[b96fd67] | 28 | DEVICE=$(ogDiskToDev "$DISK" "$PART") || exit $? |
---|
[6963f42] | 29 | |
---|
[b96fd67] | 30 | # Paso 1: Adaptar el código de ejemplo para arranque personalizado. |
---|
[6963f42] | 31 | # Nota: el script "bootOs" llama al script "bootOsCustom" después de realizar la operaciones de inicio estándar y antes de desmontar las particiones e iniciar el sistema operativo. |
---|
| 32 | |
---|
| 33 | |
---|
[b96fd67] | 34 | MNTDIR=$(ogMount $DISK $PART) || exit $? |
---|
[c436360] | 35 | NAME="$(ogGetHostname)" |
---|
| 36 | NAME=${NAME:-"pc"} |
---|
[6963f42] | 37 | OSTYPE=$(ogGetOsType $DISK $PART) |
---|
[c436360] | 38 | |
---|
[dcddace] | 39 | case "$OSTYPE" in |
---|
| 40 | Windows) |
---|
[c436360] | 41 | ## Mostrar las particiones NTFS de sistema (dos opciones) |
---|
| 42 | ## Opción 1: SIN ocultar las demás. |
---|
[b96fd67] | 43 | #ogEcho log session "[40] Mostrar y activar particion de Windows $PART." |
---|
| 44 | #[ $(ogGetPartitionType $DISK $PART) == "HNTFS" -o $(ogGetPartitionType $DISK $PART) == "WIN-RESERV" ] && ogUnhidePartition $DISK $PART |
---|
| 45 | |
---|
| 46 | ## Recorremos los distintos discos |
---|
| 47 | #for DEVICE in $(ogDiskToDev); do |
---|
| 48 | # d=$(ogDevToDisk $DEVICE) |
---|
[c436360] | 49 | |
---|
[b96fd67] | 50 | # ## Mostrar las particiones NTFS de sistema (dos opciones) |
---|
| 51 | # ## Opción 2: Ocultamos las demás. |
---|
| 52 | # ogEcho log session "[40] Activar particion de Windows $PART y ocultar las demás." |
---|
| 53 | # for (( i=1; i<=$(ogGetPartitionsNumber $d); i++ )); do |
---|
| 54 | # if [ $d == $DISK -a $i == $PART ] || [ $d == $DISKDATA -a $i == $PARTDATA ]; then |
---|
| 55 | # [ $(ogGetPartitionType $d $i) == "HNTFS" -o $(ogGetPartitionType $d $i) == "WIN-RESERV" ] && ogUnhidePartition $d $i |
---|
[6963f42] | 56 | # else |
---|
[b96fd67] | 57 | # [ "$(ogGetPartitionType $d $i)" == NTFS -o "$(ogGetPartitionType $d $i)" == "WINDOWS" ] && ogHidePartition $d $i |
---|
[6963f42] | 58 | # fi |
---|
[b96fd67] | 59 | # done |
---|
| 60 | |
---|
| 61 | # ## Borrar marcas de arrranque de todos los Windows instalados en el disco. |
---|
| 62 | # ogEcho log session "[30] Borrar marcas de arrranque de todos los Windows instalados en el disco." |
---|
| 63 | # for (( i=1; i<=$(ogGetPartitionsNumber $d); i++ )); do |
---|
| 64 | # [ "$(ogGetOsType $d $i)" == "Windows" ] && ogMount $d $i &>/dev/null |
---|
| 65 | # done |
---|
| 66 | # rm -f /mnt/*/ogboot.* |
---|
| 67 | |
---|
[6963f42] | 68 | #done |
---|
[dcddace] | 69 | ;; |
---|
| 70 | Linux) |
---|
[c436360] | 71 | ## Modificar el nombre del equipo |
---|
[b96fd67] | 72 | #ogEcho log session "[30] Asignar nombre Linux \"$NAME\"." |
---|
| 73 | #ETC=$(ogGetPath $DISK $PART /etc) |
---|
[c436360] | 74 | #[ -d "$ETC" ] && echo "$NAME" >$ETC/hostname 2>/dev/null |
---|
| 75 | |
---|
| 76 | ## Sustituir UUID o LABEL por su dispositivo en definición de sistema de archivo raíz. |
---|
| 77 | #if [ -f "$ETC/fstab" ]; then |
---|
[b96fd67] | 78 | # ogEcho log session "[40] Actualizar fstab con particion raíz \"$PART\"." |
---|
[c436360] | 79 | # awk -v P="$PART " '{ if ($2=="/" && $1!~/^#/) {sub(/^.*$/, P, $1)} |
---|
| 80 | # print }' $ETC/fstab >/tmp/fstab |
---|
| 81 | # mv /tmp/fstab $ETC/fstab |
---|
| 82 | #fi |
---|
| 83 | |
---|
[6963f42] | 84 | ## Cambiar claves usuarios, copiando fichero /etc/passwd |
---|
| 85 | ## En el servidor el nuevo fichero debe situarse en el directorio del grupo: |
---|
| 86 | ## /opt/opengnsys/images/groups/nombre_aula |
---|
| 87 | #if [ -r $(ogGetGroupDir)/passwd ]; then |
---|
[b96fd67] | 88 | # ogEcho log session "[65] Cambiar claves de usuarios." |
---|
[6963f42] | 89 | # cp $(ogGetGroupDir)/passwd $MNTDIR/etc |
---|
| 90 | #fi |
---|
[dcddace] | 91 | ;; |
---|
| 92 | esac |
---|