-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstalar
More file actions
165 lines (137 loc) · 4.1 KB
/
instalar
File metadata and controls
165 lines (137 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
# Copyright 2000-2019 Reciclanet Asociación Educativa-Reciclanet Hezkuntza Elkartea www.reciclanet.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
SERVER=${SERVER:-10.10.20.3}
HD=${HD:-'/dev/sda'}
HD_SWAP=${HD_SWAP:-4096}
HD_ROOT=${HD_ROOT:-20480}
LOCAL_MP=${LOCAL_MP:-'/tmp/pxe'}
REMOTE_MP=${REMOTE_MP:-'/pxe'}
IMAGE_DIR="$LOCAL_MP/${IMAGE_DIR:-img}"
NFSMOUNT=`/etc/init.d/nfsmount status | awk -F: '{print $2}' | sed 's/ //g'`
START_TIME=0
END_TIME=0
function pause(){
read -p "$*"
}
function init_msg(){
START_TIME=`date +%s`
pause "** INSTALACIÓN AUTOMÁTICA DE SSOO **
EL CONTENIDO DEL DISCO DURO SE BORRARÁ POR COMPLETO.
Pulse CONTROL+C para detener la instalación.
Pulse ENTER para comenzar la instalación."
}
function hd_format(){
echo "* Preparación del disco duro *"
echo "Limpiando MBR..."
dd if=/dev/zero of=$HD count=1 bs=512 &> /dev/null
echo 'Creando las nuevas particiones...'
echo "n
p
1
+"$HD_ROOT"M
n
p
2
+"$HD_SWAP"M
n
p
3
w" | fdisk $HD &> /dev/null
dmsetup remove_all
partprobe $HD
sleep 5
echo "Formateando las nuevas particiones..."
mkfs -t ext4 "$HD"1 &> /dev/null
NEW_SWAP_UUID=`mkswap "$HD"2 | grep 'UUID' | cut -d "=" -f 2`
mkfs -t ext4 "$HD"3 &> /dev/null
swapon "$HD"2 &> /dev/null
echo "Preparación del disco duro finalizada"
}
function img_install(){
echo "* Instalación de la imagen *"
echo "Iniciando instalación de imagen"
if [ $NFSMOUNT != 'started' ]; then
echo "Servicio NFS desactivado, activando..."
/etc/init.d/nfsmount start &> /dev/null
fi
mkdir -p $LOCAL_MP
mount -o nolock $SERVER:$REMOTE_MP $LOCAL_MP &> /dev/null
cd $IMAGE_DIR
IMAGES=($(ls -f ./*.fsa))
cd - &> /dev/null
IMAGE_NUM=${#IMAGES[@]}
((LAST_POS=$IMAGE_NUM-1))
SELECTED=100
while ! [[ "${SELECTED}" =~ ^[0-9]+$ ]] || [ $SELECTED -lt 0 ] || [ $SELECTED -ge $IMAGE_NUM ]; do
echo
echo "Imagenes disponibles para su instalación:"
for i in `seq 0 $LAST_POS`; do
IMAGES[$i]=`echo ${IMAGES[$i]} | sed 's,./,,g'`
echo "$i) ${IMAGES[$i]}"
done
echo "Introduce el número de la imagen que deseas instalar:"
read SELECTED
echo
done
echo "Has seleccionado la imagen ${IMAGES[$SELECTED]}"
echo "Comenzando la instalación de la imagen.
La operación puede durar aproximadamente 5 minutos."
fsarchiver restfs $IMAGE_DIR/${IMAGES[$SELECTED]} id=0,dest="$HD"1 &> /dev/null
fsarchiver restfs $IMAGE_DIR/${IMAGES[$SELECTED]} id=1,dest="$HD"3 &> /dev/null
umount $IMAGE_DIR &> /dev/null
if [ $NFSMOUNT = 'started' ]; then
echo "Servicio NFS activado, desactivando..."
/etc/init.d/nfsmount start &> /dev/null
fi
}
function grub_install(){
echo "* Instalación de GRUB *"
echo "Montando $HD y sus particiones..."
local tmproot=$(mktemp -d)
mount "$HD"1 $tmproot
mount -t proc proc $tmproot/proc
mount -t sysfs sys $tmproot/sys
mount -o bind /dev $tmproot/dev
echo "Instalando y configurando GRUB..."
chroot $tmproot update-grub2 &> /dev/null
chroot $tmproot grub-install $HD &> /dev/null
echo "Generando UUID $HD2 (swap)..."
OLD_SWAP_UUID=`cat $tmproot/etc/fstab | grep swap | grep 'UUID' | cut -d "=" -f 2 | cut -d " " -f 1`
sed -i "s/$OLD_SWAP_UUID/$NEW_SWAP_UUID/g" $tmproot/etc/fstab
echo "Desmontando $HD y sus particiones"
umount $tmproot/dev
umount $tmproot/sys
umount $tmproot/proc
umount $tmproot
rmdir $tmproot
}
function end_msg(){
END_TIME=`date +%s`
(( EXEC_TIME = $END_TIME - $START_TIME ))
echo "Fin de la instalación: Ahora solo falta reiniciar el equio"
echo "Tiempo de instalación: $EXEC_TIME segundos"
}
echo
init_msg
echo
hd_format
echo
img_install
echo
grub_install
echo
end_msg
echo