[b094c59] | 1 | #!/bin/bash |
---|
| 2 | #/** |
---|
| 3 | #@file Boot.lib |
---|
| 4 | #@brief Librería o clase Boot |
---|
| 5 | #@class Boot |
---|
| 6 | #@brief Funciones para arranque y post-configuración de sistemas de archivos. |
---|
| 7 | #@version 0.9 |
---|
| 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | #/** |
---|
| 13 | # ogBoot int_ndisk int_npartition |
---|
| 14 | #@brief Inicia el proceso de arranque de un sistema de archivos. |
---|
[42669ebf] | 15 | #@param int_ndisk nº de orden del disco |
---|
| 16 | #@param int_npartition nº de orden de la partición |
---|
[b094c59] | 17 | #@return (activar el sistema de archivos). |
---|
| 18 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 19 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 20 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 21 | #@exception OG_ERR_NOTOS La partición no tiene instalado un sistema operativo. |
---|
[f5432db7] | 22 | #@note En Linux, debe arrancarse la partición del directorio \c /boot |
---|
[985bef0] | 23 | #@version 0.1 - Integracion para OpenGNSys. - EAC: HDboot(); BootLinuxEX() en Boot.lib |
---|
| 24 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
[e05993a] | 25 | #@date 2008-10-27 |
---|
[985bef0] | 26 | #@version 0.9 - Adaptacion para OpenGNSys. |
---|
[b094c59] | 27 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 28 | #@date 2009-09-11 |
---|
[1e7eaab] | 29 | #*/ ## |
---|
[42669ebf] | 30 | function ogBoot () |
---|
| 31 | { |
---|
[b094c59] | 32 | # Variables locales. |
---|
[326cec3] | 33 | local PART TYPE MNTDIR PARAMS KERNEL INITRD APPEND FILE LOADER |
---|
[b094c59] | 34 | |
---|
[1e7eaab] | 35 | # Si se solicita, mostrar ayuda. |
---|
[b094c59] | 36 | if [ "$*" == "help" ]; then |
---|
| 37 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 38 | "$FUNCNAME 1 1" |
---|
| 39 | return |
---|
| 40 | fi |
---|
[1e7eaab] | 41 | # Error si no se reciben 2 parámetros. |
---|
[b094c59] | 42 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 43 | |
---|
[1e7eaab] | 44 | # Detectar tipo de sistema de archivos y montarlo. |
---|
[049eadbe] | 45 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
[b094c59] | 46 | TYPE=$(ogGetFsType $1 $2) || return $? |
---|
[f5432db7] | 47 | MNTDIR=$(ogMount $1 $2) 2>/dev/null |
---|
| 48 | [ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $? |
---|
[b094c59] | 49 | |
---|
| 50 | case "$TYPE" in |
---|
[049eadbe] | 51 | EXT[234]|REISERFS|REISER4|JFS|XFS) |
---|
[1e7eaab] | 52 | # Obtiene los parámetros de arranque para Linux. |
---|
[f5432db7] | 53 | PARAMS=$(ogLinuxBootParameters $1 $2) || return $? |
---|
| 54 | read -e KERNEL INITRD APPEND <<<"$PARAMS" |
---|
[1e7eaab] | 55 | # Si no hay kernel, no hay sistema operativo. |
---|
[f5432db7] | 56 | [ -z "$KERNEL" ] && ogRaiseError $OG_ERR_NOTOS && return $? |
---|
[1e7eaab] | 57 | # Arrancar de partición distinta a la original. |
---|
[049eadbe] | 58 | [ -e "$MNTDIR/etc" ] && APPEND=$(echo $APPEND | awk -v P="$PART " '{sub (/root=[-+=_/a-zA-Z0-9]* /,"root="P);print}') |
---|
[f5432db7] | 59 | # Configurar kernel Linux con los parámetros leídos de su GRUB. |
---|
[049eadbe] | 60 | kexec -l "${MNTDIR}${KERNEL}" --append="$APPEND" --initrd="${MNTDIR}${INITRD}" |
---|
[f5432db7] | 61 | ;; |
---|
| 62 | NTFS|HNTFS|FAT32|HFAT32) |
---|
[1e7eaab] | 63 | # Compruebar si hay un cargador de Windows. |
---|
[f5432db7] | 64 | for f in io.sys ntldr bootmgr; do |
---|
| 65 | FILE="$(ogGetPath $1 $2 $f 2>/dev/null)" |
---|
[d10549b] | 66 | [ -n "$FILE" ] && LOADER="$f" |
---|
[f5432db7] | 67 | done |
---|
| 68 | [ -z "$LOADER" ] && ogRaiseError $OG_ERR_NOTOS && return $? |
---|
| 69 | # Activar la partición y copiar Grub4DOS. |
---|
| 70 | ogSetPartitionActive $1 $2 |
---|
[d712f58] | 71 | #FIXME: activar seguimiento inicio sesion XP con grub4dos |
---|
[78b5dfe7] | 72 | #if `ogGetOsVersion $1 $2 | grep "XP" > /dev/null` |
---|
[d712f58] | 73 | #then |
---|
| 74 | # dd if=/dev/zero of=${MNTDIR}/ogboot.me bs=1024 count=3 |
---|
| 75 | # dd if=/dev/zero of=${MNTDIR}/ogboot.firstboot bs=1024 count=3 |
---|
| 76 | # dd if=/dev/zero of=${MNTDIR}/ogboot.secondboot bs=1024 count=3 |
---|
| 77 | # ogLoadHiveWindows $1 $2 |
---|
| 78 | # ogHiveNTRunMachine "cmd /c del c:\ogboot.* " ogcleanboot |
---|
| 79 | # ogUpdateHiveWindows |
---|
| 80 | # reboot |
---|
| 81 | #else |
---|
| 82 | cp $OGLIB/grub4dos/* $MNTDIR # */ (Comentario Doxygen) |
---|
| 83 | ##kexec -l $MNTDIR/grub.exe --append=--config-file="find --set-root /$LOADER; chainloader /$LOADER; tpm --init" |
---|
| 84 | kexec -l $MNTDIR/grub.exe --append=--config-file="root (hd$[$1-1],$[$2-1]); chainloader (hd$[$1-1],$[$2-1])/$LOADER; tpm --init" |
---|
| 85 | #fi |
---|
[f5432db7] | 86 | ;; |
---|
| 87 | *) ogRaiseError $OG_ERR_PARTITION "$1, $2" |
---|
[326cec3] | 88 | return $? |
---|
[f5432db7] | 89 | ;; |
---|
[b094c59] | 90 | esac |
---|
| 91 | |
---|
[1e7eaab] | 92 | # Arrancar. |
---|
[b094c59] | 93 | kexec -e |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | #/** |
---|
[3e1561d] | 98 | # ogGetRegistryValue path_mountpoint str_registrytype str_valuename |
---|
| 99 | #@brief Devuelve el dato de un valor del registro de Windows. |
---|
[42669ebf] | 100 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
| 101 | #@param str_registrytype tipo de registro a leer |
---|
| 102 | #@param str_valuename valor de registro |
---|
[3e1561d] | 103 | #@return str_valuedata - valor de la clave. |
---|
[055adcf] | 104 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
[f5432db7] | 105 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo. |
---|
[055adcf] | 106 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 107 | #@note registrytype = { default, sam, security, software, system, components } |
---|
| 108 | #@warning Requisitos: chntpw, awk |
---|
| 109 | #@warning La partición de Windows debe estar montada previamente. |
---|
[f5432db7] | 110 | #@version 0.9 - Adaptación para OpenGNSys. |
---|
[055adcf] | 111 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 112 | #@date 2009-09-11 |
---|
[1e7eaab] | 113 | #*/ ## |
---|
[42669ebf] | 114 | function ogGetRegistryValue () |
---|
| 115 | { |
---|
[055adcf] | 116 | # Variables locales. |
---|
[50a094c] | 117 | local FILE FILENT FILEXP |
---|
[055adcf] | 118 | |
---|
[1e7eaab] | 119 | # Si se solicita, mostrar ayuda. |
---|
[055adcf] | 120 | if [ "$*" == "help" ]; then |
---|
| 121 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key" |
---|
| 122 | return |
---|
| 123 | fi |
---|
[1e7eaab] | 124 | # Error si no se reciben 3 parámetros. |
---|
[055adcf] | 125 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 126 | |
---|
[1e7eaab] | 127 | # Camino del fichero de registro en NT/2000 o XP/Vista/7. |
---|
[055adcf] | 128 | FILENT=$(ogGetPath "/$1/winnt/system32/config/$2") |
---|
[945b003] | 129 | [ -f $FILENT ] && FILE="$FILENT" |
---|
[055adcf] | 130 | FILEXP=$(ogGetPath "/$1/windows/system32/config/$2") |
---|
[945b003] | 131 | [ -f $FLEHXP ] && FILE="$FILEXP" |
---|
[055adcf] | 132 | [ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $? |
---|
| 133 | |
---|
[1e7eaab] | 134 | # Devolver el dato del valor de registro. |
---|
| 135 | # /* (comentario Doxygen) |
---|
[055adcf] | 136 | chntpw $FILE << FIN 2>/dev/null | awk '/> Value/ {getline;print $0;}' |
---|
| 137 | cd ${3%\\*} |
---|
| 138 | cat ${3##*\\} |
---|
| 139 | q |
---|
| 140 | FIN |
---|
[42669ebf] | 141 | # (comentario Doxygen) */ |
---|
[055adcf] | 142 | } |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | #/** |
---|
[3e1561d] | 146 | # ogGetWindowsName int_ndisk int_npartition |
---|
| 147 | #@brief Muestra el nombre del equipo en el registro de Windows. |
---|
[42669ebf] | 148 | #@param int_ndisk nº de orden del disco |
---|
| 149 | #@param int_npartition nº de orden de la partición |
---|
[3e1561d] | 150 | #@return str_name - nombre del equipo |
---|
| 151 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 152 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 153 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
[f5432db7] | 154 | #@version 0.9 - Adaptación para OpenGNSys. |
---|
[3e1561d] | 155 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 156 | #@date 2009-09-23 |
---|
[1e7eaab] | 157 | #*/ ## |
---|
[42669ebf] | 158 | function ogGetWindowsName () |
---|
| 159 | { |
---|
[3e1561d] | 160 | # Variables locales. |
---|
| 161 | local PART MNTDIR |
---|
| 162 | |
---|
[1e7eaab] | 163 | # Si se solicita, mostrar ayuda. |
---|
[3e1561d] | 164 | if [ "$*" == "help" ]; then |
---|
| 165 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 166 | "$FUNCNAME 1 1 ==> PRACTICA-PC" |
---|
| 167 | return |
---|
| 168 | fi |
---|
[1e7eaab] | 169 | # Error si no se reciben 2 parámetros. |
---|
[3e1561d] | 170 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 171 | |
---|
[1e7eaab] | 172 | # Montar el sistema de archivos. |
---|
[f5432db7] | 173 | MNTDIR=$(ogMount $1 $2) 2>/dev/null |
---|
| 174 | [ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $? |
---|
[3e1561d] | 175 | |
---|
[1e7eaab] | 176 | # Obtener dato del valor de registro. |
---|
[3e1561d] | 177 | ogGetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | #/** |
---|
[50a094c] | 182 | # ogListRegistryKeys path_mountpoint str_registrytype str_key |
---|
[3e1561d] | 183 | #@brief Lista los nombres de claves de una determinada clave del registro de Windows. |
---|
[42669ebf] | 184 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
| 185 | #@param str_registrytype tipo de registro a leer |
---|
| 186 | #@param str_key clave de registro |
---|
| 187 | #@return str_key ... - lista de claves de registro |
---|
[50a094c] | 188 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 189 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 190 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 191 | #@note registrytype = { default, sam, security, software, system, components } |
---|
| 192 | #@warning Requisitos: chntpw, awk |
---|
| 193 | #@warning La partición de Windows debe estar montada previamente. |
---|
[f5432db7] | 194 | #@version 0.9 - Adaptación para OpenGNSys. |
---|
[50a094c] | 195 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 196 | #@date 2009-09-23 |
---|
[1e7eaab] | 197 | #*/ ## |
---|
[42669ebf] | 198 | function ogListRegistryKeys () |
---|
| 199 | { |
---|
[50a094c] | 200 | # Variables locales. |
---|
| 201 | local FILE FILENT FILEXP |
---|
| 202 | |
---|
[1e7eaab] | 203 | # Si se solicita, mostrar ayuda. |
---|
[50a094c] | 204 | if [ "$*" == "help" ]; then |
---|
| 205 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key" |
---|
| 206 | return |
---|
| 207 | fi |
---|
[1e7eaab] | 208 | # Error si no se reciben 3 parámetros. |
---|
[50a094c] | 209 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 210 | |
---|
[1e7eaab] | 211 | # Camino del fichero de registro en NT/2000 o XP/Vista/7. |
---|
[50a094c] | 212 | FILENT=$(ogGetPath "/$1/winnt/system32/config/$2") |
---|
[945b003] | 213 | [ -f $FILENT ] && FILE="$FILENT" |
---|
[50a094c] | 214 | FILEXP=$(ogGetPath "/$1/windows/system32/config/$2") |
---|
[945b003] | 215 | [ -f $FLEHXP ] && FILE="$FILEXP" |
---|
[50a094c] | 216 | [ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $? |
---|
| 217 | |
---|
[1e7eaab] | 218 | # Devolver la lista de claves de registro. |
---|
[50a094c] | 219 | chntpw $FILE << FIN 2>/dev/null | awk 'BEGIN {FS="[<>]"} $1~/^ $/ {print $2}' |
---|
| 220 | ls $3 |
---|
| 221 | q |
---|
| 222 | FIN |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | #/** |
---|
[4c63eb9] | 227 | # ogLinuxBootParameters int_ndisk int_npartition |
---|
[b094c59] | 228 | #@brief Muestra los parámetros de arranque de un sistema de archivos Linux. |
---|
[42669ebf] | 229 | #@param int_ndisk nº de orden del disco |
---|
| 230 | #@param int_npartition nº de orden de la partición |
---|
| 231 | #@return str_kernel str_initrd str_parameters ... |
---|
[b094c59] | 232 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 233 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 234 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
[055adcf] | 235 | #@warning Función básica usada por \c ogBoot |
---|
| 236 | #@version 0.9 - Primera adaptación para OpenGNSys. |
---|
[b094c59] | 237 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 238 | #@date 2009-09-11 |
---|
[199bdf3] | 239 | #@version 0.9.2 - Soporta partición /boot independiente. |
---|
| 240 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 241 | #@date 2010-07-20 |
---|
[1e7eaab] | 242 | #*/ ## |
---|
[42669ebf] | 243 | function ogLinuxBootParameters () |
---|
| 244 | { |
---|
[b094c59] | 245 | # Variables locales. |
---|
[199bdf3] | 246 | local MNTDIR CONFDIR CONFFILE |
---|
[b094c59] | 247 | |
---|
[1e7eaab] | 248 | # Si se solicita, mostrar ayuda. |
---|
[b094c59] | 249 | if [ "$*" == "help" ]; then |
---|
| 250 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 251 | "$FUNCNAME 1 2 ==> ..." |
---|
| 252 | return |
---|
| 253 | fi |
---|
[1e7eaab] | 254 | # Error si no se reciben 2 parámetros. |
---|
[b094c59] | 255 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 256 | |
---|
[1e7eaab] | 257 | # Detectar id. de tipo de partición y codificar al mnemonico. |
---|
[f5432db7] | 258 | MNTDIR=$(ogMount $1 $2) 2>/dev/null |
---|
| 259 | [ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $? |
---|
[b094c59] | 260 | |
---|
| 261 | # Fichero de configuración de GRUB. |
---|
[199bdf3] | 262 | CONFDIR=$MNTDIR # Partición de arranque /boot. |
---|
| 263 | [ -d $MNTDIR/boot ] && CONFDIR=$MNTDIR/boot # Partición raíz con directorio boot. |
---|
| 264 | CONFFILE="$CONFDIR/grub/menu.lst" |
---|
| 265 | [ ! -e $CONFFILE ] && CONFFILE="$CONFDIR/grub/grub.cfg" |
---|
| 266 | [ ! -e $CONFFILE ] && ogRaiseError $OG_ERR_NOTFOUND "grub.cfg" && return $? |
---|
[b094c59] | 267 | |
---|
[1e7eaab] | 268 | # Toma del fichero de configuracion los valores del kernel, initrd |
---|
[ee4a96e] | 269 | # y parámetros de arranque usando las cláusulas por defecto |
---|
| 270 | # ("default" en GRUB1, "set default" en GRUB2) |
---|
| 271 | # y los formatea para que sean compatibles con \c kexec . */ |
---|
[1e7eaab] | 272 | # /* (comentario Doxygen) |
---|
[b094c59] | 273 | awk 'BEGIN {cont=-1;} |
---|
| 274 | $1~/^default/ {sub(/=/," "); def=$2;} |
---|
[18f4bc2] | 275 | $1~/^set/ && $2~/^default/ {gsub(/[="]/," "); def=$3;} |
---|
[ee4a96e] | 276 | $1~/^title|^menuentry/ {cont++} |
---|
| 277 | $1~/^kernel|^linux/ {if (def==cont) { |
---|
[b094c59] | 278 | kern=$2; |
---|
[1e7eaab] | 279 | sub($1,"");sub($1,"");sub(/^[ \t]*/,"");app=$0} # /* (comentario Doxygen) |
---|
[b094c59] | 280 | } |
---|
| 281 | $1~/^initrd/ {if (def==cont) init=$2} |
---|
| 282 | END {if (kern!="") printf("%s %s %s", kern,init,app)} |
---|
[199bdf3] | 283 | ' $CONFFILE |
---|
[1e7eaab] | 284 | # */ (comentario Doxygen) |
---|
[b094c59] | 285 | } |
---|
| 286 | |
---|
[3e1561d] | 287 | |
---|
| 288 | |
---|
| 289 | #/** |
---|
| 290 | # ogSetRegistryValue path_mountpoint str_registrytype str_valuename str_valuedata |
---|
| 291 | #@brief Establece el dato asociado a un valor del registro de Windows. |
---|
[42669ebf] | 292 | #@param path_mountpoint directorio donde está montado el sistema Windows |
---|
| 293 | #@param str_registrytype tipo de registro |
---|
| 294 | #@param str_valuename nombre del valor de registro |
---|
| 295 | #@param str_valuedata dato del valor de registro |
---|
[3e1561d] | 296 | #@return (nada) |
---|
| 297 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
[f5432db7] | 298 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo. |
---|
[3e1561d] | 299 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 300 | #@note registrytype = { default, sam, security, software, system, components } |
---|
| 301 | #@warning Requisitos: chntpw, awk |
---|
| 302 | #@warning La partición de Windows debe estar montada previamente. |
---|
[f5432db7] | 303 | #@version 0.9 - Adaptación para OpenGNSys. |
---|
[3e1561d] | 304 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 305 | #@date 2009-09-24 |
---|
[1e7eaab] | 306 | #*/ ## |
---|
[42669ebf] | 307 | function ogSetRegistryValue () |
---|
| 308 | { |
---|
[3e1561d] | 309 | # Variables locales. |
---|
| 310 | local FILE FILENT FILEXP |
---|
| 311 | |
---|
[42669ebf] | 312 | # Si se solicita, mostrar ayuda. |
---|
[3e1561d] | 313 | if [ "$*" == "help" ]; then |
---|
| 314 | ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_registrytype str_key" |
---|
| 315 | return |
---|
| 316 | fi |
---|
[42669ebf] | 317 | # Error si no se reciben 4 parámetros. |
---|
[3e1561d] | 318 | [ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 319 | |
---|
[42669ebf] | 320 | # Camino del fichero de registro en NT/2000 o XP/Vista/7. |
---|
[3e1561d] | 321 | FILENT=$(ogGetPath "/$1/winnt/system32/config/$2") |
---|
[945b003] | 322 | [ -f $FILENT ] && FILE="$FILENT" |
---|
[3e1561d] | 323 | FILEXP=$(ogGetPath "/$1/windows/system32/config/$2") |
---|
[945b003] | 324 | [ -f $FLEHXP ] && FILE="$FILEXP" |
---|
[3e1561d] | 325 | [ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $? |
---|
| 326 | |
---|
[42669ebf] | 327 | # Cambiar el dato del valor de registro. |
---|
[f5432db7] | 328 | chntpw $FILE << FIN &>/dev/null |
---|
[3e1561d] | 329 | ed $3 |
---|
| 330 | $4 |
---|
| 331 | q |
---|
| 332 | y |
---|
| 333 | FIN |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | #/** |
---|
| 338 | # ogSetWindowsName int_ndisk int_npartition str_name |
---|
| 339 | #@brief Establece el nombre del equipo en el registro de Windows. |
---|
[42669ebf] | 340 | #@param int_ndisk nº de orden del disco |
---|
| 341 | #@param int_npartition nº de orden de la partición |
---|
| 342 | #@param str_name nombre asignado |
---|
[3e1561d] | 343 | #@return (nada) |
---|
| 344 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 345 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 346 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
[f5432db7] | 347 | #@version 0.9 - Adaptación a OpenGNSys. |
---|
[3e1561d] | 348 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 349 | #@date 2009-09-24 |
---|
[1e7eaab] | 350 | #*/ ## |
---|
[42669ebf] | 351 | function ogSetWindowsName () |
---|
| 352 | { |
---|
[3e1561d] | 353 | # Variables locales. |
---|
| 354 | local PART MNTDIR NAME |
---|
| 355 | |
---|
[1e7eaab] | 356 | # Si se solicita, mostrar ayuda. |
---|
[3e1561d] | 357 | if [ "$*" == "help" ]; then |
---|
[4b9cdda] | 358 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_name" \ |
---|
[3e1561d] | 359 | "$FUNCNAME 1 1 PRACTICA-PC" |
---|
| 360 | return |
---|
| 361 | fi |
---|
[1e7eaab] | 362 | # Error si no se reciben 3 parámetros. |
---|
[3e1561d] | 363 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 364 | |
---|
[42669ebf] | 365 | # Montar el sistema de archivos. |
---|
[f5432db7] | 366 | MNTDIR=$(ogMount $1 $2) 2>/dev/null |
---|
| 367 | [ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $? |
---|
[3e1561d] | 368 | NAME="$3" |
---|
| 369 | |
---|
[1e7eaab] | 370 | # Modificar datos de los valores de registro. |
---|
[4b9cdda] | 371 | ogSetRegistryValue $MNTDIR system '\ControlSet001\Control\ComputerName\ComputerName\ComputerName' "$NAME" 2>/dev/null |
---|
| 372 | ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null |
---|
| 373 | ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\Hostname' "$NAME" 2>/dev/null |
---|
| 374 | ogSetRegistryValue $MNTDIR system '\ControlSet001\Services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null |
---|
| 375 | ogSetRegistryValue $MNTDIR system '\ControlSet001\services\Tcpip\Parameters\NV Hostname' "$NAME" 2>/dev/null |
---|
[3e1561d] | 376 | } |
---|
| 377 | |
---|
[f5432db7] | 378 | |
---|
[4b9cdda] | 379 | #/** |
---|
| 380 | # ogSetWinlogonUser int_ndisk int_npartition str_username |
---|
| 381 | #@brief Establece el nombre de usuario por defecto en la entrada de Windows. |
---|
| 382 | #@param int_ndisk nº de orden del disco |
---|
| 383 | #@param int_npartition nº de orden de la partición |
---|
| 384 | #@param str_username nombre de usuario por defecto |
---|
| 385 | #@return (nada) |
---|
| 386 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 387 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 388 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 389 | #@version 0.9.2 - Adaptación a OpenGNSys. |
---|
| 390 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 391 | #@date 2010-07-20 |
---|
| 392 | #*/ ## |
---|
| 393 | function ogSetWinlogonUser () |
---|
| 394 | { |
---|
| 395 | # Variables locales. |
---|
| 396 | local PART MNTDIR NAME |
---|
| 397 | |
---|
| 398 | # Si se solicita, mostrar ayuda. |
---|
| 399 | if [ "$*" == "help" ]; then |
---|
| 400 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_username" \ |
---|
| 401 | "$FUNCNAME 1 1 USUARIO" |
---|
| 402 | return |
---|
| 403 | fi |
---|
| 404 | # Error si no se reciben 3 parámetros. |
---|
| 405 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 406 | |
---|
| 407 | # Montar el sistema de archivos. |
---|
| 408 | MNTDIR=$(ogMount $1 $2) 2>/dev/null |
---|
| 409 | [ -z "$MNTDIR" ] && ogRaiseError OG_ERR_PARTITION "$1, $2" && return $? |
---|
| 410 | NAME="$3" |
---|
| 411 | |
---|
| 412 | # Modificar datos en el registro. |
---|
| 413 | ogSetRegistryValue $MNTDIR SOFTWARE '\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName' "$3" |
---|
| 414 | } |
---|
| 415 | |
---|
[38231e9] | 416 | |
---|
| 417 | #/** |
---|
| 418 | # ogNewMbrXP int_ndisk |
---|
| 419 | #@brief Genera un nuevo Master Boot Record en el disco duro indicado, compatible con los SO tipo Windows |
---|
[42669ebf] | 420 | #@param int_ndisk nº de orden del disco |
---|
[945b003] | 421 | #@return salida del programa my-sys |
---|
[38231e9] | 422 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 423 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 424 | #@version 0.9 - Adaptación a OpenGNSys. |
---|
| 425 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 426 | #@date 2009-09-24 |
---|
| 427 | #*/ ## |
---|
| 428 | |
---|
[e05993a] | 429 | function ogNewMbrXP () |
---|
| 430 | { |
---|
[38231e9] | 431 | # Variables locales. |
---|
| 432 | local PART |
---|
| 433 | |
---|
| 434 | # Si se solicita, mostrar ayuda. |
---|
| 435 | if [ "$*" == "help" ]; then |
---|
| 436 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk " \ |
---|
| 437 | "$FUNCNAME 1 " |
---|
| 438 | return |
---|
[945b003] | 439 | fi |
---|
[38231e9] | 440 | # Error si no se reciben 1 parámetros. |
---|
| 441 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 442 | |
---|
[6e139c9] | 443 | PART="$(ogDiskToDev $1)" || return $? |
---|
[38231e9] | 444 | ms-sys -z -f $PART |
---|
| 445 | ms-sys -m -f $PART |
---|
[945b003] | 446 | } |
---|
[42669ebf] | 447 | |
---|
[fdad5a6] | 448 | |
---|
| 449 | |
---|
| 450 | #/** |
---|
| 451 | # ogFixBootSector int_ndisk int_parition |
---|
| 452 | #@brief Corrige el boot sector de una particion activa para MS windows/dos -fat-ntfs |
---|
| 453 | #@param int_ndisk nº de orden del disco |
---|
| 454 | #@param int_partition nº de particion |
---|
| 455 | #@return |
---|
| 456 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 457 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 458 | #@version 0.9 - Adaptación a OpenGNSys. |
---|
| 459 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 460 | #@date 2009-09-24 |
---|
| 461 | #*/ ## |
---|
| 462 | |
---|
| 463 | function ogFixBootSector () |
---|
| 464 | { |
---|
| 465 | # Variables locales. |
---|
| 466 | local PART DISK FILE |
---|
| 467 | |
---|
| 468 | # Si se solicita, mostrar ayuda. |
---|
| 469 | if [ "$*" == "help" ]; then |
---|
| 470 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \ |
---|
| 471 | "$FUNCNAME 1 1 " |
---|
| 472 | return |
---|
| 473 | fi |
---|
| 474 | |
---|
| 475 | # Error si no se reciben 2 parámetros. |
---|
| 476 | [ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
| 477 | |
---|
| 478 | #TODO, solo si la particion existe |
---|
| 479 | #TODO, solo si es ntfs o fat |
---|
| 480 | PARTYPE=$(ogGetPartitionId $1 $2) |
---|
| 481 | case $PARTYPE in |
---|
| 482 | 1|4|6|7|b|c|e|f) |
---|
| 483 | ;; |
---|
| 484 | *) |
---|
| 485 | return $(ogRaiseError $OG_ERR_PARTITION; echo $?) |
---|
| 486 | ;; |
---|
| 487 | esac |
---|
| 488 | |
---|
| 489 | ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?) |
---|
| 490 | |
---|
| 491 | #Preparando instruccion |
---|
| 492 | let DISK=$1-1 |
---|
| 493 | PART=$2 |
---|
| 494 | FILE=/tmp/temporal |
---|
| 495 | cat > $FILE <<EOF |
---|
| 496 | disk=$DISK |
---|
| 497 | main_part=$PART |
---|
| 498 | fix_first_sector=yes |
---|
| 499 | EOF |
---|
| 500 | |
---|
| 501 | spartlnx.run -cui -nm -a -f $FILE |
---|
| 502 | |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | |
---|
| 506 | |
---|
| 507 | #/** |
---|
| 508 | # ogWindowsBootParameters int_ndisk int_parition |
---|
[78b5dfe7] | 509 | #@brief Configura el gestor de arranque de windows 7 / vista / XP / 2000 |
---|
[fdad5a6] | 510 | #@param int_ndisk nº de orden del disco |
---|
| 511 | #@param int_partition nº de particion |
---|
| 512 | #@return |
---|
| 513 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 514 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
[78b5dfe7] | 515 | #@version 0.9 - Integración desde EAC para OpenGNSys. |
---|
[fdad5a6] | 516 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 517 | #@date 2009-09-24 |
---|
[78b5dfe7] | 518 | #@version 1.0.1 - Adapatacion para OpenGnsys. |
---|
| 519 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 520 | #@date 2011-05-20 |
---|
[fdad5a6] | 521 | #*/ ## |
---|
| 522 | |
---|
| 523 | |
---|
| 524 | function ogWindowsBootParameters () |
---|
| 525 | { |
---|
| 526 | # Variables locales. |
---|
| 527 | local PART DISK FILE |
---|
[78b5dfe7] | 528 | #Preparando variables adaptadas a sintaxis windows. |
---|
| 529 | let DISK=$1-1 |
---|
| 530 | PART=$2 |
---|
| 531 | FILE=/tmp/temporal |
---|
[fdad5a6] | 532 | |
---|
| 533 | # Si se solicita, mostrar ayuda. |
---|
| 534 | if [ "$*" == "help" ]; then |
---|
| 535 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition " \ |
---|
| 536 | "$FUNCNAME 1 1 " |
---|
| 537 | return |
---|
| 538 | fi |
---|
| 539 | |
---|
| 540 | # Error si no se reciben 2 parámetros. |
---|
| 541 | [ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
| 542 | |
---|
| 543 | ogDiskToDev $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?) |
---|
| 544 | |
---|
| 545 | VERSION=$(ogGetOsVersion $1 $2) |
---|
| 546 | |
---|
[78b5dfe7] | 547 | if echo "$VERSION" | grep "Windows 7" |
---|
[fdad5a6] | 548 | then |
---|
| 549 | WINVER="Windows 7" |
---|
[78b5dfe7] | 550 | elif echo "$VERSION" | grep "Windows Seven" |
---|
[fdad5a6] | 551 | then |
---|
| 552 | WINVER="Windows Vista" |
---|
[78b5dfe7] | 553 | elif echo "$VERSION" | grep "XP" |
---|
| 554 | then |
---|
| 555 | MOUNT=$(ogMount $1 $2) |
---|
| 556 | [ -f ${MOUNT}/boot.ini ] || return $(ogRaiseError $OG_ERR_NOTOS; echo $?) |
---|
| 557 | cat ${MOUNT}/boot.ini | sed s/partition\([0-9]\)/partition\($PART\)/g | sed s/rdisk\([0-9]\)/rdisk\($DISK\)/g > ${MOUNT}/tmp.boot.ini; mv ${MOUNT}/tmp.boot.ini ${MOUNT}/boot.ini |
---|
| 558 | return 0 |
---|
[fdad5a6] | 559 | else |
---|
| 560 | return $(ogRaiseError $OG_ERR_NOTOS; echo $?) |
---|
| 561 | fi |
---|
| 562 | |
---|
| 563 | ogUnmount $1 $2 || return $(ogRaiseError $OG_ERR_PARTITION; echo $?) |
---|
[78b5dfe7] | 564 | |
---|
[fdad5a6] | 565 | |
---|
| 566 | #Preparando instruccion Windows Resume Application |
---|
| 567 | cat > $FILE <<EOF |
---|
| 568 | boot_disk=$DISK |
---|
| 569 | boot_main_part=$PART |
---|
| 570 | disk=$DISK |
---|
| 571 | main_part=$PART |
---|
| 572 | boot_entry=Windows Resume Application |
---|
| 573 | EOF |
---|
| 574 | spartlnx.run -cui -nm -w -f $FILE |
---|
| 575 | |
---|
| 576 | #Preparando instruccion tipo windows |
---|
| 577 | cat > $FILE <<EOF |
---|
| 578 | boot_disk=$DISK |
---|
| 579 | boot_main_part=$PART |
---|
| 580 | disk=$DISK |
---|
| 581 | main_part=$PART |
---|
| 582 | boot_entry=$WINVER |
---|
| 583 | EOF |
---|
| 584 | spartlnx.run -cui -nm -w -f $FILE |
---|
| 585 | |
---|
| 586 | #Preparando instruccion Ramdisk Options |
---|
| 587 | cat > $FILE <<EOF |
---|
| 588 | boot_disk=$DISK |
---|
| 589 | boot_main_part=$PART |
---|
| 590 | disk=$DISK |
---|
| 591 | main_part=$PART |
---|
| 592 | boot_entry=Ramdisk Options |
---|
| 593 | EOF |
---|
| 594 | spartlnx.run -cui -nm -w -f $FILE |
---|
| 595 | |
---|
| 596 | #Preparando instruccion Windows Boot Manager |
---|
| 597 | cat > $FILE <<EOF |
---|
| 598 | boot_disk=$DISK |
---|
| 599 | boot_main_part=$PART |
---|
| 600 | disk=$DISK |
---|
| 601 | main_part=$PART |
---|
| 602 | boot_entry=Windows Boot Manager |
---|
| 603 | EOF |
---|
| 604 | spartlnx.run -cui -nm -w -f $FILE |
---|
| 605 | |
---|
| 606 | #Preparando instruccion Herramienta de diagnóstico de memoria de Windows |
---|
| 607 | #cat > $FILE <<EOF |
---|
| 608 | #boot_disk=$DISK |
---|
| 609 | #boot_main_part=$PART |
---|
| 610 | #disk=$DISK |
---|
| 611 | #main_part=$PART |
---|
| 612 | #boot_entry=Herramienta de diagnóstico de memoria de Windows |
---|
| 613 | #EOF |
---|
| 614 | #spartlnx.run -cui -nm -w -f $FILE |
---|
| 615 | |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | |
---|
[78b5dfe7] | 619 | # ogWindowsRegisterPartition int_ndisk int_partiton str_volume int_disk int_partition |
---|
[fdad5a6] | 620 | #@brief Registra una partición en windows con un determinado volumen. |
---|
| 621 | #@param int_ndisk nº de orden del disco a registrar |
---|
| 622 | #@param int_partition nº de particion a registrar |
---|
| 623 | #@param str_volumen volumen a resgistar |
---|
| 624 | #@param int_ndisk_windows nº de orden del disco donde esta windows |
---|
| 625 | #@param int_partition_windows nº de particion donde esta windows |
---|
| 626 | #@return |
---|
| 627 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 628 | #@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar. |
---|
| 629 | #@version 0.9 - Adaptación a OpenGNSys. |
---|
| 630 | #@author Antonio J. Doblas Viso. Universidad de Málaga |
---|
| 631 | #@date 2009-09-24 |
---|
| 632 | #*/ ## |
---|
| 633 | |
---|
| 634 | |
---|
[78b5dfe7] | 635 | function ogWindowsRegisterPartition () |
---|
[fdad5a6] | 636 | { |
---|
| 637 | # Variables locales. |
---|
| 638 | local PART DISK FILE |
---|
| 639 | |
---|
| 640 | # Si se solicita, mostrar ayuda. |
---|
| 641 | if [ "$*" == "help" ]; then |
---|
| 642 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk_TO_registre int_partition_TO_registre str_NewVolume int_disk int_parition " \ |
---|
| 643 | "$FUNCNAME 1 1 c: 1 1" |
---|
| 644 | return |
---|
| 645 | fi |
---|
| 646 | |
---|
| 647 | # Error si no se reciben 5 parámetros. |
---|
| 648 | [ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?) |
---|
| 649 | |
---|
| 650 | REGISTREDDISK=$1 |
---|
| 651 | REGISTREDPART=$2 |
---|
| 652 | REGISTREDVOL=$(echo $3 | cut -c1 | tr '[:lower:]' '[:upper:]') |
---|
| 653 | DISK=$4 |
---|
| 654 | PART=$5 |
---|
| 655 | FILE=/tmp/temporal |
---|
| 656 | |
---|
| 657 | ogDiskToDev $REGISTREDDISK $REGISTREDPART || return $(ogRaiseError $OG_ERR_PARTITION "particion a registrar "; echo $?) |
---|
| 658 | ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows"; echo $?) |
---|
| 659 | |
---|
| 660 | ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?) |
---|
| 661 | |
---|
| 662 | VERSION=$(ogGetOsVersion $DISK $PART) |
---|
| 663 | |
---|
| 664 | #Systemroot |
---|
| 665 | |
---|
| 666 | if ogGetPath $DISK $PART WINDOWS |
---|
| 667 | then |
---|
| 668 | SYSTEMROOT="Windows" |
---|
| 669 | elif ogGetPath $DISK $PART WINNT |
---|
| 670 | then |
---|
| 671 | SYSTEMROOT="winnt" |
---|
| 672 | else |
---|
| 673 | return $(ogRaiseError $OG_ERR_NOTOS; echo $?) |
---|
| 674 | fi |
---|
| 675 | |
---|
| 676 | ogUnmount $DISK $PART |
---|
| 677 | let DISK=$DISK-1 |
---|
| 678 | let REGISTREDDISK=$REGISTREDDISK-1 |
---|
| 679 | #Preparando instruccion Windows Boot Manager |
---|
| 680 | cat > $FILE <<EOF |
---|
| 681 | windows_disk=$DISK |
---|
| 682 | windows_main_part=$PART |
---|
| 683 | windows_dir=$SYSTEMROOT |
---|
| 684 | disk=$REGISTREDDISK |
---|
| 685 | main_part=$REGISTREDPART |
---|
| 686 | ;ext_part |
---|
| 687 | part_letter=$REGISTREDVOL |
---|
| 688 | EOF |
---|
| 689 | spartlnx.run -cui -nm -u -f $FILE |
---|
| 690 | } |
---|