121 lines
4.2 KiB
Bash
121 lines
4.2 KiB
Bash
#!/bin/bash
|
|
#/**
|
|
#@brief Descomprime el fichero ogclient.sqfs en ogclient.img con un formato donde podemos escribir.
|
|
#@param none
|
|
#@note Copiado del wiki: http://opengnsys.es/wiki/ClienteInitrdDSGenerarlo
|
|
#@note para "entrar" en ogclient: schroot -c ogclient.img o mount ogclient.img ogclientmount -o loop,offset=32256
|
|
#@exeption 1 No es usuario root
|
|
#@exeption 2 No existe el fichero ogclient.sqfs
|
|
#@date 2013-11.27
|
|
#*/
|
|
PROG="$(basename $0)"
|
|
# Mostrar ayuda si se solicita.
|
|
if [ "$*" == "help" ]; then
|
|
echo -e "$PROG: Descomprime el fichero ogclient.sqfs en ogclient.img con un formato donde podemos escribir. \n" \
|
|
" Uso: $PROG (sin parametros)"
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$USER" != "root" ]; then
|
|
echo "$PROG: Error: solo ejecutable por root" >&2
|
|
exit 1
|
|
fi
|
|
|
|
|
|
|
|
DATE=$(date +%y-%m-%d)
|
|
OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"}
|
|
OGCLIENTBASEDIR=$OPENGNSYS/tftpboot/ogclient/;
|
|
OGCLIENTSQFS=${OGCLIENTBASEDIR}ogclient.sqfs
|
|
OGCLIENTFILE=${OGCLIENTBASEDIR}ogclient.img;
|
|
OGCLIENTMOUNT=${OGCLIENTBASEDIR}ogclientmount;
|
|
OGCLIENTSIZEMB=1900;
|
|
OGCLIENTLABEL=ogClient;
|
|
|
|
# Comprobamos que existe el cliente .sqfs
|
|
! [ -f $OGCLIENTSQFS ] && echo "No existe $OGCLIENTSQFS" && exit 3
|
|
|
|
# instalamos los paquetes necesarios.
|
|
echo "Si no existen, instalamos los paquetes necesarios: squashfs-tools schroot."
|
|
if ! which schroot unsquashfs 2>&1 >/dev/null; then
|
|
apt-get update
|
|
apt-get -y install squashfs-tools schroot
|
|
fi
|
|
|
|
# Creamos el archivo.
|
|
echo -e "\nCreamos el archivo."
|
|
echo dd if=/dev/zero of=$OGCLIENTFILE bs=1048576 count=$OGCLIENTSIZEMB;
|
|
dd if=/dev/zero of=$OGCLIENTFILE bs=1048576 count=$OGCLIENTSIZEMB;
|
|
DISKLOOP=$(losetup -f);
|
|
losetup $DISKLOOP $OGCLIENTFILE;
|
|
echo -e "n\np\n1\n\n\nt\n83\nw" | fdisk $DISKLOOP;
|
|
losetup -d $DISKLOOP ;
|
|
|
|
# Creamos el sistema de ficheros.
|
|
echo "Creamos el sistema de ficheros."
|
|
echo "mkfs.ext4 -b 4096 -L $OGCLIENTLABEL $PARTLOOP"
|
|
PARTLOOP=$(losetup -f);
|
|
losetup -o 32256 $PARTLOOP $OGCLIENTFILE && mkfs.ext4 -b 4096 -L $OGCLIENTLABEL $PARTLOOP;
|
|
losetup -d $PARTLOOP ;
|
|
|
|
# Descomprimimos el ogclient.sqfs en el sistema de ficheros.
|
|
mkdir -p $OGCLIENTMOUNT;
|
|
echo "Descomprimimos el ogclient.sqfs en el sistema de ficheros."
|
|
mount | grep $OGCLIENTMOUNT || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256;
|
|
echo "unsquashfs -d ${OGCLIENTMOUNT}/ -f $OGCLIENTSQFS"
|
|
unsquashfs -d ${OGCLIENTMOUNT}/ -f $OGCLIENTSQFS
|
|
umount $OGCLIENTMOUNT;
|
|
|
|
# Creamos los archivos de configuracion de schroot.
|
|
echo "Creamos los archivos de configuracion de schroot."
|
|
cp /etc/schroot/schroot.conf /etc/schroot/schroot.conf.$DATE
|
|
cat << EOF > /etc/schroot/schroot.conf
|
|
[ogclient.img]
|
|
type=loopback
|
|
file=${OGCLIENTBASEDIR}ogclient.img
|
|
description=ogclient ubuntu luc IMGi
|
|
#priority=1
|
|
users=root
|
|
groups=root
|
|
root-groups=root
|
|
mount-options=-o offset=32256
|
|
root-users=root
|
|
#[DIRogclient]
|
|
#type=directory
|
|
#directory=${OGCLIENTBASEDIR}ogclientmount
|
|
#description=ogclient ubuntu lucid DIR
|
|
#priority=2
|
|
#users=root
|
|
#groups=root
|
|
#root-groups=root
|
|
#root-users=root
|
|
EOF
|
|
|
|
cp /etc/schroot/mount-defaults /etc/schroot/mount-defaults.$DATE
|
|
cat << EOF > /etc/schroot/mount-defaults
|
|
# mount.defaults: static file system information for chroots.
|
|
# Note that the mount point will be prefixed by the chroot path
|
|
# (CHROOT_PATH)
|
|
#
|
|
# <file system> <mount point> <type> <options> <dump> <pass>
|
|
proc /proc proc defaults 0 0
|
|
#procbususb /proc/bus/usb usbfs defaults 0 0
|
|
/dev /dev none rw,bind 0 0
|
|
/dev/pts /dev/pts none rw,bind 0 0
|
|
/dev/shm /dev/shm none rw,bind 0 0
|
|
#/home /home none rw,bind 0 0
|
|
/tmp /tmp none rw,bind 0 0
|
|
EOF
|
|
|
|
# Si existen dispositivos loop los eliminamos.
|
|
echo "Si existen dispositivos loop los eliminamos."
|
|
LOOPDEVICES=$(losetup -a|grep $OGCLIENTFILE |cut -d: -f1)
|
|
for DEVICE in $LOOPDEVICES
|
|
do
|
|
echo "losetup -d $DEVICE"
|
|
losetup -d $DEVICE
|
|
done
|
|
|
|
echo -e "Para \"entrar\" en ogclient: \n \t schroot -c ogclient.img o \n \t mount ogclient.img ogclientmount -o loop,offset=32256"
|
|
echo "El servicio schroot montará el cliente automaticamente, si no queremos que pase hay que apagarlo."
|