Work on modular installer

This commit is contained in:
Joshua Boniface 2023-09-01 15:41:56 -04:00
parent b3d2580eeb
commit 0dcb39a2f5
3 changed files with 411 additions and 278 deletions

35
install.seed.example Normal file
View File

@ -0,0 +1,35 @@
###
### General definitions
###
# The Debian release to use
debrelease="bullseye"
# The Debian mirror to use
debmirror="http://debian.mirror.rafal.ca/debian"
# Package list (installed during debootstrap)
debpkglist="lvm2,parted,gdisk,grub-pc,grub-efi-amd64,linux-image-amd64,sudo,vim,gpg,gpg-agent,aptitude,openssh-server,vlan,ifenslave,python2,python3,ca-certificates,ntp"
# Package list (installed in chroot)
suppkglist="firmware-linux,firmware-linux-nonfree,firmware-bnx2,firmware-bnx2x"
###
### Per-host definitions
###
# The hostname of the system (set per-run)
target_hostname="HOSTNAME"
# The target disk (either path or model to find; path overrides model if set)
target_disk_path="/dev/disk/by-path/pci-0000:01:00.0-scsi-0:2:0:0" # Example: Dell BOSS on R6515 via explicit path
target_disk_model="DELLBOSS VD" # Example: Dell BOSS on R6515 via model name
# SSH key method (usually tftp)
target_keys_method="tftp"
# SSH key path
target_keys_path="keys.txt"
# Deploy username
target_deploy_user="deploy"

View File

