-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminino-traspasa32
executable file
·371 lines (326 loc) · 14.9 KB
/
minino-traspasa32
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/bin/bash
# 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 <http://www.gnu.org/licenses/>
# (c) Antonio Sánchez León, 2010, 2011, 2012, 2013, 2014,2015, 2016, 2017 <introlinux[fix@]gmail[fix.]com>
# (c) Miguel Anxo Bouzada, 2010, 2011, 2012, 2013, 2014,2015, 2016, 2017 <mbouzada[fix@]gmail[fix.]com>
# (c) GALPon MinNo Team, 2010, 2011, 2012, 2013, 2014,2015, 2016, 2017 <minino[fix@]galpon[fix.]org>
## -
case $LANG in
ca*)
TIT="Minino traspasa"
TIT0="Transferir el sistema"
TIT1="On transferim tot el sistema?"
TEXT1A="La destinació ha de tenir una mida d'almenys"
TEXT1B="i estar formatat en EXT4.\n\nNecesitará el doble de mida si està transferint des d'un DVD en viu (live)."
TIT2="Transferint el sistema ..."
TEXT2="Sistema transferit.\n\nReinicia el sistema abans de desendollar\nper assegurar que totes les particions\nes van desmuntar correctament."
TEXT3="Transferència cancel·lada.\nEl sistema no est à completament transferit."
TEXT4="Hi va haver algun problema en transferir el sistema.\nSegurament no estigui completament transferit\ni no podràs iniciar-ho."
ECHO1="Això trigarà una estona. Paciència! ..."
ECHO2="Uf! La carpeta /usr sí que té coses..."
ECHO3="Ja queda menys."
ECHO4="Ja queda molt poquet."
MSG="Aquesta utilitat <b>no formata</b> el disc de destinació,
simplement copia i instal·la un carregador d'arrencada.
Si necessita formatar, faci-ho abans de llançar l'script,
per aixó pot utilitzar l'eina <i>Gparted</i>. \n
A més, vés amb compte i neteja l'historial dels navegadors,
contrasenyes que puguis tenir guardades, documents a les
teves carpetes personals ... abans de bolcar el sistema en
l'equip d'un amic o veí per preservar la teva intimitat. \n
Si necessites informació sobre com fer això,
pregunta en el <a href='http://minino.galpon.org/es/forum'>fòrum de GALPon MiniNo</a>. "
;;
es*)
TIT="Minino traspasa"
TIT0="Transferir el sistema"
TIT1="¿Dónde transferimos todo el sistema?"
TEXT1A="El destino debe tener un tamaño de al menos"
TEXT1B="y estar formateado en EXT4.\n\n"
TIT2="Transfiriendo el sistema ..."
TEXT2="Sistema transferido.\n\nReinicie el sistema antes de desenchufar\npara asegurar que todas las particiones\nse desmontaron correctamente."
TEXT3="Transferencia cancelada.\nEl sistema no está completamente transferido."
TEXT4="Hubo algún problema al transferir el sistema.\nSeguramente no esté completamente transferido\ny no podrá iniciarlo."
ECHO1="Esto tardará un rato. Sea paciente ..."
ECHO2="Uf! La carpeta /usr sí que tiene cosas..."
ECHO3="Ya queda menos."
ECHO4="Ya queda muy poquito."
MSG="Esta utilidad <b>no formatea</b> el disco de destino,
simplemente copia e instala un cargador de arranque.
Si necesita formatear, hágalo antes de lanzar el script,
para ello puede utilizar la herramienta <i>Gparted</i>. \n
Además, tenga cuidado y limpie el historial de los
navegadores, contraseñas que pueda tener guardadas,
documentos en sus carpetas personales... antes de
volcar el sistema en el equipo de un amigo o vecino
para preservar su intimidad. \n
Si necesita información sobre cómo hacer esto,
pregunte en el <a href='http://minino.galpon.org/es/forum'>foro de GALPon MiniNo</a>. "
;;
gl*)
TIT="Minino traspasa"
TIT0="Transferir o sistema"
TIT1="Cara onde transferimos todo o sistema?"
TEXT1A="O destino ten que ter un tamaño de canda menos"
TEXT1B="e estar formatado en EXT4.\n\n"
TIT2="Transferindo o sistema ..."
TEXT2="Sistema transferido.\n\nReinicie o sistema antes de desenchufar\npara asegurar que todas as particións\nforon desmontadas correctamente."
TEXT3="Transferencia cancelada.\nO sistema non foi transferido completamente."
TEXT4="Xurdiu algún problema ao transferir o sistema.\nSeguramente non estea transferido completamente\ne non poderá inicialo."
ECHO1="A isto aínda lle vai levar o seu ..."
ECHO2="Vaites! O cartafol /usr sí que está cheíño..."
ECHO3="Xa faltou máis."
ECHO4="Pouco queda xa."
MSG="Esta utilidade <b>non formata</b> o disco de destino,
simplemente copia e instala un cargador de arrinque.
Se precisa formatar, fágao antes de executar o script,
para elo pode utilizar a ferramenta <i>Gparted</i>. \n
Ademais, teña coidado e limpe o historial dos navegadores,
contrasinais que poida ter gardadas, documentos nos seus
cartafoles persoais... antes de envorcar o sistema no
equipo dun amigo ou veciño para preservar a súa intimidade. \n
Se necesita información sobre como facer isto,
pregunte no <a href='http://minino.galpon.org/gl/forum'>foro de GALPon MiniNo</a>. "
;;
*)
TIT="Minino transfer"
TIT0="Transfer system"
TIT1="Where the system will be transfered?"
TEXT1A="The target must have a size of at least"
TEXT1B="and formated in EXT4."
TIT2="Transfering the system..."
TEXT2="System transfered.\n\nRestart before unpluging\nto be sure all partitions\nare umounted."
TEXT3="Transfer canceled.\nThe system is not transfered completly."
TEXT4="There was a problem when transferring the system.\nSurely not completely transferred\nand you can't boot it."
ECHO1="This will take a while, be patient..."
ECHO2="Wow! The folder /usr has a lot of stuffs..."
ECHO3="Not much longer now."
ECHO4="It's getting close."
MSG="This utility does <b>not format</b> the target disk,
simply copies files and installs a boot loader.
If you need to format, do it before launching the utility,
you can use <i>Gparted</i> tool for this task. \n
Also, be careful and clean the browser history,
saved passwords you may have, documents in your
personal folders ... before transfer the system
on the computer of a friend or neighbor to preserve
your privacy. \n
If you need information for doing this,
please ask in <a href='http://minino.galpon.org/en/forum'>GALPon MiniNo forum</a>. "
;;
esac
# DEPENDENCIAS: gdisk, util-linux, yad, refind, grub
# Determinar si estamos en un livedvd o no
LIVE=`df | grep aufs`
if [ "$LIVE" != "" ];then echo "LiveDVD" && LIVE=yes;fi
KERNEL="vmlinuz-`uname -r`"
ICON="drive-harddisk"
traspasaMiniNo(){
rm /tmp/todaslasparticiones*
# RECOGEMOS DATOS
# discousado=`df -h|grep "rootfs"|awk '{print $3}'`
# tamanioroot=`df |grep "rootfs"|awk '{print $3}'`
discousado=`df -h|grep -w "/"|awk '{print $3}'`
if [ "$LIVE" = "yes" ];then
discousado=`df |grep squashfs|awk '{print $3}'`
scale=2
discousado=`echo "scale=1;$discousado*2/1024/1024"|bc`
discousado="${discousado}GB"
fi
tamanioroot=`df |grep -w "/"|awk '{print $3}'`
if [ "$LIVE" = "yes" ];then tamanioroot=`df|grep squashfs|awk '{print $3}'`;fi
blkid -o device >/tmp/particiones
blkid >/tmp/infoparticiones
python /usr/local/bin/encuentra-pendrive.py >/tmp/infopendrives
while read -r line
do
caracterfinal=`echo -n $line|tail -c 1`
if [[ $caracterfinal != *[[:digit:]]* ]]; then echo "$line" >>/tmp/infopen; fi
done</tmp/infopendrives
mv /tmp/infopen /tmp/infopendrives
# ESTO ES PARA EL FORMATEO DE LO QUE APARECERÁ EN yad/YAD
# particion tiene forma /dev/sda1
for particion in `cat /tmp/particiones`;do
INFOPARTI=`fdisk -l "$particion"|grep "$particion"|grep bytes|awk '{print $3 $4}'`
SD=`echo $particion|tr -d [:digit:]`
SDINFO=`cat /tmp/infopendrives|grep -a $SD|cut -d"," -f1`
LABEL=`cat /tmp/infoparticiones|grep $particion|awk -F'LABEL=' '{print $2}'|awk '{print $1}'`
if [ "$LABEL" == "" ];then LABEL="Sin etiqueta";fi
FORMAT=`cat /tmp/infoparticiones|grep $particion|awk -F'TYPE=' '{print $2}'|awk '{print $1}'`
ESPACIO=" ----> "
LINEA="$particion: $INFOPARTI $FORMAT $ESPACIO $LABEL $SDINFO"
echo "$LINEA" >>/tmp/todaslasparticiones_repes
done
sort -u /tmp/todaslasparticiones_repes > /tmp/a;mv /tmp/a /tmp/todaslasparticiones_sinrepes
cat /tmp/todaslasparticiones_sinrepes|grep "ext4" >/tmp/todaslasparticiones
rpl ": " ": " /tmp/todaslasparticiones
cat /tmp/todaslasparticiones |cut -d" " -f1- |tac| yad --list --title "${TIT1}" \
--text "${TEXT1A} <b>${discousado}</b> ${TEXT1B}" --width 500 --height 300 \
--window-icon "$ICON" --image "$ICON" \
--column Dispositivos >/tmp/partielegida
# PARTIELEGIDA tiene forma sda1
PARTIELEGIDA=`cat /tmp/partielegida|cut -d":" -f1|cut -d"/" -f3`
echo "PARTICIÓN ELEGIDA: ${PARTIELEGIDA}"
if [ "$PARTIELEGIDA" == "" ] || [ "$PARTIELEGIDA" == "/" ];then echo "No se eligió ninguna opción" && exit 0;fi
umount /dev/$PARTIELEGIDA
# Preparamos el icono para el arranque EFI
cp /usr/local/share/icons/madexa.png /boot/${KERNEL}.png
# AQUÍ TRANSFERIMOS EL SISTEMA
(
cd /tmp
mkdir $PARTIELEGIDA
mount /dev/$PARTIELEGIDA /tmp/$PARTIELEGIDA
#tamaniodrive=`df|grep "/dev/$PARTIELEGIDA"|awk '{print $3}'`
cd /
#echo $(($tamaniodrive*100/$tamanioroot))
echo 3
### Copiamos todo el sistema al destino, como no tenemos forma de saber el
### progreso de la copia, dividimos lo que se tiene que copiar en carpetas y simulamos una especie de progreso
echo "#${ECHO1}"
rsync -va --exclude '*' --exclude '/tmp' --include '*/' / /tmp/$PARTIELEGIDA/
echo 6
rsync -va --delete /bin/ /tmp/$PARTIELEGIDA/bin/
echo 10
rsync -va --delete /boot/ /tmp/$PARTIELEGIDA/boot/
echo 12
rsync -va --delete /etc/ /tmp/$PARTIELEGIDA/etc/
echo 14
rsync -vaXAH --delete --ignore-errors /lib/ /tmp/$PARTIELEGIDA/lib/ --exclude 'live/mount/*'
echo 18
rsync -va --delete /var/ /tmp/$PARTIELEGIDA/var/
echo 25
rsync -vaXAH --delete --ignore-errors /home/ /tmp/$PARTIELEGIDA/home/ --exclude '/home/remastersys/*'
echo 30
echo "#${ECHO2}"
rsync -va --delete /usr/bin/ /tmp/$PARTIELEGIDA/usr/bin/
echo 35
rsync -va --delete /usr/share/ /tmp/$PARTIELEGIDA/usr/share/
echo 40
rsync -va --delete /usr/local/ /tmp/$PARTIELEGIDA/usr/local/
echo 45
rsync -va --delete /usr/share/lib/ /tmp/$PARTIELEGIDA/usr/share/lib/
echo 50
rsync -va --delete --ignore-errors /usr/ /tmp/$PARTIELEGIDA/usr/
rsync -va --delete /proc /tmp/$PARTIELEGIDA/ --exclude '/proc/*';rm -r /tmp/$PARTIELEGIDA/proc/*
rsync -va --delete /dev /tmp/$PARTIELEGIDA/ --exclude '/dev/*';rm -r /tmp/$PARTIELEGIDA/dev/*
rsync -va --delete /sys /tmp/$PARTIELEGIDA/ --exclude '/sys/*';rm -r /tmp/$PARTIELEGIDA/sys/*
rsync -va --delete /run /tmp/$PARTIELEGIDA/ --exclude '/run/*';rm -r /tmp/$PARTIELEGIDA/run/*
echo 60
echo "#${ECHO3}"
rsync -va --delete /opt/ /tmp/$PARTIELEGIDA/opt/
echo 65
rsync -va --delete /root/ /tmp/$PARTIELEGIDA/root/
echo 70
rsync -vaXAH --delete --ignore-errors /sbin/ /tmp/$PARTIELEGIDA/sbin/
echo 75
rsync -va --delete --ignore-errors /srv/ /tmp/$PARTIELEGIDA/srv/
echo 77
rsync -vaxXAH --ignore-errors / /tmp/$PARTIELEGIDA/ --exclude '/home/remastersys/*' --exclude '/proc/*' --exclude '/dev/*' --exclude '/sys/*' --exclude '/tmp/*' --exclude '/media/*' --exclude '/mnt/*' --exclude '/run/*' --exclude '/lib/live/mount/*' --exclude '/live/*' --exclude '/selinux/*'
echo 80
echo "#${ECHO4}"
rm /tmp/$PARTIELEGIDA/etc/udev/rules.d/70-persistent-net.rules
### Etiquetamos el destino para no andar con UUIDs
e2label /dev/$PARTIELEGIDA minino-$PARTIELEGIDA
echo 85
### Modificamos fstab para que el sistema encuentre dónde está la nueva partición
cp /tmp/$PARTIELEGIDA/etc/fstab /tmp/$PARTIELEGIDA/etc/fstab-original
cat <<-EOF >/tmp/$PARTIELEGIDA/etc/fstab
# /etc/fstab: static file system information.
# Format:
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
LABEL=minino-$PARTIELEGIDA / ext4 errors=remount-ro,noatime,commit=60 0 1
/SWAPFILE none swap sw 0 0
EOF
### Actualizamos configuración por si se usa REFIND para arrancar EN UEFI
######### EN PRUEBAS INSTALACIÓN CON UEFI
disktype=`echo $PARTIELEGIDA|cut -c 1`
if [ "$disktype" = "s" ];then
disk=`echo -n $PARTIELEGIDA |head -c -1`
else
disk=`echo -n $PARTIELEGIDA |head -c -2`
fi
if [ "$disktype" = "s" ];then
efipart=`gdisk -l /dev/$disk|grep EF00|awk '{print $1}'`
numpartefi=$efipart
else
efipart=`gdisk -l /dev/$disk|grep EF00|awk '{print $1}'`
numpartefi=$efipart
efipart="p"$efipart
fi
echo -n '"Boot with standard options" "ro root=' >/tmp/$PARTIELEGIDA/boot/refind_linux.conf
uuid=`blkid -o export -s UUID /dev/$PARTIELEGIDA| grep UUID`
echo -n $uuid >>/tmp/$PARTIELEGIDA/boot/refind_linux.conf
echo -n ' quiet splash zswap.zpool=zsmalloc"' >>/tmp/$PARTIELEGIDA/boot/refind_linux.conf
if [ "$efipart" = "" ];then
echo -n "No se encuentra la partición EFI."
else
#efipart=$disk$efipart
echo "INSTALAMOS REFIND en /dev/$disk$efipart" >/tmp/refindi
cd /opt/refind/
./refind-install --usedefault /dev/$disk$efipart --alldrivers
fi
### Añadimos un archivo swap en el raíz del destino de 256M
dd if=/dev/zero of=/tmp/$PARTIELEGIDA/SWAPFILE bs=1M count=256
mkswap -L SWAP /tmp/$PARTIELEGIDA/SWAPFILE
echo 90
### Instalamos GRUB
mount -B /dev /tmp/$PARTIELEGIDA/dev
mount -t proc proc /tmp/$PARTIELEGIDA/proc
mount -t sysfs sysfs /tmp/$PARTIELEGIDA/sys
#Grub considera la imagen.png del logo que usa refind como otro kernel y lo muestra en el menú,
#estos mv son para evitarlo
mv /tmp/$PARTIELEGIDA/boot/${KERNEL}.png /tmp/$PARTIELEGIDA/boot/a.png
chroot /tmp/$PARTIELEGIDA update-grub
mv /tmp/$PARTIELEGIDA/boot/a.png /tmp/$PARTIELEGIDA/boot/${KERNEL}.png
discoduro=`echo $PARTIELEGIDA |tr -d [:digit:]`
chroot /tmp/$PARTIELEGIDA grub-install /dev/$discoduro
sync
umount -a
umount /tmp/$PARTIELEGIDA/dev
umount /tmp/$PARTIELEGIDA/proc
umount /tmp/$PARTIELEGIDA/sys
umount /tmp/$PARTIELEGIDA
echo 100
)|yad --progress --auto-close --auto-kill --width 400 --title "${TIT2}" \
--window-icon "$ICON" --image "$ICON"
# Eliminamos el icono para que no se lie el kernel al arrancar
rm /boot/${KERNEL}.png
case $? in
0) yad --info --text "${TEXT2}" --window-icon "$ICON" --image "$ICON" --button="gtk-ok:0" --title "${TIT}"
;;
1) killall rsync
killall dd
umount -a
umount /tmp/$PARTIELEGIDA/dev
umount /tmp/$PARTIELEGIDA/proc
umount /tmp/$PARTIELEGIDA/sys
umount /tmp/$PARTIELEGIDA
yad --info --text "${TEXT3}" --window-icon "$ICON" --image "$ICON" --title "${TIT}"
;;
-1) killall rsync
killall dd
umount -a
umount /tmp/$PARTIELEGIDA/dev
umount /tmp/$PARTIELEGIDA/proc
umount /tmp/$PARTIELEGIDA/sys
umount /tmp/$PARTIELEGIDA
yad --info --text "${TEXT4}" --window-icon "$ICON" --image "$ICON" --title "${TIT}"
;;
esac
}
MESSAGE=$(yad --info --text "$MSG" --title "$TIT0" --window-icon "$ICON" --image "$ICON")
ret=$?
if [ "$ret" != "0" ]; then
exit 0
else
traspasaMiniNo
fi