From 1f67acf077af435f9770d58c5331983c00ede7d3 Mon Sep 17 00:00:00 2001 From: Roberto Berto <463349+robertoberto@users.noreply.github.com> Date: Wed, 15 May 2024 00:51:46 +0000 Subject: vyos installer in 2 stages image1 and image2 --- scripts/vyos/cleanup.sh | 58 +++++++++++++++++++++++++++++++++++ scripts/vyos/cloud-init-datasource.sh | 17 ++++++++++ scripts/vyos/cloud-init-debian.sh | 6 ++++ scripts/vyos/cloud-init-vyos.sh | 8 ++++- scripts/vyos/configure.sh | 24 +++++++++++++++ scripts/vyos/grub-serial.sh | 15 +++++++++ scripts/vyos/vyos-install-expect.sh | 19 ++++++++++++ scripts/vyos/vyos-install-pre.sh | 56 --------------------------------- scripts/vyos/vyos-install.sh | 19 ------------ 9 files changed, 146 insertions(+), 76 deletions(-) create mode 100644 scripts/vyos/cleanup.sh create mode 100644 scripts/vyos/cloud-init-datasource.sh create mode 100644 scripts/vyos/configure.sh create mode 100644 scripts/vyos/grub-serial.sh create mode 100644 scripts/vyos/vyos-install-expect.sh delete mode 100644 scripts/vyos/vyos-install-pre.sh delete mode 100644 scripts/vyos/vyos-install.sh (limited to 'scripts') diff --git a/scripts/vyos/cleanup.sh b/scripts/vyos/cleanup.sh new file mode 100644 index 0000000..6ccf753 --- /dev/null +++ b/scripts/vyos/cleanup.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -e +set -x + +export DEBIAN_FRONTEND=noninteractive + +# delete interfaces ethernet eth0 address +# delete interfaces ethernet eth0 hw-id +# delete system name-server + +cat < /home/vyos/cleanup-vyos.sh +#!/bin/vbash +source /opt/vyatta/etc/functions/script-template +configure +set system host-name 'test' +commit +save +exit +EOF +chmod 0700 /home/vyos/cleanup-vyos.sh +chown vyos:users /home/vyos/cleanup-vyos.sh +su - vyos -c "/home/vyos/cleanup-vyos.sh" + +# reconfiguring ssh +rm -f /etc/ssh/ssh_host_* +dpkg-reconfigure openssh-server + +# those packages can't be removed since they are needed for next script vyos-install.sh +# apt remove -y \ +# python3-pexpect \ +# expect + +# cleanup apt +rm -f /etc/apt/sources.list.d/debian.list +apt -y autoremove --purge +apt-get clean + +# cleanup machine-id +truncate -s 0 /etc/machine-id + +# removing /tmp files +rm -rf /tmp/* + +# removing log files +rm -rf /var/log/* + +rm -rf /home/vyos/cleanup-vyos.sh + +# removing history +export HISTFILE=0 +rm -f /home/vyos/.bash_history +rm -f /root/.bash_history + +# removing disk data +dd if=/dev/zero of=/EMPTY bs=1M || : +rm -f /EMPTY +sync diff --git a/scripts/vyos/cloud-init-datasource.sh b/scripts/vyos/cloud-init-datasource.sh new file mode 100644 index 0000000..66e5509 --- /dev/null +++ b/scripts/vyos/cloud-init-datasource.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e +set -x + +if [[ "${CLOUD_INIT}" == "debian" || "${CLOUD_INIT}" == "vyos" ]]; then + if [[ "${CLOUD_INIT_DATASOURCE}" == "nocloud_configdrive" ]]; then + cat < /etc/cloud/cloud.cfg.d/99_nocloud_configdrive.cfg +datasource_list: [ NoCloud, ConfigDrive ] +EOF + else + echo "$0 - info: cloud_init_datasource will not run, not supported cloud_init_datasource" + exit 0 + fi +else + echo "$0 - info: cloud_init_datasource will not run, not supported cloud_init" +fi diff --git a/scripts/vyos/cloud-init-debian.sh b/scripts/vyos/cloud-init-debian.sh index 2cf398f..6a66935 100644 --- a/scripts/vyos/cloud-init-debian.sh +++ b/scripts/vyos/cloud-init-debian.sh @@ -21,3 +21,9 @@ apt install -y \ ifupdown systemctl enable cloud-init + +cat < /etc/cloud/cloud.cfg.d/99_pve.cfg +datasource_list: [ NoCloud, ConfigDrive ] +EOF + + diff --git a/scripts/vyos/cloud-init-vyos.sh b/scripts/vyos/cloud-init-vyos.sh index 92be545..0dd3d93 100644 --- a/scripts/vyos/cloud-init-vyos.sh +++ b/scripts/vyos/cloud-init-vyos.sh @@ -19,5 +19,11 @@ apt install -t "$VYOS_RELEASE" --force-yes -y \ cloud-init \ cloud-utils \ ifupdown - systemctl enable cloud-init + + +cat < /etc/cloud/cloud.cfg.d/90_disable_config_stage.cfg +# Disable all config-stage modules +cloud_config_modules: +EOF + diff --git a/scripts/vyos/configure.sh b/scripts/vyos/configure.sh new file mode 100644 index 0000000..2628959 --- /dev/null +++ b/scripts/vyos/configure.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e +set -x + +# export DEBIAN_FRONTEND=noninteractive + +# delete interfaces ethernet eth0 address +# delete interfaces ethernet eth0 hw-id +# delete system name-server + +cat < /home/vyos/configure-vyos.sh +#!/bin/vbash +source /opt/vyatta/etc/functions/script-template +configure +set system host-name 'test' +commit +save +exit +EOF +chmod 0700 /home/vyos/configure-vyos.sh +chown vyos:users /home/vyos/configure-vyos.sh +su - vyos -c "/home/vyos/configure-vyos.sh" + diff --git a/scripts/vyos/grub-serial.sh b/scripts/vyos/grub-serial.sh new file mode 100644 index 0000000..b72b1a8 --- /dev/null +++ b/scripts/vyos/grub-serial.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e +set -x + +if [[ "${GRUB_SERIAL}" -ne 1 ]]; then + echo "$0 - info: grub will keep default=0 (kvm). to use serial add to .env: GRUB_SERIAL=1" + exit 0 +fi + +GRUB_CFG="/boot/grub/grub.cfg" +GRUB_DEFAULT="/etc/default/grub" + +sed -i 's/^set default=.*/set default=1/' $GRUB_CFG +sed -i 's/^set default=.*/set default=1/' $GRUB_DEFAULT diff --git a/scripts/vyos/vyos-install-expect.sh b/scripts/vyos/vyos-install-expect.sh new file mode 100644 index 0000000..aa23064 --- /dev/null +++ b/scripts/vyos/vyos-install-expect.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e +set -x + +# answers_url=http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}/answers.expect +# install_url=http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}/install-image.vsh +install_url=http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}/install-image.py + +# touch /root/answers.expect +# chmod 0600 /root/answers.expect +# wget $answers_url -O /root/answers.expect + +touch /root/install-image.py +chmod 0700 /root/install-image.py +wget $install_url -O /root/install-image.py + +python3 /root/install-image.py + diff --git a/scripts/vyos/vyos-install-pre.sh b/scripts/vyos/vyos-install-pre.sh deleted file mode 100644 index c61905d..0000000 --- a/scripts/vyos/vyos-install-pre.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -set -e -set -x - -export DEBIAN_FRONTEND=noninteractive - -# delete interfaces ethernet eth0 address -# delete interfaces ethernet eth0 hw-id -# delete system name-server - -cat < /home/vyos/cleanup-vyos.sh -#!/bin/vbash -source /opt/vyatta/etc/functions/script-template -configure -set system host-name host-name 'test' -commit -save -exit -EOF -chmod 0700 /home/vyos/cleanup-vyos.sh -chown vyos:users /home/vyos/cleanup-vyos.sh -su - vyos -c "/home/vyos/cleanup-vyos.sh" - -# reconfiguring ssh -rm -f /etc/ssh/ssh_host_* -dpkg-reconfigure openssh-server - -# those packages can't be removed since they are needed for next script vyos-install.sh -# apt remove -y \ -# python3-pexpect \ -# expect - -# cleanup apt -rm -f /etc/apt/sources.list.d/debian.list -apt -y autoremove --purge -apt-get clean - -# cleanup machine-id -truncate -s 0 /etc/machine-id - -# removing /tmp files -rm -rf /tmp/* - -# removing log files -rm -rf /var/log/* - -# removing history -export HISTFILE=0 -rm -f /home/vyos/.bash_history -rm -f /root/.bash_history - -# removing disk data -dd if=/dev/zero of=/EMPTY bs=1M || : -rm -f /EMPTY -sync diff --git a/scripts/vyos/vyos-install.sh b/scripts/vyos/vyos-install.sh deleted file mode 100644 index aa23064..0000000 --- a/scripts/vyos/vyos-install.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -set -e -set -x - -# answers_url=http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}/answers.expect -# install_url=http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}/install-image.vsh -install_url=http://${PACKER_HTTP_IP}:${PACKER_HTTP_PORT}/install-image.py - -# touch /root/answers.expect -# chmod 0600 /root/answers.expect -# wget $answers_url -O /root/answers.expect - -touch /root/install-image.py -chmod 0700 /root/install-image.py -wget $install_url -O /root/install-image.py - -python3 /root/install-image.py - -- cgit v1.2.3