@ -6,10 +6,13 @@ if [[ $( whoami ) != "root" ]]; then
exit 1 exit 1
fi fi
logfile="/tmp/pvc-install.log" iso_name="XXDATEXX"
target_deploy_user="XXDEPLOYUSERXX"
supported_debrelease="buster bullseye" supported_debrelease="buster bullseye"
default_debrelease="buster" default_debrelease="buster"
default_debmirror="http://debian.mirror.rafal.ca/debian" default_debmirror="http://debian.mirror.rafal.ca/debian"
debpkglist="lvm2,parted,gdisk,grub-pc,grub-efi-amd64,linux-image-amd64,sudo,vim,gpg,gpg-agent,aptitude,openssh-server,vlan,ifenslave,python2,python3,ca-certificates,ntp" debpkglist="lvm2,parted,gdisk,grub-pc,grub-efi-amd64,linux-image-amd64,sudo,vim,gpg,gpg-agent,aptitude,openssh-server,vlan,ifenslave,python2,python3,ca-certificates,ntp"
suppkglist="firmware-linux,firmware-linux-nonfree,firmware-bnx2,firmware-bnx2x" suppkglist="firmware-linux,firmware-linux-nonfree,firmware-bnx2,firmware-bnx2x"
@ -20,11 +23,85 @@ suppkglist="firmware-linux,firmware-linux-nonfree,firmware-bnx2,firmware-bnx2x"
# roles will overwrite it by default during configuration. # roles will overwrite it by default during configuration.
root_password="hCb1y2PF" root_password="hCb1y2PF"
# Obtain the mode from the kernel command line
kernel_cmdline=$( cat /proc/cmdline )
install_option="$( awk '{
for(i=1; i<=NF; i++) {
if($i ~ /pvcinstall.preseed/) {
print $i;
}
}
}' <<<"${kernel_cmdline}" | awk -F'=' '{ print $NF }' )"
seed_config() {
echo "Hello ${1}"
seed_vlan="$( awk '{
for(i=1; i<=NF; i++) {
if($i ~ /pvcinstall.seed_vlan/) {
print $i;
}
}
}' <<<"${kernel_cmdline}" | awk -F'=' '{ print $NF }' )"
seed_host="$( awk '{
for(i=1; i<=NF; i++) {
if($i ~ /pvcinstall.seed_host/) {
print $i;
}
}
}' <<<"${kernel_cmdline}" | awk -F'=' '{ print $NF }' )"
seed_file="$( awk '{
for(i=1; i<=NF; i++) {
if($i ~ /pvcinstall.seed_file/) {
print $i;
}
}
}' <<<"${kernel_cmdline}" | awk -F'=' '{ print $NF }' )"
if [[ -n ${seed_vlan} ]]; then
modprobe 8021q
fi
# Perform DHCP on all interfaces to come online
for interface in $( ip address | grep '^[0-9]' | grep 'eno\|enp\|ens\|wlp' | awk '{ print $2 }' | tr -d ':' ); do
ip link set ${interface} up
if [[ -n ${seed_vlan} ]]; then
vconfig add ${interface} ${seed_vlan}
dhclient ${interface}.${seed_vlan}
else
dhclient ${interface}
fi
done
# Fetch the seed config
tftp -m binary "${seed_host}" -c get "${seed_file}" /tmp/install.seed
. /tmp/install.seed
# Handle the target disk
if [[ -n ${target_disk_path} ]]; then
target_disk="$( readlink ${target_disk_path} )"
if [[ ! -b ${target_disk} ]]; then
echo "Invalid disk!"
exit 1
fi
else
# Find the (first) disk with the given model
for disk in /dev/sd?; do
disk_model="$( fdisk -l ${disk} | grep 'Disk model:' | sed 's/Disk model: //g' )"
if [[ ${disk_model} == ${target_disk_model} ]]; then
target_disk="${disk}"
break
fi
done
fi
}
interactive_config() {
clear clear
echo "--------------------------------------------------------" echo "-----------------------------------------------------"
echo "| PVC Node installer (XXDATEXX) |" echo "| PVC Node installer (${iso_name}) |"
echo "--------------------------------------------------------" echo "-----------------------------------------------------"
echo echo
echo "This LiveCD will install a PVC node base system ready for bootstrapping with 'pvc-ansible'." echo "This LiveCD will install a PVC node base system ready for bootstrapping with 'pvc-ansible'."
echo echo
@ -262,6 +339,7 @@ while [[ -z ${debmirror} ]]; do
echo echo
done done
target_keys_method="wget"
echo "5) Please enter an HTTP URL containing a text list of SSH authorized keys to" echo "5) Please enter an HTTP URL containing a text list of SSH authorized keys to"
echo "fetch. These keys will be allowed access to the deployment user 'XXDEPLOYUSER'" echo "fetch. These keys will be allowed access to the deployment user 'XXDEPLOYUSER'"
echo "via SSH." echo "via SSH."
@ -269,12 +347,12 @@ echo ""
echo "Leave blank to bypass this and use a password instead." echo "Leave blank to bypass this and use a password instead."
echo echo
echo -n "> " echo -n "> "
read target_keys_url read target_keys_path
if [[ -z ${target_keys_url} ]]; then if [[ -z ${target_keys_path} ]]; then
echo echo
echo "No SSH keys URL specified. Falling back to password configuration." echo "No SSH keys URL specified. Falling back to password configuration."
echo echo
echo "5) Please enter a password (hidden), twice, for the deployment user 'XXDEPLOYUSERXX'." echo "5) Please enter a password (hidden), twice, for the deployment user '${target_deploy_user}'."
while [[ -z "${target_password}" ]]; do while [[ -z "${target_password}" ]]; do
echo echo
echo -n "> " echo -n "> "
@ -291,17 +369,28 @@ if [[ -z ${target_keys_url} ]]; then
fi fi
done done
else else
while ! wget -O /dev/null ${target_keys_url} &>/dev/null; do while ! wget -O /dev/null ${target_keys_path} &>/dev/null; do
echo echo
echo "Please enter a valid SSH keys URL." echo "Please enter a valid SSH keys URL."
echo echo
echo -n "> " echo -n "> "
read target_keys_url read target_keys_path
done done
echo echo
echo "SSH key source '${target_keys_url}' successfully validated." echo "SSH key source '${target_keys_path}' successfully validated."
fi fi
echo echo
}
case ${install_option} in
on)
seed_config
;;
*)
interactive_config
;;
esac
titlestring_text="| Proceeding with installation of host '${target_hostname}'. |" titlestring_text="| Proceeding with installation of host '${target_hostname}'. |"
titlestring_len="$(( $( wc -c <<<"${titlestring_text}" ) - 2 ))" titlestring_len="$(( $( wc -c <<<"${titlestring_text}" ) - 2 ))"
@ -314,6 +403,8 @@ echo
echo "LOGFILE: ${logfile}" echo "LOGFILE: ${logfile}"
echo echo
exit 0
set -o errexit set -o errexit
exec 1> >( tee -ia ${logfile} ) exec 1> >( tee -ia ${logfile} )
exec 2> >( tee -ia ${logfile} >/dev/null ) exec 2> >( tee -ia ${logfile} >/dev/null )
@ -480,14 +571,21 @@ echo "done."
echo -n "Adding deployment user... " echo -n "Adding deployment user... "
mv ${target}/home ${target}/var/home >&2 mv ${target}/home ${target}/var/home >&2
chroot ${target} useradd -u 200 -d /var/home/XXDEPLOYUSERXX -m -s /bin/bash -g operator -G sudo XXDEPLOYUSERXX >&2 chroot ${target} useradd -u 200 -d /var/home/${target_deploy_user} -m -s /bin/bash -g operator -G sudo ${target_deploy_user} >&2
chroot ${target} mkdir -p /var/home/XXDEPLOYUSERXX/.ssh chroot ${target} mkdir -p /var/home/${target_deploy_user}/.ssh
if [[ -n ${target_keys_url} ]]; then if [[ -n ${target_keys_path} ]]; then
wget -O ${target}/var/home/XXDEPLOYUSERXX/.ssh/authorized_keys ${target_keys_url} case ${target_keys_method} in
chroot ${target} chmod 0600 /var/home/XXDEPLOYUSERXX/.ssh/authorized_keys wget)
chroot ${target} chown -R XXDEPLOYUSERXX:operator /var/home/XXDEPLOYUSERXX wget -O ${target}/var/home/${target_deploy_user}/.ssh/authorized_keys ${target_keys_path}
;;
tftp)
tftp -m binary "${seed_host}" -c get "${target_keys_path}" ${target}/var/home/${target_deploy_user}/.ssh/authorized_keys
;;
esac
chroot ${target} chmod 0600 /var/home/${target_deploy_user}/.ssh/authorized_keys
chroot ${target} chown -R ${target_deploy_user}:operator /var/home/${target_deploy_user}
else else
echo "XXDEPLOYUSERXX:${target_password}" | chroot ${target} chpasswd >&2 echo "${target_deploy_user}:${target_password}" | chroot ${target} chpasswd >&2
fi fi
echo "done." echo "done."

0
pxelinux.0 Normal file
View File