Fusion des 2 script install PXE

This commit is contained in:
Adrien Reslinger 2020-04-13 00:08:00 +02:00
parent cc4d694c8e
commit 5eb90966eb
2 changed files with 30 additions and 110 deletions

View file

@ -1,5 +1,19 @@
#/bin/bash
for PARAM in "$@"; do
case "$PARAM" in
--version=*) CENTOS_VERSION="${PARAM/*=}" ;;
--distrib=*) DISTRIB="${PARAM/*=}" ;;
esac
done
if [ -z "${CENTOS_VERSION}" ]; then
CENTOS_VERSION=8
fi
if [ -z "${DISTRIB}" ]; then
DISTRIB="CentOS"
fi
if ! which wget; then
yum install -y wget
fi
@ -13,8 +27,17 @@ MAC="$(ip addr show $IF | grep ether\ | awk '{print $2}' | cut -d/ -f2 | tr [A-
DNS="$(grep nameserver /etc/resolv.conf | grep -v 127.0.0.1 | awk '{printf $2","}' | sed 's/,$//')"
ARCH=$(uname -m | sed 's|i.86|i386|')
MIRROIR=http://mirror.centos.org/centos/8/BaseOS/$ARCH/os
#MIRROIR=http://lune.saacy.reslinger.net/repos/CentOS8/$ARCH/os
if [ "${CENTOS_VERSION}" == "8" ]; then
MIRROIR=http://mirror.centos.org/centos/8/BaseOS/$ARCH/os
#MIRROIR=http://lune.saacy.reslinger.net/repos/CentOS8/$ARCH/os
elif [ "${CENTOS_VERSION}" == "7" ]; then
#MIRROIR=http://centos.mirrors.ovh.net/ftp.centos.org/7/os/$ARCH
MIRROIR=http://mirror.centos.org/centos/7/os/$ARCH
#MIRROIR=http://lune.saacy.reslinger.net/repos/CentOS7/$ARCH/os
else
echo "Version ${CENTOS_VERSION} non reconnue" >&2
exit 1
fi
#DESKTOP=desktop
INST_OPTIONS="lang=fr_FR keymap=fr-latin9 panic=1 ks.sendsn ks.sendmac inst.sshd=1 net.ifnames=0 biosdevname=0 $DESKTOP"
INST_OPTIONS="${INST_OPTIONS} inst.vnc inst.vncpassword=SDFGHJKL"
@ -63,14 +86,14 @@ if [ -f /boot/grub2/grub.cfg ]; then
fi
cat >> /etc/grub.d/40_custom <<EOF
menuentry 'CentOS 8 Install (PXE)' --unrestricted {
menuentry 'CentOS ${CENTOS_VERSION} Install (PXE)' --unrestricted {
set root='${UUID_BOOT_DISK}'
if [ x\$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint='${UUID_BOOT_DISK}' ${BOOT_UUID}
else
search --no-floppy --fs-uuid --set=root ${BOOT_UUID}
fi
linux $PARTBOOT/vmlinuz ${INST_OPTIONS} inst.ks=http://boot.reslinger.net/ks8.cfg inst.stage2=$MIRROIR ${CONSOLE}
linux $PARTBOOT/vmlinuz ${INST_OPTIONS} inst.ks=http://boot.reslinger.net/ks${CENTOS_VERSION}.cfg inst.stage2=$MIRROIR ${CONSOLE}
initrd $PARTBOOT/initrd.img
}
EOF
@ -80,12 +103,12 @@ EOF
CONFDIR=/boot/grub2
fi
grub2-mkconfig --output="${CONFDIR}"/grub.cfg
grub2-reboot 'CentOS 8 Install (PXE)'
grub2-reboot 'CentOS ${CENTOS_VERSION} Install (PXE)'
elif [ -f /boot/grub/grub.conf ]; then
cat >> /boot/grub/grub.conf <<EOF
title CentOS 8 Install (PXE)
title CentOS ${CENTOS_VERSION} Install (PXE)
root (hd0,0)
kernel $PARTBOOT/vmlinuz ${INST_OPTIONS} inst.ks=http://boot.reslinger.net/ks8.cfg inst.stage2=$MIRROIR ${CONSOLE}
kernel $PARTBOOT/vmlinuz ${INST_OPTIONS} inst.ks=http://boot.reslinger.net/ks${CENTOS_VERSION}.cfg inst.stage2=$MIRROIR ${CONSOLE}
initrd $PARTBOOT/initrd.img
EOF
NB="$(grep -Ev '^($| *#)' /boot/grub/grub.conf | grep -c title)"

View file

@ -1,103 +0,0 @@
#/bin/bash
if ! which wget; then
yum install -y wget
fi
IF="$(ip route show | grep ^default | sed 's/.* dev \([^ ]*\) *.*/\1/' | sort -u)"
IP="$(ip addr show $IF | grep inet\ | awk '{print $2}' | cut -d/ -f1)"
PREFIX="$(ip addr show $IF | grep inet\ | awk '{print $2}' | cut -d/ -f2)"
MASK="$(ipcalc -m $IP/$PREFIX | cut -d= -f2)"
GW="$(ip route show | grep ^default | sed 's/.* via \([^ ]*\) *.*/\1/' | sort -u)"
MAC="$(ip addr show $IF | grep ether\ | awk '{print $2}' | cut -d/ -f2 | tr [A-Z] [a-z])"
DNS="$(grep nameserver /etc/resolv.conf | grep -v 127.0.0.1 | awk '{printf $2","}' | sed 's/,$//')"
ARCH=$(uname -m | sed 's|i.86|i386|')
#MIRROIR=ftp://ftp.scientificlinux.org/linux/scientific/6x/$ARCH/os
#MIRROIR=ftp://mirrors.ircam.fr/pub/scientificlinux/scientific/6x/$ARCH/os
#MIRROIR=http://centos.mirrors.ovh.net/ftp.centos.org/7/os/$ARCH
MIRROIR=http://mirror.centos.org/centos/7/os/$ARCH
#MIRROIR=http://lune.saacy.reslinger.net/repos/CentOS7/$ARCH/os
#DESKTOP=desktop
INST_OPTIONS="lang=fr_FR keymap=fr-latin9 panic=1 ks.sendsn ks.sendmac inst.sshd=1 net.ifnames=0 biosdevname=0 inst.vnc inst.vncpassword=SDFGHJKL $DESKTOP"
#kernel $PARTBOOT/vmlinuz vnc vncpassword=ovhpassword ip=$IP netmask=$MASK gateway=$GW dns=$DNS ksdevice=$MAC method=$MIRROIR/ lang=fr_FR keymap=fr-latin1 panic=1 kssendmac sshd=1
if [ -z "$DNS" ]; then
if [ $(whois $IP | grep -ci dedibox) -gt 0 ]; then
# Dedibox
DNS=62.210.16.6,62.210.16.7
else
# OVH
DNS=213.186.33.99
#DNS=46.246.46.46,194.132.32.23
fi
fi
if [ $(mount | grep -c /boot\ ) -eq 1 ]; then
PARTBOOT=""
else
PARTBOOT="/boot"
fi
cd /boot
wget "$MIRROIR"/isolinux/{vmlinuz,initrd.img}
if [ $(ip link show | grep ^[0-9] | grep -v lo: | wc -l) -eq 1 ]; then
INST_OPTIONS="ks.device=link ${INST_OPTIONS}"
else
INST_OPTIONS="ks.device=$MAC ${INST_OPTIONS}"
fi
if [ ! -z "$STATIC" ]; then
INST_OPTIONS="ip=$IP::$GW:$MASK:$(hostname -s):$IF:off:${DNS/,*} ${INST_OPTIONS}"
fi
if [ -f /boot/grub/grub.conf ]; then
cat >> /boot/grub/grub.conf <<EOF
title CentOS 7 Install (PXE)
root (hd0,0)
kernel $PARTBOOT/vmlinuz ${INST_OPTIONS} inst.ks=http://boot.reslinger.net/ks7.cfg inst.stage2=$MIRROIR ${CONSOLE}
initrd $PARTBOOT/initrd.img
EOF
NB="$(grep -Ev '^($| *#)' /boot/grub/grub.conf | grep -c title)"
NB=$[$NB-1]
echo -e "savedefault --default=$NB --once\nquit\n" | grub --batch
elif [ -f /boot/grub2/grub.cfg ]; then
if [ $(sed 's/ /\n/g' /proc/cmdline | grep -c console) -gt 1 ]; then
# echo "On ajoute les console pour avoir une config également en serial"
CONSOLE="$(for i in `sed 's/ /\n/g' /proc/cmdline | grep console`; do echo -n "$i "; done | sed 's/ $//')"
fi
#BOOT_DISK="$(df -hP /boot/ | awk '{print $1}' | tail -n1)"
BOOT_DISK="$(mount | grep -e '\s'"`df -h /boot | tail -n1 | awk '{print $6}'`"'\s' | cut -f1 -d\ )"
#BOOT_UUID="$(tune2fs -l ${BOOT_DISK} | grep UUID | awk '{print $3}')"
BOOT_UUID="$(blkid ${BOOT_DISK} | sed 's/.*\sUUID="\([^ ]*\)".*/\1/')"
if [ $(echo "${BOOT_DISK}" | grep -c /dev/md) -eq 1 ]; then
# Pas forcement /dev/md2 !!!
UUID_BOOT_DISK="mduuid/$(mdadm --detail ${BOOT_DISK} | grep UUID | awk '{print $3}' | sed 's/://g')"
else
#echo "UUID_BOOT_DISK non defini" >&2
#exit 1
UUID_BOOT_DISK="${BOOT_UUID}"
fi
cat >> /etc/grub.d/40_custom <<EOF
menuentry 'CentOS 7 Install (PXE)' --unrestricted {
set root='${UUID_BOOT_DISK}'
if [ x\$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint='${UUID_BOOT_DISK}' ${BOOT_UUID}
else
search --no-floppy --fs-uuid --set=root ${BOOT_UUID}
fi
linux $PARTBOOT/vmlinuz ${INST_OPTIONS} inst.ks=http://boot.reslinger.net/ks7.cfg inst.stage2=$MIRROIR ${CONSOLE}
initrd $PARTBOOT/initrd.img
}
EOF
# ksdevice=MAC Replaced with BO O T IF= MAC ?
# kernel $PARTBOOT/vmlinuz install=http://centos.arcticnetwork.ca/6.4/os/$ARCH/ hostip=88... gateway=88... usessh=1 sshpassword=123456789
grub2-mkconfig --output=/boot/grub2/grub.cfg
#NB="$(grep -Ev '^($| *#)' /boot/grub2/grub.cfg | grep -c ^menuentry)"
#NB=$[$NB-1]
#grub2-reboot $NB
grub2-reboot 'CentOS 7 Install (PXE)'
else
echo "Bootloader non identifié !" >&2
exit 1
fi
# avec tigervnc:
# vncviewer CompressLevel 9 FullColor 176.31.103.156:1