Last active
October 27, 2019 08:05
-
-
Save debxp/63b912bc46023d6e2e3f2bcaff09a0c4 to your computer and use it in GitHub Desktop.
Novo script de customização de imagens Debian netinstall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Uso: | |
# | |
# ./custom-iso imagem-netinstall.iso \ | |
# imagem-nova.iso \ | |
# /caminho/arquivo/preseed.cfg | |
# 1. Caminho de extração da imagem original (tmp_dir) | |
tmp_dir="mnt" | |
# 2. Verificar se usuário é root | |
if [[ $EUID -ne 0 ]]; then | |
echo -e "Use 'sudo' para executar este script!\n" 1>&2 | |
exit 1 | |
fi | |
# 3. Dependências | |
declare -A deps | |
deps[bsdtar]=libarchive-tools | |
deps[isohybrid]=syslinux-utils | |
deps[genisoimage]=genisoimage | |
for d in "${!deps[@]}"; do | |
[[ -z $(command -v $d) ]] \ | |
&& echo -e "\n\n-- ${deps[$d]} não instalado, saindo...\n\n" \ | |
&& exit 1 | |
done | |
# 4. Extrair imagem original | |
echo -e "\n-- Extraindo imagem para $tmp_dir..." | |
mkdir $tmp_dir | |
bsdtar -C "$tmp_dir/" -xf $1 | |
# 5. Detectar a arquitetura da imagem | |
arch=$(find $tmp_dir/install.* -maxdepth 0 -type d) | |
arch=${arch##*.} | |
echo "-- Arquitetura detectada: $arch" | |
# 6. Descompactar initrd.gz | |
chmod -R +w "$tmp_dir/install.$arch" | |
echo "-- Extraindo $tmp_dir/install.$arch/initrd.gz..." | |
gunzip "$tmp_dir/install.$arch/initrd.gz" | |
# 7. Incluir o preseed em initrd | |
echo -e "-- Incluindo arquivo $3 em initrd... \c" | |
cp $3 preseed.cfg | |
echo preseed.cfg | cpio -H newc -o -A -F "$tmp_dir/install.$arch/initrd" | |
rm preseed.cfg | |
# 8. Recomprimir o initrd | |
echo "-- Comprimindo o initrd..." | |
gzip "$tmp_dir/install.$arch/initrd" | |
chmod -R -w "$tmp_dir/install.$arch" | |
# 9. Atualizar a soma md5 | |
echo "-- Atualizando md5sum.txt..." | |
cd $tmp_dir | |
md5sum $(find -follow -type f 2>/dev/null) > md5sum.txt | |
cd .. | |
# 10. Gerar a nova imagem | |
echo -e "-- Gerando imagem $2..." | |
rm -f $2 | |
genisoimage -quiet -r -J -b isolinux/isolinux.bin \ | |
-c isolinux/boot.cat -no-emul-boot \ | |
-boot-load-size 4 -boot-info-table \ | |
-o $2 $tmp_dir | |
real_usr="$(logname)" | |
chown $real_usr:$real_usr $2 | |
# 11. Tornar nova imagem bootável por por USB | |
echo -e "-- Tornando $2 bootable..." | |
isohybrid $2 | |
# 12. Limpeza | |
rm -fr $tmp_dir | |
echo -e "\nPronto!\n" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment