[3ec149c] | 1 | #!/bin/bash |
---|
| 2 | |
---|
[e034672] | 3 | |
---|
| 4 | #Load engine configurator from engine.cfg file. |
---|
| 5 | #Carga el configurador del engine desde el fichero engine.cfg |
---|
| 6 | [ -z $OGENGINECONFIGURATE ] && source /opt/opengnsys/etc/engine.cfg |
---|
| 7 | |
---|
| 8 | # Clear temporary file used as log track by httpdlog |
---|
| 9 | # Limpia los ficheros temporales usados como log de seguimieincludento para httpdlog |
---|
| 10 | echo " " > $OGLOGSESSION; echo " " > $OGLOGCOMMAND; echo " " > ${OGLOGCOMMAND}.tmp |
---|
| 11 | |
---|
| 12 | # Registro de inicio de ejecución |
---|
| 13 | #echo "[START Interface ] Run this command: $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 14 | echo "$MSG_INTERFACE_START $0 $*" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 15 | |
---|
| 16 | # Solo ejecutable por OpenGnSys Client. |
---|
| 17 | PATH=$PATH:$(dirname $0) |
---|
| 18 | PROG=$(basename $0) |
---|
| 19 | |
---|
| 20 | #____________________________________________________________________ |
---|
[3ec149c] | 21 | # |
---|
[e034672] | 22 | # El parámetro $2 es el que aporta toda la información y el $1 se queda obsoleto |
---|
[3ec149c] | 23 | # Formato de entrada: |
---|
[e034672] | 24 | # dis=Número de disco |
---|
| 25 | # $=caracter de separación |
---|
| 26 | # che=Vale 0 o 1 |
---|
| 27 | # $=caracter de separación |
---|
| 28 | # $tch=tamaño cache |
---|
| 29 | # @= caracter de separación |
---|
| 30 | # |
---|
| 31 | # Y un numero indeterminado de cadenas del tipo siguuenteseparadas por el caracter '$': |
---|
| 32 | # par=Número de particion#cod=Código de partición#sfi=Sistema de ficheros#tam=Tamaño de la partición#ope=Operación |
---|
| 33 | #____________________________________________________________________ |
---|
[3ec149c] | 34 | |
---|
[e034672] | 35 | # Captura de parámetros |
---|
| 36 | param=$2; |
---|
| 37 | #param='dis=1$che=0$tch=70000000@par=1$cpt=NTFS$sfi=NTFS$tam=11000000$ope=0#' |
---|
| 38 | echo "Parametros recibidos"$param | tee -a $OGLOGSESSION $OGLOGFILE |
---|
[3997593] | 39 | |
---|
| 40 | # Activa navegador para ver progreso |
---|
[e034672] | 41 | coproc /opt/opengnsys/bin/browser -qws http://localhost/cgi-bin/httpd-log.sh |
---|
[3997593] | 42 | |
---|
[e034672] | 43 | # Separacion de los dos bloques separados por '@' |
---|
| 44 | declare -a TBPRM |
---|
[3997593] | 45 | |
---|
[e034672] | 46 | for ((i=1;i<3;i++)); |
---|
| 47 | do |
---|
| 48 | TBPRM[$i]=$(echo $param | awk p=$i'{ |
---|
| 49 | n=split($0,sep,"!"); |
---|
| 50 | printf("%s",sep[p]);}') |
---|
| 51 | done |
---|
| 52 | |
---|
| 53 | pparam=${TBPRM[1]} |
---|
| 54 | sparam=${TBPRM[2]} |
---|
| 55 | |
---|
| 56 | #echo "Parametros recibidos pparam"$pparam | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 57 | #echo "Parametros recibidos sparam"$sparam | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 58 | |
---|
| 59 | # Toma valores de disco y caché |
---|
| 60 | # Los valores están en las variables $dis: disco,$che: vale 1 0 cero, $tch: Tamaño de la cache" |
---|
| 61 | declare -a TBP |
---|
| 62 | for ((prm=1;prm<4;prm++)); |
---|
| 63 | do |
---|
| 64 | TBPRM[$prm]=$(echo $pparam | awk -v p=$prm '{ |
---|
| 65 | split($0,sep,"*"); |
---|
| 66 | printf("%s",sep[p]); |
---|
| 67 | }') |
---|
| 68 | eval ${TBPRM[$prm]} |
---|
| 69 | done |
---|
[3997593] | 70 | |
---|
[e034672] | 71 | # Toma valores de tamaño y distribución de particiones |
---|
[3ec149c] | 72 | declare -a TBP |
---|
| 73 | declare -a TBF |
---|
[3997593] | 74 | |
---|
[e034672] | 75 | particiones=$(echo $sparam | awk '{n=split($0,sep,"%");print n}') |
---|
| 76 | |
---|
[3ec149c] | 77 | for ((par=1;par<$particiones;par++)); |
---|
| 78 | do |
---|
[e034672] | 79 | TBP[$par]=$(echo $sparam | awk -v p=$par '{ |
---|
| 80 | n=split($0,sep,"%"); |
---|
| 81 | split(sep[p],dua,"*"); |
---|
[3ec149c] | 82 | split(dua[1],prm,"="); |
---|
| 83 | par=prm[2]; |
---|
| 84 | split(dua[2],prm,"="); |
---|
| 85 | cpt=prm[2]; |
---|
| 86 | split(dua[3],prm,"="); |
---|
| 87 | sfi=prm[2]; |
---|
| 88 | split(dua[4],prm,"="); |
---|
| 89 | tam=prm[2]; |
---|
| 90 | split(dua[5],prm,"="); |
---|
| 91 | ope=prm[2]; |
---|
[e034672] | 92 | printf("%s %s %s %s %s",par,cpt,sfi,tam,ope); |
---|
[3ec149c] | 93 | }') |
---|
| 94 | done |
---|
| 95 | |
---|
[e034672] | 96 | # Prepara cadena de particiones |
---|
[3ec149c] | 97 | cP="" |
---|
| 98 | for ((par=1;par<$particiones;par++)); |
---|
| 99 | do |
---|
[e034672] | 100 | cfg=${TBP[$par]} |
---|
[3ec149c] | 101 | cP=$cP$(echo $cfg | awk '{ |
---|
| 102 | n=split($0,prm," "); |
---|
| 103 | par=prm[1]; |
---|
| 104 | cpt=prm[2]; |
---|
| 105 | sfi=prm[3]; |
---|
| 106 | tam=prm[4]; |
---|
[e034672] | 107 | ope=prm[5]; |
---|
| 108 | printf("%s:%s ",cpt,tam); |
---|
[3ec149c] | 109 | }') |
---|
| 110 | |
---|
| 111 | TBF[$par]=$(echo $cfg | awk '{ |
---|
| 112 | n=split($0,prm," "); |
---|
| 113 | sfi=prm[3]; |
---|
| 114 | ope=prm[5]; |
---|
| 115 | if(ope==1) |
---|
| 116 | printf("%s",sfi); |
---|
| 117 | else |
---|
| 118 | printf("EMPTY"); |
---|
| 119 | }') |
---|
| 120 | |
---|
| 121 | done |
---|
[3997593] | 122 | |
---|
[e034672] | 123 | #____________________________________________________ |
---|
| 124 | # |
---|
| 125 | # Proceso |
---|
| 126 | #____________________________________________________ |
---|
| 127 | |
---|
[3997593] | 128 | |
---|
| 129 | # Desmonta todas las particiones y la caché |
---|
[e034672] | 130 | echo "Desmonta todas las particiones y la caché" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 131 | ogUnmountCache |
---|
| 132 | ogUnmountAll $dis |
---|
| 133 | |
---|
| 134 | # Elimina la tabla de particiones |
---|
| 135 | echo "Elimina la tabla de particiones" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 136 | ogDeletePartitionTable $dis |
---|
| 137 | ogUpdatePartitionTable $dis | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 138 | |
---|
| 139 | echo "Creando tabla de particiones tipo MSDOS" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 140 | # Crea tabla de particiones MSDOS |
---|
| 141 | ogCreatePartitionTable $dis MSDOS |
---|
| 142 | |
---|
| 143 | echo "Creando entradas en la tabla de particiones $dis $cP" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 144 | ogCreatePartitions $dis $cP | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 145 | |
---|
| 146 | RETVAL=$? |
---|
| 147 | if [ $RETVAL -ne 0 ]; then |
---|
| 148 | kill $COPROC_PID |
---|
| 149 | exit $RETVAL |
---|
| 150 | fi |
---|
| 151 | echo "Tabla de particiones creada" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 152 | |
---|
| 153 | # Formatear particiones |
---|
[3ec149c] | 154 | for ((par=1;par<$particiones;par++)); |
---|
| 155 | do |
---|
| 156 | sfi=${TBF[$par]} |
---|
[e034672] | 157 | if [ "$sfi" != "EMPTY" ]; then |
---|
| 158 | echo "Formateando disco $dis, particion $par con tipo $sfi" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 159 | ogFormatFs $dis $par $sfi | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 160 | RETVAL=$? |
---|
| 161 | if [ $RETVAL -ne 0 ]; then |
---|
| 162 | kill $COPROC_PID |
---|
| 163 | exit $OG_ERR_PARTITION |
---|
| 164 | fi |
---|
[3ec149c] | 165 | fi |
---|
[e034672] | 166 | done |
---|
| 167 | |
---|
| 168 | # Cuestión caché |
---|
| 169 | if [ "$che" == "1" ]; then |
---|
| 170 | echo "Creando y actualizando la cache con el tamaño:$tch" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 171 | initCache $tch &>/dev/null | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 172 | fi |
---|
| 173 | |
---|
| 174 | ogUpdatePartitionTable $dis | tee -a $OGLOGSESSION $OGLOGFILE |
---|
| 175 | |
---|
[3997593] | 176 | #___________________________________________________________________ |
---|
| 177 | # |
---|
| 178 | # Retorno |
---|
| 179 | #___________________________________________________________________ |
---|
| 180 | |
---|
[e034672] | 181 | echo "¡¡¡ El proceso ha terminado con exito !!!" | tee -a $OGLOGSESSION $OGLOGFILE |
---|
[3997593] | 182 | kill $COPROC_PID |
---|
| 183 | exit 0 |
---|
| 184 | |
---|