diff options
Diffstat (limited to 'others/vm3/.config/cloud-init-generator')
| -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 | |||
| 49 | LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS | 49 | LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS |
| 50 | PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\'' | 50 | PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\'' |
| 51 | EOF' \ | 51 | EOF' \ |
| 52 | --run-command 'tee -a /home/user/.bashrc > /dev/null << "EOF" | ||
| 53 | LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS | ||
| 54 | PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\'' | ||
| 55 | EOF' \ | ||
| 52 | --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' && \ | 56 | --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' && \ |
| 53 | 57 | ||
| 54 | # Create flag file after successful customization | 58 | # 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 @@ | |||
| 1 | |||
| 2 | #!/bin/bash | ||
| 3 | # generates user data, meta data, and seed.iso for cloud init. for rocky | ||
| 4 | # requires the name of the vm as an argument | ||
| 5 | # | ||
| 6 | # osinfo-query os to list all available vm types to deploy. rocky is rocky9.0 or similar | ||
| 7 | image_url="https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2" | ||
| 8 | sshkeysdir="/root/k" | ||
| 9 | scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir | ||
| 10 | dir_path="/var/lib/libvirt/images/.image_store" | ||
| 11 | src_file="${dir_path}/rocky9.0.qcow2" | ||
| 12 | config_dir="/var/lib/libvirt/images/.temp" | ||
| 13 | user_data="${config_dir}/user-data" | ||
| 14 | meta_data="${config_dir}/meta-data" | ||
| 15 | seed_iso="${config_dir}/seed.iso" | ||
| 16 | # note that cloud init specifically looks for "user-data" and "meta-data" in the seed.iso disk. do not deviate from the naming convention. | ||
| 17 | if [ $# -ne 1 ]; then | ||
| 18 | echo "Usage: $0 <vm-name>" | ||
| 19 | exit 1 | ||
| 20 | fi | ||
| 21 | sudo mkdir -p "$dir_path" | ||
| 22 | sudo mkdir -p "$config_dir" | ||
| 23 | [ ! -f "$src_file" ] && echo "source image does not exist! downloading..." && sudo wget -O "$src_file" "$image_url" | ||
| 24 | cat > "$user_data" << EOF | ||
| 25 | #cloud-config | ||
| 26 | users: | ||
| 27 | - name: user | ||
| 28 | ssh-authorized-keys: | ||
| 29 | EOF | ||
| 30 | for key in $sshkeysdir/*.pub; do | ||
| 31 | echo " - $(cat "$key")" >> $user_data | ||
| 32 | done | ||
| 33 | cat >> "$user_data" << 'EOF' | ||
| 34 | sudo: ['ALL=(ALL) NOPASSWD:ALL'] | ||
| 35 | groups: wheel | ||
| 36 | shell: /bin/bash | ||
| 37 | runcmd: | ||
| 38 | - sudo systemctl enable --now serial-getty@ttyS0.service | ||
| 39 | - sudo growpart /dev/sda 1 | ||
| 40 | - sudo xfs_growfs / | ||
| 41 | - sudo dnf install -y vim git | ||
| 42 | - cd /home/user | ||
| 43 | - git clone https://git.0nom.ch/setup | ||
| 44 | - touch /home/user/runcmd_done | ||
| 45 | EOF | ||
| 46 | cat > "$meta_data" << EOF | ||
| 47 | instance-id: vm_id | ||
| 48 | local-hostname: $1 | ||
| 49 | EOF | ||
| 50 | genisoimage -output "$seed_iso" -volid cidata -joliet -rock "$user_data" "$meta_data" &> /dev/null || { echo "Failed to create seed.iso."; exit 1; } | ||
| 51 | echo "Configuration files generated successfully" | ||
| 52 | |||
| 53 | |||
