diff options
Diffstat (limited to 'others/vm3/.config/cloud-init-generator/debian12.sh')
| -rwxr-xr-x | others/vm3/.config/cloud-init-generator/debian12.sh | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/others/vm3/.config/cloud-init-generator/debian12.sh b/others/vm3/.config/cloud-init-generator/debian12.sh deleted file mode 100755 index 6bfa54b..0000000 --- a/others/vm3/.config/cloud-init-generator/debian12.sh +++ /dev/null | |||
| @@ -1,67 +0,0 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # generates user data, meta data, and seed.iso for cloud init. for debian | ||
| 3 | # requires the name of the vm as an argument | ||
| 4 | # | ||
| 5 | # osinfo-query os to list all available vm types to deploy. debian is debian12 | ||
| 6 | # use no cloud and some other tools because cloud init does not work | ||
| 7 | # | ||
| 8 | #qemu-img resize debian-11-generic-amd64.qcow2 +10G # try this if you want to install something big like kde | ||
| 9 | # sudo apt update | ||
| 10 | # sudo apt install kde-plasma-desktop | ||
| 11 | |||
| 12 | # | ||
| 13 | image_url="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.qcow2" | ||
| 14 | sshkeysdir="/root/k" | ||
| 15 | scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir | ||
| 16 | dir_path="/var/lib/libvirt/images/.image_store" | ||
| 17 | src_file="${dir_path}/debian12.qcow2" | ||
| 18 | config_dir="/var/lib/libvirt/images/.temp" | ||
| 19 | user_data="${config_dir}/user-data" | ||
| 20 | meta_data="${config_dir}/meta-data" | ||
| 21 | seed_iso="${config_dir}/seed.iso" | ||
| 22 | # note that cloud init specifically looks for "user-data" and "meta-data" in the seed.iso disk. do not deviate from the naming convention. | ||
| 23 | if [ $# -ne 1 ]; then | ||
| 24 | echo "Usage: $0 <vm-name>" | ||
| 25 | exit 1 | ||
| 26 | fi | ||
| 27 | sudo mkdir -p "$dir_path" # make image store dir | ||
| 28 | sudo mkdir -p "$config_dir" | ||
| 29 | |||
| 30 | [ ! -f "$src_file" ] && echo "source image does not exist! downloading..." && sudo wget -O "$src_file" "$image_url" | ||
| 31 | |||
| 32 | # generate all the lines from the file | ||
| 33 | SSH_INJECT_OPTS=$(find ${sshkeysdir} -name "*.pub" -exec echo "--ssh-inject user:file:{}" \;) | ||
| 34 | |||
| 35 | flag_file="${dir_path}/debian12_customized" | ||
| 36 | |||
| 37 | # NOTE to delete customfile if debqcow2 is deleted. otherwise it will be ambiguous | ||
| 38 | # this to check if image is already customised | ||
| 39 | if [ -f "$flag_file" ]; then | ||
| 40 | echo "Image already customized, skipping customization..." | ||
| 41 | else | ||
| 42 | echo "Customizing image..." | ||
| 43 | # to install virt customise tool | ||
| 44 | sudo dnf install -y libguestfs libguestfs-tools libvirt virt-install virt-manager guestfs-tools | ||
| 45 | export LIBGUESTFS_BACKEND=direct | ||
| 46 | sudo -E virt-customize -a /var/lib/libvirt/images/.image_store/debian12.qcow2 \ | ||
| 47 | --run-command 'useradd -m -s /bin/bash user' \ | ||
| 48 | $SSH_INJECT_OPTS \ | ||
| 49 | --update \ | ||
| 50 | --install openssh-server,git,cloud-guest-utils,tmux \ | ||
| 51 | --run-command 'echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/user' \ | ||
| 52 | --run-command 'sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config' \ | ||
| 53 | --run-command 'sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config' \ | ||
| 54 | --run-command 'cd /home/user && git clone https://git.0nom.ch/keys && chown -R user:user keys && sudo -u user ./keys/add-ssh-keys.sh' \ | ||
| 55 | --run-command 'tee -a /etc/bash.bashrc > /dev/null << "EOF" | ||
| 56 | LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS | ||
| 57 | PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\'' | ||
| 58 | EOF' \ | ||
| 59 | --run-command 'tee -a /home/user/.bashrc > /dev/null << "EOF" | ||
| 60 | LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS | ||
| 61 | PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\'' | ||
| 62 | EOF' \ | ||
| 63 | --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' && \ | ||
| 64 | |||
| 65 | # Create flag file after successful customization | ||
| 66 | sudo touch "$flag_file" | ||
| 67 | fi | ||
