source: client/engine/PostConfEAC.lib @ 20a91aa

Last change on this file since 20a91aa was 71643c0, checked in by ramon <ramongomez@…>, 13 years ago

Integrar versión 1.0.2 en rama trunk (modificar #464).

git-svn-id: https://opengnsys.es/svn/trunk@2404 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 19.8 KB
Line 
1#!/bin/bash
2
3#         ogLoadHiveWindows int_ndisk int_partiton
4#@brief   Localiza los hive del registro de windows (de sistema y usuarios)
5#@param   int_ndisk      nº de orden del disco
6#@param   int_partition     nº de particion
7#@return 
8#@exception OG_ERR_FORMAT    Formato incorrecto.
9#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
10#@version 0.9 - Adaptación a OpenGNSys.
11#@author  Antonio J. Doblas Viso. Universidad de Málaga
12#@date    2009-09-24
13#*/ ##
14
15
16function ogLoadHiveWindows () {
17# Variables locales.
18local PART DISK
19
20# Si se solicita, mostrar ayuda.
21if [ "$*" == "help" ]; then
22    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition" \
23           "$FUNCNAME 1 1 "
24    return
25fi     
26
27# Error si no se reciben 2 parámetros.
28[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
29
30DISK=$1; PART=$2;
31
32#Comprobaciones redundantes: borrar"
33#ogDiskToDev $DISK $PART || return $(ogRaiseError $OG_ERR_PARTITION "particion de windows no detectada"; echo $?)
34#ogGetOsType $DISK $PART | grep "Windows" || return $(ogRaiseError $OG_ERR_NOTOS "no es windows"; echo $?)
35#VERSION=$(ogGetOsVersion $DISK $PART)
36#Fin Comprobaciones redundantes: borrar"
37
38if ogGetPath $DISK $PART WINDOWS
39then
40        SYSTEMROOT="Windows"
41elif ogGetPath $DISK $PART WINNT
42then
43        SYSTEMROOT="winnt"
44else
45        return $(ogRaiseError $OG_ERR_NOTOS "version windows no detectada"; echo $?)
46fi
47
48hiveSAM=$(ogGetPath $DISK $PART /${SYSTEMROOT}/system32/config/SAM) && export hiveSAM || return $(ogRaiseError $OG_ERR_NOTOS " hive SAM  no detectada"; echo $?)
49hiveSYSTEM=$(ogGetPath $DISK $PART /${SYSTEMROOT}/system32/config/system) && export hiveSYSTEM || return $(ogRaiseError $OG_ERR_NOTOS "hive SYSTEM  no detectada"; echo $?)
50hiveSOFTWARE=$(ogGetPath $DISK $PART /${SYSTEMROOT}/system32/config/software) && export hiveSOFTWARE || return $(ogRaiseError $OG_ERR_NOTOS "hive SOFTWARE no detectada"; echo $?)
51export TEMPhive=/tmp/tmpregistry
52
53## borrar elementos de la primera integracion
54#export particion=`ogMount $DISK $PART`
55#mkfifo pipe 2>/dev/null
56#declare -i count
57#declare -A HivePathUser
58#count=3
59# fin borrar elementos de la primera integracion
60
61declare -i COUNT
62COUNT=3
63BASEHOMEDIR=$(ogGetPath 1 1 /"Documents and Settings")
64TMPUSERFILE="/tmp/WuserRegAndDAT.tmp"
65find "$BASEHOMEDIR/" -type f -name NTUSER.DAT > $TMPUSERFILE 
66LISTUSERS=$(drbl-chntpw -l $hiveSAM | grep RID | awk -F"<" '{print $2}' | awk -F">" '{print $1}')
67#echo "$BASEHOMEDIR" $LISTUSERS
68for user in $LISTUSERS
69do     
70        # borrar elementos de la primera integracion.
71                #if find ${particion}/ -type f -name NTUSER.DAT > pipe| cat pipe | grep $user > /tmp/path.txt.$count
72                #then
73                #echo pefil de $user encontrado, para utilizar este usuario con funciones utilizar id_hive= $count o \$usuario
74                #read camino < /tmp/path.txt.$count
75                #echo $camino | sed -e 's/ /\\ /g' > /tmp/path.txt.$count
76                #camino2=$(echo $camino | sed -e 's/ /\\ /g')
77                #echo $camino2 | sed -e 's/\\/\\\\/g' > /tmp/path.txt.$count
78                #export `echo $user=hiveUSER$count`
79                #export `echo hiveUSER$count`="$camino2"
80                #count=${count}+1
81                #fiecho $user
82    # Fin borrar elementos de la primera integracion.
83       
84        # Comprobamos que el usuario registrado tiene .DAT
85                if HOMEDIR=$(cat $TMPUSERFILE | grep -w $user) 
86                then
87                        #echo "$user exportamos los usuarios de windows como variables, y como valor hiveUSERX; donde la X es 3 4 5 6 ... X"
88                        export `echo $user=hiveUSER$COUNT`
89                        #echo "$user exportamos la variable hiveUSERX con el valor del home de la variable-usuario_windows"
90                        ##export `echo hiveUSER$COUNT`="$(echo $HOMEDIR | sed -e 's/ /\\ /'g | sed -e 's/\\/\\\\/g')"
91                        export `echo hiveUSER$COUNT`="$(echo $HOMEDIR)"
92                        #echo " estas variables \$USUARIO -> Identificador del HIVE ; \${!USUARIO} -> path del HIVE "
93                        COUNT=${COUNT}+1
94                fi
95               
96done
97COUNT=0
98}
99
100
101#         ogUpdateHiveWindows 
102#@brief   Actualiza los hive de windows.
103#@param   int_ndisk       
104#@param   int_partition     
105#@return 
106#@exception OG_ERR_FORMAT    Formato incorrecto.
107#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
108#@version 0.9 - Adaptación a OpenGNSys.
109#@author  Antonio J. Doblas Viso. Universidad de Málaga
110#@date    2009-09-24
111#*/ ##
112
113
114function ogUpdateHiveWindows (){
115# Variables locales.
116local PART DISK FILE
117
118#TODO detectar llamada a ogLoadHiveWindows
119
120# Si se solicita, mostrar ayuda.
121if [ "$*" == "help" ]; then
122    ogHelp "$FUNCNAME" "$FUNCNAME " \
123           "$FUNCNAME  "
124    return
125fi     
126
127echo drbl-chntpw -f $TEMPhive $hiveSAM $hiveSYSTEM $hiveSOFTWARE \"${hiveUSER3}\" \"${hiveUSER4}\" \"${hiveUSER5}\" \"${hiveUSER6}\" \"${hiveUSER7}\" \"${hiveUSER8}\" \"${hiveUSER9}\" > /tmp/run.sh
128cat /tmp/run.sh; sh /tmp/run.sh; rm -fr $TEMPhive; rm /tmp/run.sh
129
130unset hiveSAM hiveSYSTEM hiveSOFTWARE TEMPhive hiveUSER3 hiveUSER4 hiveUSER5 hiveUSER6 hiveUSER7 hiveUSER8 hiveUSER9
131 
132
133}
134
135
136
137function ogHiveNTRunMachine () {
138#echo sintaxis:  PathScripts idScripts
139#echo ejemplo:   c:\\\\WINDOSWS\\\\crearusuarios.bat  scripts1
140#echo IMPORTANTE: el path debe llevar dos barras \\, pero como se deben 'escapar' debes poner cuatro \\\\
141#echo "identifica 0=$hiveSAM 1=$hiveSystem 2=$hiveSoftware 3=$HiveUser3"
142
143local PART DISK FILE
144
145# Si se solicita, mostrar ayuda.
146if [ "$*" == "help" ]; then
147    ogHelp "$FUNCNAME" "$FUNCNAME PathScripts|command keyName " \
148           "$FUNCNAME c:\\\\Windows\\\\crearusuarios.cmd scripts_crearUsuarios "\
149           "$FUNCNAME "cmd /c del c:\ogboot.*" ogcleanboot "\
150           "$FUNCNAME Requiere la previa ejecución de ogLoadHive int_disk int_part"\
151           "$FUNCNAME Despues requiere el ogUpdateHive"
152    return
153fi     
154       
155
156# Error si no se reciben al menos 1 parámetros.
157[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)   
158
159
160cat >> $TEMPhive << EOF
161h 2
162cd \Microsoft\Windows\CurrentVersion\Run
163nv 1 $2
164ed $2
165$1
166EOF
167#ogGetRegistryValue /mnt/sda1 software '\Microsoft\Windows\CurrentVersion\Run\og3'
168}
169
170function ogNTPolUserOn () {
171
172# Si se solicita, mostrar ayuda.
173if [ "$*" == "help" ]; then
174    ogHelp "$FUNCNAME" "$FUNCNAME id_hive_user " \
175           "$FUNCNAME NombreUsuario"\
176           "$FUNCNAME "
177    return
178fi             
179
180# TODO: error si no se ha llamado previamente a ogLoadHiveWindows
181[ -n $hiveSAM ] || return $(ogRaiseError $OG_ERR_FORMAT "se debe utilizar primero la utilidad ogLoadHiveWindows"; echo $?)
182
183# TODO: error si el usuario no tiene cuenta en windows.
184drbl-chntpw -l $hiveSAM | grep RID | grep -w $1 || return $(ogRaiseError $OG_ERR_FORMAT "el usuario $1 no tiene cuenta en este windows: Compruebe mayusculas o minusculas"; echo $?)
185
186# TODO: error si no el usario no no tiene HIVE asociado.
187[ -n "${!1}" ] || return $(ogRaiseError $OG_ERR_FORMAT "el usuario no tiene hive creado"; echo $?)
188
189
190HIVEID=$(echo ${!1} | tr -d "hiveUSER")
191
192
193#echo "IMPORTANTE:  la variable HiveUser3=/mnt/windows/Document/\ and/\ Seeting\alumnmos\NTUSER.dat"
194echo $HIVEID
195#cp /var/EAC/admin/utilswin/Fondo.BMP ${particion}/WINDOWS/
196
197cat >> $TEMPhive << EOF
198h $HIVEID
199cd \Control Panel\Desktop
200ed Wallpaper
201C:\\WINDOWS\\fondo.bmp
202
203cd \Software\Microsoft\Windows\CurrentVersion\Policies
204nk Explorer
205cd Explorer
206
207nv 4 NoDesktop
208ed NoDesktop
2091
210
211nv 4 NoSimpleStartMenu
212ed NoSimpleStartMenu
2131
214nv 4 NoWindowsUpdate
215ed NoWindowsUpdate
2161
217
218nv 4 NoSMConfigurePrograms
219ed NoSMConfigurePrograms
2201
221
222nv 4 NoChangeStartMenu
223ed NoChangeStartMenu
2241
225
226nv 4 Intellimenus
227ed Intellimenus
2281
229
230nv 4 NoRun
231ed NoRun
2321
233
234nv 4 NoRecentDocsHistory
235ed NoRecentDocsHistory
2361
237EOF
238}
239
240
241
242
243
244##########################################################
245##########################################################
246#####librerias de PostConfiguracion v0.1para Advanced Deploy enViorenment###########
247# Liberado bajo licencia GPL <http://www.gnu.org/licenses/gpl.html>################
248############# 2008 Antonio Jes�s Doblas Viso  adv@uma.es ##########################
249########### Universidad de Malaga (Spain)############################
250##########################################################
251
252
253
254
255
256function NTChangeName () {
257if [ $# = 0 ]
258then
259echo sintaxis: NTChangeNAME str_$var
260echo ejemplos: NTCHangeName adi${IPcuatro}-xp
261fi
262cat >> $temporal << EOF
263h 1
264ed ControlSet001\Control\ComputerName\ComputerName\ComputerName
265$1
266ed ControlSet001\Services\Tcpip\Parameters\Hostname
267$1
268ed ControlSet001\Services\Tcpip\Parameters\NV Hostname
269$1
270h 2
271cd \Microsoft\Windows NT\CurrentVersion\Winlogon
272ed DefaultDomainName
273$1
274EOF
275}
276
277
278
279function NTSetGroupName () {
280if [ $# = 0 ]
281then
282echo sintaxis: NTSetGroupName str_$var
283echo ejemplos: NTSetGroupName adi
284fi
285cat >> $temporal << EOF
286h 2
287ed \Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName
288$1
289EOF
290}
291
292
293function NTSetOwner (){
294if [ $# = 0 ]
295then
296echo sintaxis: NtSetOwner str_propietario str_organizacion
297echo ejemplos: NTSetOwner eu\ politecnica universidad\ de\ malaga
298fi
299cat >> $temporal << EOF
300h 2
301ed \Microsoft\Windows NT\CurrentVersion\RegisteredOwner
302$1
303ed \Microsoft\Windows NT\CurrentVersion\RegisteredOrganization
304$2
305EOF
306}
307
308
309function NTAutoLogon (){
310if [ $# = 0 ]
311then
312echo sintaxis: Int_Activar Int_nves str_usuario str_passwd str_equipo
313echo ejemplos: 1 2 administrador 3451 $equipo
314echo IMPORTANTE: cuando AutoLogonCount llegue a 0, activa el AutoAdminLogon a 0. Pero no borra los valores de DefaultPassword
315return 2
316fi
317echo la pass es $4
318export temporal=/tmp/tmpregistry
319cat >> $temporal << EOF
320hive 2
321cd \Microsoft\Windows NT\CurrentVersion\Winlogon
322nv 1 AutoAdminLogon
323ed AutoAdminLogon
324$1
325nv 1 AutoLogonCount
326ed AutoLogonCount
327$2
328nv 1 DefaultUserName
329ed DefaultUserName
330$3
331nv 1 DefaultDomainName
332ed DefaultDomainName
333$5
334EOF
335if [ "$4" == none ]
336then
337echo "debe aparecer done" $4
338cat >> $temporal << EOF
339dv DefaultPassword
340
341
342EOF
343else
344cat >> $temporal << EOF
345nv 1 DefaultPassword
346ed DefaultPassword
347$4
348EOF
349fi
350}
351
352function NTStatusRatonTeclado (){
353if [ $# = 0 ]
354then
355echo sintaxis: Int-StatusRaton Int-StatusTeclado
356echo ejemplos:  int=1 activo   int=4 desactivado
357return 2
358fi
359cat >> $temporal << EOF
360hive 1
361cd \ControlSet001\Services\Mouclass
362ed Start
363$1
364cd \ControlSet001\Services\Kbdclass
365ed Start
366$2
367EOF
368}
369
370function NTRunOnceMachine () {
371if [ $# = 0 ]
372then
373echo sintaxis:  PathScripts idScripts
374echo "ejemplo:   c:\\\\WINDOSWS\\\\crearusuarios.bat  scripts1"
375echo "IMPORTANTE: el path debe llevar dos barras \\, pero como se deben 'escapar' debes poner cuatro \\\\"
376return 2
377fi
378export temporal=/tmp/tmpregistry
379cat >> $temporal << EOF
380h 2
381cd \Microsoft\Windows\CurrentVersion\RunOnce
382nv 1 $2
383ed $2
384$1
385EOF
386}
387
388function NTRunMachine () {
389if [ $# = 0 ]
390then
391echo sintaxis:  PathScripts idScripts
392echo ejemplo:   c:\\\\WINDOSWS\\\\crearusuarios.bat  scripts1
393echo IMPORTANTE: el path debe llevar dos barras \\, pero como se deben 'escapar' debes poner cuatro \\\\
394return 2
395fi
396export temporal=/tmp/tmpregistry
397cat >> $temporal << EOF
398h 2
399cd \Microsoft\Windows\CurrentVersion\Run
400nv 1 $2
401ed $2
402$1
403EOF
404}
405
406function NTRunUser () {
407if [ $# = 0 ]
408then
409echo sintaxis:  str_PathWINScripts str_idScripts Int_hive||\$usuario
410echo ejemplo:   c:\\\\WINDOSWS\\\\crearusuarios.bat  scripts1 3
411echo IMPORTANTE: el pathWIN debe llevar dos barras \\, pero como se deben 'escapar' debes poner cuatro \\\\
412echo IMPORTANTE: el pathLinux si lleva espacios debe escaparse con una barra \\
413echo IMPORTANTE Int_hive: 3 para el primer usuario, 4 para el segundo usuario
414echo requiere export un HiveUser3=/mnt/windows/Document\ and\ Seeting\alumnmos\NTUSER.dat
415return 2
416fi
417cat >> $temporal << EOF
418h $3
419cd \Software\Microsoft\Windows\CurrentVersion\Run
420nv 1 $2
421ed $2
422$1
423EOF
424}
425
426
427
428function NTPolUserOn () {
429if [ $# = 0 ]
430then
431Msg "requiere LoadRegistryUser str_user1 str_user2..." orange
432echo "sintaxis:  Int_hive"
433echo "ejemplo: NTPolUserOn 3"
434echo "IMPORTANTE:  la variable HiveUser3=/mnt/windows/Document/\ and/\ Seeting\alumnmos\NTUSER.dat"
435return 2
436fi
437cp /var/EAC/admin/utilswin/Fondo.BMP ${particion}/WINDOWS/
438cat >> $temporal << EOF
439h $1
440cd \Control Panel\Desktop
441ed Wallpaper
442C:\\WINDOWS\\fondo.bmp
443
444cd \Software\Microsoft\Windows\CurrentVersion\Policies
445nk Explorer
446cd Explorer
447
448nv 4 NoDesktop
449ed NoDesktop
4501
451
452nv 4 NoSimpleStartMenu
453ed NoSimpleStartMenu
4541
455nv 4 NoWindowsUpdate
456ed NoWindowsUpdate
4571
458
459nv 4 NoSMConfigurePrograms
460ed NoSMConfigurePrograms
4611
462
463nv 4 NoChangeStartMenu
464ed NoChangeStartMenu
4651
466
467nv 4 Intellimenus
468ed Intellimenus
4691
470
471nv 4 NoRun
472ed NoRun
4731
474
475nv 4 NoRecentDocsHistory
476ed NoRecentDocsHistory
4771
478EOF
479}
480
481function NTPolUserOFF () {
482if [ $# = 0 ]
483then
484Msg "requiere LoadRegistryUser str_user1 str_user2..." orange
485echo "sintaxis:  Int_hive"
486echo "ejemplo: NTPolUserOFF 3"
487echo "IMPORTANTE:  la variable HiveUser3=/mnt/windows/Document/\ and/\ Seeting\alumnmos\NTUSER.dat"
488return 2
489fi
490cat >> $temporal << EOF
491h $1
492cd \Control Panel\Desktop
493ed Wallpaper
494C:\\WINDOWS\\web\\wallpaper\\Felicidad.bmp
495
496cd \Software\Microsoft\Windows\CurrentVersion\
497rdel Policies
498nk Policies
4991
500EOF
501}
502
503
504function NTStatusBootChk () {
505if [ $# = 0 ]
506then
507echo sintaxis: Int-Status
508echo ejemplos:  int=0 desactivado int=1 activado
509return 2
510fi
511[ $1 = 0 ] && valor="none"
512[ $1 = 1 ] && valor="autocheck autochk *"
513cat >> $temporal << EOF
514hive 1
515cd \ControlSet001\Control\Session Manager
516ed BootExecute
517$valor
518--n
519EOF
520}
521
522
523function ogSchrootLinux () {
524
525# Variables locales.
526local PART DISK DIRCONF SCHROOTDEVICE
527
528# Si se solicita, mostrar ayuda.
529if [ "$*" == "help" ]; then
530    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_partition" \
531           "$FUNCNAME 1 1 "
532    return
533fi     
534
535# Error si no se reciben 2 parámetros.
536[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
537
538DISK=$1; PART=$2; DIRCONF="/etc/schroot"
539
540
541VERSION=$(ogGetOsVersion $DISK $PART)
542echo $VERSION | grep "Linux" || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
543
544ogUnmount $DISK $PART || return $(ogRaiseError $OG_ERR_NOTOS "no es linux"; echo $?)
545
546SCHROOTDEVICE=$(ogDiskToDev $DISK $PART)
547
548
549rm ${DIRCONF}/mount-defaults
550rm ${DIRCONF}/schroot.conf
551
552cat >> ${DIRCONF}/mount-defaults << EOF
553# <file system> <mount point>   <type>  <options>       <dump>  <pass>
554proc            /proc           proc    defaults        0       0
555/dev            /dev            none    rw,bind         0       0
556/dev/pts        /dev/pts        none    rw,bind         0       0
557/dev/shm        /dev/shm        none    rw,bind         0       0
558EOF
559
560
561cat >> ${DIRCONF}/schroot.conf << EOF
562[linux]
563description=$VERSION
564type=block-device
565device=$SCHROOTDEVICE
566EOF
567
568
569
570
571schroot -c linux
572
573schroot -end-sessiona --all-sessions
574}
575
576####################################################################################
577################### Funciones para postconfiguracion windows #######################
578############# 2011 Jonathan Alonso Martinez  jonathan.alonso@uab.cat ###############
579#################### Universidad Autonoma de Barcelona (Spain)######################
580####################################################################################
581
582#/**
583#         ogInstallMiniSetup path_mountpoint str_filename
584#@brief   Crea unas claves del registro y el archivo cmd que se ejecutara en el primer arranque estando la maquina en un estado bloqueado
585#@param   path_mountpoint       directorio donde está montado el sistema Windows
586#@param   str_filename          nombre del archivo .cmd a ejecutar en el arranque (estara en system32 y sera visible por el sistema)
587#@return  (nada)
588#@exception OG_ERR_FORMAT    Formato incorrecto.
589#@version 1.0.2 - Nueva función
590#@author  Jonathan Alonso Martinez - Universidad Autonoma de Barcelona
591#@date    2011-06-29
592#*/ ##
593function ogInstallMiniSetup ()
594{
595local CMDDIR CMDFILE
596# Si se solicita, mostrar ayuda.
597if [ "$*" == "help" ]; then
598    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_filename" \
599           "$FUNCNAME /mnt/sda1 filename.cmd"
600    return
601fi
602# Error si no se reciben 2 parámetros.
603[ $# == 2 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
604# Comprobar que existe el directorio del fichero de comandos.
605CMDDIR=$(ogGetPath "$1/windows/system32")
606[ -n "$CMDDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$1/windows/system32" || return $?
607CMDFILE="$CMDDIR/$2"
608
609# Creamos el archivo cmd y creamos un par de comandos para que una vez acabe la
610# postconfiguracion resetee el mini setup, sino lo haria en cada arranque.
611cat > "$CMDFILE" << EOF
612REG ADD HKLM\System\Setup /v SystemSetupInProgress /t REG_DWORD /d 0 /f
613REG ADD HKLM\System\Setup /v CmdLine /t REG_SZ /d "" /f
614EOF
615
616#Creamos las claves de registro necesarias para que se haga la ejecucion del .cmd al aranque
617ogSetRegistryValue "$1" SYSTEM "\Setup\SystemSetupInProgress" 1
618ogSetRegistryValue "$1" SYSTEM "\Setup\SetupType" 4
619ogSetRegistryValue "$1" SYSTEM "\Setup\CmdLine" "cmd.exe /c $2"
620}
621
622
623#         ogAddCmd path_mountpoint str_filename str_commands
624#@brief   Añade comandos al cmd creado por ogInstalMiniSetup
625#@param   path_mountpoint       directorio donde está montado el sistema Windows
626#@param   str_filename          nombre del fichero cmd (siempre se guardara en windows\system32\para que sea visible por el sistema
627#@param   str_commands          comando o comandos que se añadiran al fichero
628#@return 
629#@exception OG_ERR_FORMAT    Formato incorrecto.
630#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
631#@version 1.0.2 - Nueva función
632#@author  Jonathan Alonso Martinez - Universidad Autonoma de Barcelona
633#@date    2011-06-29
634#*/ ##
635
636function ogAddCmd ()
637{
638local CMDFILE
639# Si se solicita, mostrar ayuda.
640if [ "$*" == "help" ]; then
641    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_filename str_commands" \
642           "$FUNCNAME /mnt/sda1 filename.cmd command"
643    return
644fi
645# Error si no se reciben 3 parámetros.
646[ $# == 3 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
647# Comprobar que existe el fichero de comandos.
648CMDFILE=$(ogGetPath "$1/windows/system32/$2")
649[ -n "$CMDFILE" ] || ogRaiseError $OG_ERR_NOTFOUND "$1/windows/system32/$2" || return $?
650
651cat >> "$CMDFILE" << EOF
652$3
653EOF
654}
655
656#         ogDomainScript path_mountpoint str_domain str_user str_password
657#@brief   Crea un script .vbs para unir al dominio una maquina windows y el comando adequado en el archivo cmd creado por ogInstallMiniSetup
658#@param   path_mountpoint       directorio donde está montado el sistema Windows
659#@param   str_filename          nombre del fichero cmd donde deberemos introducir el comando de ejecutar el script vbs
660#@param   str_domain            Dominio donde se quiere conectar
661#@param   str_user              Usuario con privilegios para unir al dominio
662#@param   str_password          Password del usuario con privilegios
663#@return 
664#@exception OG_ERR_FORMAT    Formato incorrecto.
665#@version 1.0.2 - Nueva función
666#@author  Jonathan Alonso Martinez - Universidad Autonoma de Barcelona
667#@date    2011-06-29
668#*/ ##
669
670function ogDomainScript ()
671{
672local CMDDIR
673# Si se solicita, mostrar ayuda.
674if [ "$*" == "help" ]; then
675    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_filename str_domain str_user str_password" \
676           "$FUNCNAME /mnt/sda1 filename.cmd domain user password_user"
677    return
678fi
679# Error si no se reciben 4 parámetros.
680[ $# == 5 ] || return $(ogRaiseError $OG_ERR_FORMAT; echo $?)
681# Comprobar que existe el directorio de comandos.
682CMDDIR=$(ogGetPath "$1/windows/system32")
683[ -n "$CMDDIR" ] || ogRaiseError $OG_ERR_NOTFOUND "$1/windows/system32" || return $?
684
685# Añadimos en el cmd que se ejecutara al arranque, el comando de ejecutar el script que añade al dominio.
686ogAddCmd $1 "$2" "CSCRIPT joindomain.vbs"
687# Eliminamos el script porque tiene el usuario de administrador de dominio en claro
688ogAddCmd $1 "$2" "del /Q C:\Windows\System32\joindomain.vbs"
689
690# Creamos el archivo joindomain.vbs que nos introduce la maquina en el dominio
691cat > "$CMDDIR/joindomain.vbs" << EOF
692Const JOIN_DOMAIN = 1
693Const ACCT_CREATE = 2
694Const ACCT_DELETE = 4
695Const WIN9X_UPGRADE = 16
696Const DOMAIN_JOIN_IF_JOINED = 32
697Const JOIN_UNSECURE = 64
698Const MACHINE_PASSWORD_PASSED = 128
699Const DEFERRED_SPN_SET = 256
700Const INSTALL_INVOCATION = 262144
701
702strDomain = "$3"
703strUser = "$4"
704strPassword = "$5"
705
706Set objNetwork = CreateObject("WScript.Network")
707strComputer = objNetwork.ComputerName
708
709Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\\" & _
710    strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
711
712ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, _
713    strDomain & "\" & strUser, NULL, JOIN_DOMAIN + ACCT_CREATE)
714EOF
715}
716
Note: See TracBrowser for help on using the repository browser.