Skip to content

Instantly share code, notes, and snippets.

@rkmax
Created January 10, 2013 01:22
Show Gist options
  • Save rkmax/4498603 to your computer and use it in GitHub Desktop.
Save rkmax/4498603 to your computer and use it in GitHub Desktop.
Genera imagenes minimas para el servidor
#!/bin/bash
SOURCE=http://es.archive.ubuntu.com/ubuntu/
BASEPATH="images"
VARIANT=minbase
ARCH=amd64
INCLUDE="language-pack-es,language-pack-es-base,ssh,vim"
if [ -z $BASEPATH ];then
echo "Defina una ruta base"
exit 1
fi
mk_image()
{
image=$(mktemp)
dd if=/dev/zero of=${image} bs=1M count=1024 &> /dev/null
mkfs.ext3 -F ${image} &> /dev/null
echo ${image}
}
clean()
{
img=$1
path=$2
echo -n "Limpiando: "
sudo umount ${path}
rm -rf ${img}
echo "OK"
}
bootstrap()
{
release=$1
dest="${BASEPATH}/${ARCH}/${release}"
user=${USER}
error_log=$(mktemp)
echo -n "Creando imagen temporal: "
img=$(mk_image) && echo "OK" || {
echo "FAIL"
exit 1
}
echo -n "Creando punto de montaje: "
[ -d $dest ] || mkdir -p $dest
[ -d $dest ] && echo "OK" || {
echo "FAIL"
exit 1
}
echo -n "Montando imagen: "
sudo mount ${img} ${dest} -o loop &> /dev/null && echo "OK" || {
echo "FAIL"
clean ${img} ${dest}
exit 1
}
echo -n "Generando distribucion: "
sudo debootstrap --arch $ARCH --include $INCLUDE --variant $VARIANT $release $dest 2> ${error_log} && {
echo "OK"
sudo umount ${dest} &> /dev/null && mv ${img} "${dest}/${release}-${VARIANT}.img"
sudo chown ${user}. ${img} "${dest}/${release}-${VARIANT}.img" &> /dev/null
}
if [[ $? == 1 ]]; then
echo "FAIL"
clean ${img} ${dest}
echo -e "----------\n"
cat ${error_log}
exit 1
fi
}
bootstrap $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment