From 2705ea92439dab9d3c0a2e4ea073b4e61b0a8179 Mon Sep 17 00:00:00 2001 From: Eliezer Croitoru Date: Tue, 14 Nov 2023 21:52:09 +0200 Subject: [PATCH] 2 --- alma-disk-from-qcow/Makefile | 20 +++++++++++ alma-disk-from-qcow/fix-gpt-free-space.sh | 3 ++ debian-disk-from-qcow/Makefile | 17 ++++++++++ debian-disk-from-qcow/fix-gpt-free-space.sh | 3 ++ gen-cloud-init/.gitignore | 4 +++ gen-cloud-init/LICENSE | 22 +++++++++++++ gen-cloud-init/Makefile | 27 +++++++++++++++ gen-cloud-init/SSH_KEY1 | 1 + gen-cloud-init/SSH_KEY2 | 1 + gen-cloud-init/SSH_KEY3 | 1 + gen-cloud-init/build.sh | 32 ++++++++++++++++++ .../gen-hostname-and-instance-id.sh | 13 ++++++++ gen-cloud-init/meta-data-debian | 2 ++ gen-cloud-init/meta-data-rhel | 2 ++ gen-cloud-init/replace.rb | 10 ++++++ gen-cloud-init/user-data-debian | 31 +++++++++++++++++ gen-cloud-init/user-data-rhel | 33 +++++++++++++++++++ rocky-disk-from-qcow/Makefile | 26 +++++++++++++++ rocky-disk-from-qcow/fix-gpt-free-space.sh | 3 ++ ubuntu-disk-from-qcow/Makefile | 11 +++++++ ubuntu-disk-from-qcow/fix-gpt-free-space.sh | 3 ++ 21 files changed, 265 insertions(+) create mode 100644 alma-disk-from-qcow/Makefile create mode 100644 alma-disk-from-qcow/fix-gpt-free-space.sh create mode 100644 debian-disk-from-qcow/Makefile create mode 100644 debian-disk-from-qcow/fix-gpt-free-space.sh create mode 100644 gen-cloud-init/.gitignore create mode 100644 gen-cloud-init/LICENSE create mode 100644 gen-cloud-init/Makefile create mode 100644 gen-cloud-init/SSH_KEY1 create mode 100644 gen-cloud-init/SSH_KEY2 create mode 100644 gen-cloud-init/SSH_KEY3 create mode 100644 gen-cloud-init/build.sh create mode 100644 gen-cloud-init/gen-hostname-and-instance-id.sh create mode 100644 gen-cloud-init/meta-data-debian create mode 100644 gen-cloud-init/meta-data-rhel create mode 100644 gen-cloud-init/replace.rb create mode 100644 gen-cloud-init/user-data-debian create mode 100644 gen-cloud-init/user-data-rhel create mode 100644 rocky-disk-from-qcow/Makefile create mode 100644 rocky-disk-from-qcow/fix-gpt-free-space.sh create mode 100644 ubuntu-disk-from-qcow/Makefile create mode 100644 ubuntu-disk-from-qcow/fix-gpt-free-space.sh diff --git a/alma-disk-from-qcow/Makefile b/alma-disk-from-qcow/Makefile new file mode 100644 index 0000000..9b56deb --- /dev/null +++ b/alma-disk-from-qcow/Makefile @@ -0,0 +1,20 @@ +install-dependencies: + dnf install -y wget qemu-img + +download-alam-9-bios-image: + wget https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2 -O /tmp/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2 + ln -s /tmp/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2 /tmp/almalinux.qcow2 + +download-alam-8-uefi-image: + wget https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-UEFI-latest.x86_64.qcow2 -O /tmp/AlmaLinux-8-GenericCloud-UEFI-latest.x86_64.qcow2 + ln -s /tmp/AlmaLinux-8-GenericCloud-UEFI-latest.x86_64.qcow2 /tmp/almalinux.qcow2 + +download-alam-8-bios-image: + wget https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2 -O /tmp/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2 + ln -s /tmp/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2 /tmp/almalinux.qcow2 + +write-image-to-sda: + qemu-img convert -p -f qcow2 -O raw /tmp/almalinux.qcow2 /dev/sda + +fix-gpt: + /bin/sh fix-gpt-free-space.sh diff --git a/alma-disk-from-qcow/fix-gpt-free-space.sh b/alma-disk-from-qcow/fix-gpt-free-space.sh new file mode 100644 index 0000000..4d2c533 --- /dev/null +++ b/alma-disk-from-qcow/fix-gpt-free-space.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +printf "fix\n" | parted ---pretend-input-tty /dev/sda print diff --git a/debian-disk-from-qcow/Makefile b/debian-disk-from-qcow/Makefile new file mode 100644 index 0000000..3cd14b5 --- /dev/null +++ b/debian-disk-from-qcow/Makefile @@ -0,0 +1,17 @@ +install-dependencies: + dnf install -y wget qemu-img + +download-10-image: + wget https://cloud.debian.org/images/cloud/buster/latest/debian-10-generic-amd64.qcow2 -O /tmp/debian-cloudimg-amd64.qcow2 + +download-11-image: + wget https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.qcow2 -O /tmp/debian-cloudimg-amd64.qcow2 + +download-12-image: + wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2 -O /tmp/debian-cloudimg-amd64.qcow2 + +write-image-to-sda: + qemu-img convert -p -f qcow2 -O raw /tmp/debian-cloudimg-amd64.qcow2 /dev/sda + +fix-gpt: + /bin/sh fix-gpt-free-space.sh diff --git a/debian-disk-from-qcow/fix-gpt-free-space.sh b/debian-disk-from-qcow/fix-gpt-free-space.sh new file mode 100644 index 0000000..4d2c533 --- /dev/null +++ b/debian-disk-from-qcow/fix-gpt-free-space.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +printf "fix\n" | parted ---pretend-input-tty /dev/sda print diff --git a/gen-cloud-init/.gitignore b/gen-cloud-init/.gitignore new file mode 100644 index 0000000..0be2d4d --- /dev/null +++ b/gen-cloud-init/.gitignore @@ -0,0 +1,4 @@ +build.log +init.iso +*-init-*.*.iso +tmp/ diff --git a/gen-cloud-init/LICENSE b/gen-cloud-init/LICENSE new file mode 100644 index 0000000..080041d --- /dev/null +++ b/gen-cloud-init/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2022 Eliezer Croitoru + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/gen-cloud-init/Makefile b/gen-cloud-init/Makefile new file mode 100644 index 0000000..fc6dec1 --- /dev/null +++ b/gen-cloud-init/Makefile @@ -0,0 +1,27 @@ +all: + echo OK + +rhel: + cp -fv user-data-rhel user-data + cp -fv meta-data-rhel meta-data + bash ./build.sh rhel-master-init.iso + +deploy-rhel: + cp -fv rhel-master-init.iso ./isos/ + +debian: + cp -fv user-data-debian user-data + cp -fv meta-data-debian meta-data + bash ./build.sh debian-master-init.iso + +deploy-debian: + cp -fv debian-master-init.iso ./isos/ + +ubuntu: + cp -fv user-data-ubuntu user-data + cp -fv meta-data-ubuntu meta-data + bash ./build.sh ubuntu-master-init.iso + +deploy-ubuntu: + cp -fv ubuntu-master-init.iso ./isos/ + diff --git a/gen-cloud-init/SSH_KEY1 b/gen-cloud-init/SSH_KEY1 new file mode 100644 index 0000000..e3e1efa --- /dev/null +++ b/gen-cloud-init/SSH_KEY1 @@ -0,0 +1 @@ +ssh-rsa testkey user@DESKTOP-1 \ No newline at end of file diff --git a/gen-cloud-init/SSH_KEY2 b/gen-cloud-init/SSH_KEY2 new file mode 100644 index 0000000..e3e1efa --- /dev/null +++ b/gen-cloud-init/SSH_KEY2 @@ -0,0 +1 @@ +ssh-rsa testkey user@DESKTOP-1 \ No newline at end of file diff --git a/gen-cloud-init/SSH_KEY3 b/gen-cloud-init/SSH_KEY3 new file mode 100644 index 0000000..e3e1efa --- /dev/null +++ b/gen-cloud-init/SSH_KEY3 @@ -0,0 +1 @@ +ssh-rsa testkey user@DESKTOP-1 \ No newline at end of file diff --git a/gen-cloud-init/build.sh b/gen-cloud-init/build.sh new file mode 100644 index 0000000..e7495a0 --- /dev/null +++ b/gen-cloud-init/build.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +FILENAME="init-$(date -u '+%Y%m%d')_$(uuidgen |cut -d '-' -f 1).iso" + +if [ $# -eq 1 ]; then + FILENAME="$1" + echo "Building image to ${FILENAME} ..." +elif [ $# -gt 1 ]; then + echo 'Usage: ./build.sh [filename]' + exit 1 +else + echo "Building image to ${FILENAME} ..." +fi + +SSH_KEY1=$(head -1 "SSH_KEY1") +SSH_KEY2=$(head -1 "SSH_KEY2") +SSH_KEY3=$(head -1 "SSH_KEY3") + +cat user-data | ruby replace.rb "###SSH_KEY_1###" "${SSH_KEY1}" | ruby replace.rb "###SSH_KEY_2###" "${SSH_KEY2}" | ruby replace.rb "###SSH_KEY_3###" "${SSH_KEY3}" > user-data.in && \ + cp -vf user-data.in user-data + +cloud-init devel schema --config-file user-data + +genisoimage -output ${FILENAME} -volid cidata -joliet -rock user-data meta-data + +FILESIZE=$(stat -c %s ${FILENAME} 2>/dev/null) +if [[ "${FILESIZE}" -gt "0" ]]; then + printf '%s (%d bytes) ... done!\n' ${FILENAME} ${FILESIZE} +else + printf 'Something went wrong while trying to make %s\n' ${FILENAME} +fi + diff --git a/gen-cloud-init/gen-hostname-and-instance-id.sh b/gen-cloud-init/gen-hostname-and-instance-id.sh new file mode 100644 index 0000000..77b6514 --- /dev/null +++ b/gen-cloud-init/gen-hostname-and-instance-id.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +OS_DISTRO="$1" + +if [ -z "${OS_DISTRO}" ];then + OS_DISTRO="generic" +fi + +INSTANCE_ID="$( uuidgen |cut -d '-' -f 1 )" +HOSTNAME="$(OS_DISTRO)-${INSTANCE_ID}" + +cat meta-data | ruby replace.rb "##INSTANCE_ID##" "${INSTANCE_ID}" | ruby replace.rb "##HOSTNAME##" "${HOSTNAME}" > meta-data.in && \ + cp -vf meta-data.in > meta-data \ No newline at end of file diff --git a/gen-cloud-init/meta-data-debian b/gen-cloud-init/meta-data-debian new file mode 100644 index 0000000..ee3fee3 --- /dev/null +++ b/gen-cloud-init/meta-data-debian @@ -0,0 +1,2 @@ +instance-id: ##INSTANCE_ID## +local-hostname: ##HOSTNAME## diff --git a/gen-cloud-init/meta-data-rhel b/gen-cloud-init/meta-data-rhel new file mode 100644 index 0000000..7221c11 --- /dev/null +++ b/gen-cloud-init/meta-data-rhel @@ -0,0 +1,2 @@ +instance-id: ##INSTANCE_ID## +local-hostname: ##HOSTNAME## \ No newline at end of file diff --git a/gen-cloud-init/replace.rb b/gen-cloud-init/replace.rb new file mode 100644 index 0000000..5c405d0 --- /dev/null +++ b/gen-cloud-init/replace.rb @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +input = ARGV[0] +output = ARGV[1] + +STDOUT.sync = true + +while line = STDIN.gets + puts line.gsub("#{input}", "#{output}") +end \ No newline at end of file diff --git a/gen-cloud-init/user-data-debian b/gen-cloud-init/user-data-debian new file mode 100644 index 0000000..7d89d7e --- /dev/null +++ b/gen-cloud-init/user-data-debian @@ -0,0 +1,31 @@ +#cloud-config + +# remove this block entirely if not using password authentication +password: ###PASSWORD### +ssh_pwauth: True +chpasswd: { expire: False } + +package_upgrade: true +packages: +- git +- htop +- tmux +- wget + +# replace with your own public key (e.g. ~/.ssh/id_rsa.pub) +ssh_authorized_keys: + - ###SSH_KEY_1### + - ###SSH_KEY_2### + - ###SSH_KEY_3### + +users: + - default + - name: root + ssh_authorized_keys: + - ###SSH_KEY_1### + - ###SSH_KEY_2### + - ###SSH_KEY_3### +runcmd: + - [ "/usr/bin/wget" , "https://raw.githubusercontent.com/elico/ispmail-project/master/debian-bullseye-il-sources.list" , "-O" , "/etc/apt/sources.list.debian-11.in" ] + +final_message: "The system is finally up, after $UPTIME seconds" diff --git a/gen-cloud-init/user-data-rhel b/gen-cloud-init/user-data-rhel new file mode 100644 index 0000000..47fca8f --- /dev/null +++ b/gen-cloud-init/user-data-rhel @@ -0,0 +1,33 @@ +#cloud-config + +# remove this block entirely if not using password authentication +password: ###PASSWORD### +ssh_pwauth: True +chpasswd: { expire: False } + +#package_upgrade: true +#packages: +#- git +#- tmux +#- wget + +# replace with your own public key (e.g. ~/.ssh/id_rsa.pub) +ssh_authorized_keys: + - ###SSH_KEY_1### + - ###SSH_KEY_2### + - ###SSH_KEY_3### + +users: + - default + - name: root + ssh_authorized_keys: + - ###SSH_KEY_1### + - ###SSH_KEY_2### + - ###SSH_KEY_3### + +runcmd: + - [ "/usr/bin/curl" , "https://gist.githubusercontent.com/elico/aa7cf0bf563361b72afe9cadafdbf688/raw/7ca31701051cd3bfd8974cfd31eaaeaa32b4c4c0/rhel-create-swap-file.sh" , "-o" , "/usr/loca/bin/rhel-create-swap-file.sh" ] + - [ "/bin/bash" , "/usr/loca/bin/rhel-create-swap-file.sh" ] + - [ "/usr/bin/curl" , "http://www.ngtech.co.il/static/finihsed" , "-o" , "/dev/null" ] + +final_message: "The system is finally up, after $UPTIME seconds" diff --git a/rocky-disk-from-qcow/Makefile b/rocky-disk-from-qcow/Makefile new file mode 100644 index 0000000..7aabf96 --- /dev/null +++ b/rocky-disk-from-qcow/Makefile @@ -0,0 +1,26 @@ +install-dependencies: + dnf install -y wget qemu-img + +download-rocky-8-base-image: + wget https://download.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2 -O /tmp/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2 + ln -s /tmp/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2 /tmp/rocky.qcow2 + +download-rocky-8-lvm-image: + wget https://download.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-EC2-LVM.latest.x86_64.qcow2 -O /tmp/Rocky-8-EC2-LVM.latest.x86_64.qcow2 + ln -s /tmp/Rocky-8-EC2-LVM.latest.x86_64.qcow2 /tmp/rocky.qcow2 + +download-rocky-9-base-image: + wget https://download.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2 -O /tmp/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2 + ln -s /tmp/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2 /tmp/rocky.qcow2 + +download-rocky-9-lvm-image: + wget https://download.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-LVM.latest.x86_64.qcow2 -O /tmp/Rocky-9-GenericCloud-LVM.latest.x86_64.qcow2 + ln -s /tmp/Rocky-9-GenericCloud-LVM.latest.x86_64.qcow2 /tmp/rocky.qcow2 + +write-image-to-sda: + qemu-img convert -p -f qcow2 -O raw /tmp/rocky.qcow2 /dev/sda + +fix-gpt: + /bin/sh fix-gpt-free-space.sh +reboot: + reboot diff --git a/rocky-disk-from-qcow/fix-gpt-free-space.sh b/rocky-disk-from-qcow/fix-gpt-free-space.sh new file mode 100644 index 0000000..4d2c533 --- /dev/null +++ b/rocky-disk-from-qcow/fix-gpt-free-space.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +printf "fix\n" | parted ---pretend-input-tty /dev/sda print diff --git a/ubuntu-disk-from-qcow/Makefile b/ubuntu-disk-from-qcow/Makefile new file mode 100644 index 0000000..083b9b6 --- /dev/null +++ b/ubuntu-disk-from-qcow/Makefile @@ -0,0 +1,11 @@ +install-dependencies: + dnf install -y wget qemu-img + +download-image: + wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img -O /tmp/jammy-server-cloudimg-amd64.img + +write-image-to-sda: + qemu-img convert -p -f qcow2 -O raw /tmp/jammy-server-cloudimg-amd64.img /dev/sda + +fix-gpt: + /bin/sh fix-gpt-free-space.sh diff --git a/ubuntu-disk-from-qcow/fix-gpt-free-space.sh b/ubuntu-disk-from-qcow/fix-gpt-free-space.sh new file mode 100644 index 0000000..4d2c533 --- /dev/null +++ b/ubuntu-disk-from-qcow/fix-gpt-free-space.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +printf "fix\n" | parted ---pretend-input-tty /dev/sda print