This commit is contained in:
Eliezer Croitoru 2023-11-14 21:52:09 +02:00
parent a06bf88d65
commit 2705ea9243
21 changed files with 265 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
#!/usr/bin/env sh
printf "fix\n" | parted ---pretend-input-tty /dev/sda print

View File

@ -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

View File

@ -0,0 +1,3 @@
#!/usr/bin/env sh
printf "fix\n" | parted ---pretend-input-tty /dev/sda print

4
gen-cloud-init/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
build.log
init.iso
*-init-*.*.iso
tmp/

22
gen-cloud-init/LICENSE Normal file
View File

@ -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.

27
gen-cloud-init/Makefile Normal file
View File

@ -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/

1
gen-cloud-init/SSH_KEY1 Normal file
View File

@ -0,0 +1 @@
ssh-rsa testkey user@DESKTOP-1

1
gen-cloud-init/SSH_KEY2 Normal file
View File

@ -0,0 +1 @@
ssh-rsa testkey user@DESKTOP-1

1
gen-cloud-init/SSH_KEY3 Normal file
View File

@ -0,0 +1 @@
ssh-rsa testkey user@DESKTOP-1

32
gen-cloud-init/build.sh Normal file
View File

@ -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

View File

@ -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

View File

@ -0,0 +1,2 @@
instance-id: ##INSTANCE_ID##
local-hostname: ##HOSTNAME##

View File

@ -0,0 +1,2 @@
instance-id: ##INSTANCE_ID##
local-hostname: ##HOSTNAME##

10
gen-cloud-init/replace.rb Normal file
View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -0,0 +1,3 @@
#!/usr/bin/env sh
printf "fix\n" | parted ---pretend-input-tty /dev/sda print

View File

@ -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

View File

@ -0,0 +1,3 @@
#!/usr/bin/env sh
printf "fix\n" | parted ---pretend-input-tty /dev/sda print