diff options
| author | hc <hc@email.ch> | 2025-01-26 12:14:06 +0800 |
|---|---|---|
| committer | hc <hc@email.ch> | 2025-01-26 12:14:06 +0800 |
| commit | eabf5b889b42ac79c021a692c6bcdb74fafa5c15 (patch) | |
| tree | b4e7ab0de8706274af346323cac79d0d57e110c5 /others/vm3/.config | |
| parent | ff7f42e5b89d6c1cf664ae866f29f790132a7da7 (diff) | |
update
Diffstat (limited to 'others/vm3/.config')
| -rwxr-xr-x | others/vm3/.config/cloud-init-generator/debian12.sh | 4 | ||||
| -rw-r--r-- | others/vm3/.config/cloud-init-generator/rocky9.0.sh | 53 |
2 files changed, 57 insertions, 0 deletions
diff --git a/others/vm3/.config/cloud-init-generator/debian12.sh b/others/vm3/.config/cloud-init-generator/debian12.sh index de0751f..07c3fb7 100755 --- a/others/vm3/.config/cloud-init-generator/debian12.sh +++ b/others/vm3/.config/cloud-init-generator/debian12.sh @@ -49,6 +49,10 @@ else LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\'' EOF' \ + --run-command 'tee -a /home/user/.bashrc > /dev/null << "EOF" +LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS +PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\'' +EOF' \ --run-command 'echo "sudo growpart /dev/vda 1 && sudo resize2fs /dev/vda1 && source /etc/bash.bashrc" > /home/user/start.sh && chmod +x /home/user/start.sh' && \ # Create flag file after successful customization diff --git a/others/vm3/.config/cloud-init-generator/rocky9.0.sh b/others/vm3/.config/cloud-init-generator/rocky9.0.sh new file mode 100644 index 0000000..c880206 --- /dev/null +++ b/others/vm3/.config/cloud-init-generator/rocky9.0.sh @@ -0,0 +1,53 @@ + +#!/bin/bash +# generates user data, meta data, and seed.iso for cloud init. for rocky +# requires the name of the vm as an argument +# +# osinfo-query os to list all available vm types to deploy. rocky is rocky9.0 or similar +image_url="https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2" +sshkeysdir="/root/k" +scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir +dir_path="/var/lib/libvirt/images/.image_store" +src_file="${dir_path}/rocky9.0.qcow2" +config_dir="/var/lib/libvirt/images/.temp" +user_data="${config_dir}/user-data" +meta_data="${config_dir}/meta-data" +seed_iso="${config_dir}/seed.iso" +# note that cloud init specifically looks for "user-data" and "meta-data" in the seed.iso disk. do not deviate from the naming convention. +if [ $# -ne 1 ]; then + echo "Usage: $0 <vm-name>" + exit 1 +fi +sudo mkdir -p "$dir_path" +sudo mkdir -p "$config_dir" +[ ! -f "$src_file" ] && echo "source image does not exist! downloading..." && sudo wget -O "$src_file" "$image_url" +cat > "$user_data" << EOF +#cloud-config +users: + - name: user + ssh-authorized-keys: +EOF +for key in $sshkeysdir/*.pub; do + echo " - $(cat "$key")" >> $user_data +done +cat >> "$user_data" << 'EOF' + sudo: ['ALL=(ALL) NOPASSWD:ALL'] + groups: wheel + shell: /bin/bash +runcmd: + - sudo systemctl enable --now serial-getty@ttyS0.service + - sudo growpart /dev/sda 1 + - sudo xfs_growfs / + - sudo dnf install -y vim git + - cd /home/user + - git clone https://git.0nom.ch/setup + - touch /home/user/runcmd_done +EOF +cat > "$meta_data" << EOF +instance-id: vm_id +local-hostname: $1 +EOF +genisoimage -output "$seed_iso" -volid cidata -joliet -rock "$user_data" "$meta_data" &> /dev/null || { echo "Failed to create seed.iso."; exit 1; } +echo "Configuration files generated successfully" + + |
