diff options
Diffstat (limited to 'others')
| -rw-r--r-- | others/.vm.sh2.swp | bin | 16384 -> 0 bytes | |||
| -rwxr-xr-x | others/vm3/.config/cloud-init-generator/debian12.sh | 8 | ||||
| -rwxr-xr-x | others/vm3/compute/create.sh | 14 | ||||
| -rwxr-xr-x | others/vm3/compute/ls.sh | 2 | ||||
| -rwxr-xr-x | others/vm3/compute/rm.sh (renamed from others/vm3/compute/delete.sh) | 2 | ||||
| -rw-r--r-- | others/vm3/meta-data | 2 | ||||
| -rw-r--r-- | others/vm3/user-data | 27 | ||||
| -rwxr-xr-x | others/vm3/vm.sh | 5 |
8 files changed, 47 insertions, 13 deletions
diff --git a/others/.vm.sh2.swp b/others/.vm.sh2.swp deleted file mode 100644 index bfa52a2..0000000 --- a/others/.vm.sh2.swp +++ /dev/null | |||
| Binary files differ | |||
diff --git a/others/vm3/.config/cloud-init-generator/debian12.sh b/others/vm3/.config/cloud-init-generator/debian12.sh index 5e4d7fb..de0751f 100755 --- a/others/vm3/.config/cloud-init-generator/debian12.sh +++ b/others/vm3/.config/cloud-init-generator/debian12.sh | |||
| @@ -40,15 +40,17 @@ else | |||
| 40 | --run-command 'useradd -m -s /bin/bash user' \ | 40 | --run-command 'useradd -m -s /bin/bash user' \ |
| 41 | $SSH_INJECT_OPTS \ | 41 | $SSH_INJECT_OPTS \ |
| 42 | --update \ | 42 | --update \ |
| 43 | --install openssh-server,git \ | 43 | --install openssh-server,git,cloud-guest-utils,tmux \ |
| 44 | --run-command 'echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/user' \ | 44 | --run-command 'echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/user' \ |
| 45 | --run-command 'sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config' \ | 45 | --run-command 'sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config' \ |
| 46 | --run-command 'sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config' \ | 46 | --run-command 'sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config' \ |
| 47 | --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' \ | 47 | --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' \ |
| 48 | --run-command 'tee -a /etc/bashrc > /dev/null << "EOF" | 48 | --run-command 'tee -a /etc/bash.bashrc > /dev/null << "EOF" |
| 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 '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 | |||
| 52 | # Create flag file after successful customization | 54 | # Create flag file after successful customization |
| 53 | sudo touch "$flag_file" | 55 | sudo touch "$flag_file" |
| 54 | fi | 56 | fi |
diff --git a/others/vm3/compute/create.sh b/others/vm3/compute/create.sh index a1d84f6..1a0411b 100755 --- a/others/vm3/compute/create.sh +++ b/others/vm3/compute/create.sh | |||
| @@ -49,8 +49,8 @@ xml="${workingdir}/xml" | |||
| 49 | 49 | ||
| 50 | image_dir_path="/var/lib/libvirt/images/.image_store" | 50 | image_dir_path="/var/lib/libvirt/images/.image_store" |
| 51 | src_file="${image_dir_path}/${os}.qcow2" | 51 | src_file="${image_dir_path}/${os}.qcow2" |
| 52 | new_vm_dir="/var/lib/libvirt/images/${vmname}" | 52 | new_vm_config_dir="/var/lib/libvirt/images/${vmname}.config" |
| 53 | new_vm="${new_vm_dir}/${vmname}.qcow2" | 53 | new_vm="/var/lib/libvirt/images/${vmname}.qcow2" |
| 54 | 54 | ||
| 55 | # Check mandatory arguments, basicaly checking for initial 1 argument. if it dont exist, vmname will be null | 55 | # Check mandatory arguments, basicaly checking for initial 1 argument. if it dont exist, vmname will be null |
| 56 | # image is os!! | 56 | # image is os!! |
| @@ -75,7 +75,7 @@ if [ ! -f "${src_file}" ]; then | |||
| 75 | exit 1 | 75 | exit 1 |
| 76 | fi | 76 | fi |
| 77 | 77 | ||
| 78 | sudo mkdir -p $new_vm_dir | 78 | sudo mkdir -p $new_vm_config_dir |
| 79 | 79 | ||
| 80 | sudo cp "$src_file" "$new_vm" &> /dev/null || { echo "Failed to create a new image."; exit 1; } | 80 | sudo cp "$src_file" "$new_vm" &> /dev/null || { echo "Failed to create a new image."; exit 1; } |
| 81 | 81 | ||
| @@ -90,11 +90,12 @@ fi | |||
| 90 | 90 | ||
| 91 | # Define the disk options based on OS type | 91 | # Define the disk options based on OS type |
| 92 | if [ "$os" = "debian12" ]; then | 92 | if [ "$os" = "debian12" ]; then |
| 93 | disk_opts="--disk path=$new_vm,format=qcow2" | 93 | disk_opts="--disk path=${new_vm},format=qcow2" |
| 94 | else | 94 | else |
| 95 | disk_opts="--disk path=$new_vm,format=qcow2 --disk path=$seed_iso,device=cdrom" | 95 | disk_opts="--disk path=${new_vm},format=qcow2 --disk path=$seed_iso,device=cdrom" |
| 96 | fi | 96 | fi |
| 97 | 97 | ||
| 98 | |||
| 98 | # Use the conditional disk options in virt-install | 99 | # Use the conditional disk options in virt-install |
| 99 | sudo virt-install --name $vmname \ | 100 | sudo virt-install --name $vmname \ |
| 100 | --vcpus $vcpu \ | 101 | --vcpus $vcpu \ |
| @@ -105,7 +106,8 @@ sudo virt-install --name $vmname \ | |||
| 105 | --virt-type kvm \ | 106 | --virt-type kvm \ |
| 106 | --graphics none \ | 107 | --graphics none \ |
| 107 | --network bridge=virbr0,model=virtio \ | 108 | --network bridge=virbr0,model=virtio \ |
| 108 | --print-xml > $xml || { sudo rm -rf $new_vm_dir; exit 1; } | 109 | --print-xml > $xml || { sudo rm -rf $new_vm; exit 1; } |
| 110 | # if you want this in a new storage pool, move it to a new storage pool after initialisation | ||
| 109 | 111 | ||
| 110 | sudo virsh define $xml #&> /dev/null || { echo "Failed to define the new VM."; exit 1; } | 112 | sudo virsh define $xml #&> /dev/null || { echo "Failed to define the new VM."; exit 1; } |
| 111 | 113 | ||
diff --git a/others/vm3/compute/ls.sh b/others/vm3/compute/ls.sh index b62ef14..b821fd1 100755 --- a/others/vm3/compute/ls.sh +++ b/others/vm3/compute/ls.sh | |||
| @@ -27,7 +27,7 @@ for vm in $vms; do | |||
| 27 | sudo virsh domstate "$vm" 2>/dev/null > /tmp/state.$$ & | 27 | sudo virsh domstate "$vm" 2>/dev/null > /tmp/state.$$ & |
| 28 | echo "$xml" | grep "<vcpu" | awk -F'[<>]' '{print $3}' > /tmp/vcpus.$$ & | 28 | echo "$xml" | grep "<vcpu" | awk -F'[<>]' '{print $3}' > /tmp/vcpus.$$ & |
| 29 | echo "$xml" | grep "<memory" | awk -F'[<>]' '{print $3}' | awk '{ printf "%.2f", $1/1048576 }' > /tmp/ram.$$ & | 29 | echo "$xml" | grep "<memory" | awk -F'[<>]' '{print $3}' | awk '{ printf "%.2f", $1/1048576 }' > /tmp/ram.$$ & |
| 30 | sudo du -sk "/var/lib/libvirt/images/${vm}/${vm}.qcow2" 2>/dev/null | awk '{ printf "%.2f", $1/1024/1024 }' > /tmp/disk.$$ & | 30 | sudo du -sk "/var/lib/libvirt/images/${vm}.qcow2" 2>/dev/null | awk '{ printf "%.2f", $1/1024/1024 }' > /tmp/disk.$$ & |
| 31 | 31 | ||
| 32 | wait | 32 | wait |
| 33 | 33 | ||
diff --git a/others/vm3/compute/delete.sh b/others/vm3/compute/rm.sh index dd65379..f77831c 100755 --- a/others/vm3/compute/delete.sh +++ b/others/vm3/compute/rm.sh | |||
| @@ -22,6 +22,6 @@ fi | |||
| 22 | for vm in "$@"; do | 22 | for vm in "$@"; do |
| 23 | sudo virsh destroy "$vm" &>/dev/null | 23 | sudo virsh destroy "$vm" &>/dev/null |
| 24 | sudo virsh undefine "$vm" --remove-all-storage &>/dev/null | 24 | sudo virsh undefine "$vm" --remove-all-storage &>/dev/null |
| 25 | sudo rm -rf "/var/lib/libvirt/images/${vm}" &>/dev/null | 25 | #sudo rm -rf "/var/lib/libvirt/images/${vm}" &>/dev/null |
| 26 | printf "%-50s%10s\n" "Removing $vm..." $([[ $? -eq 0 ]] && echo "Successful" || echo "Failed") | 26 | printf "%-50s%10s\n" "Removing $vm..." $([[ $? -eq 0 ]] && echo "Successful" || echo "Failed") |
| 27 | done | 27 | done |
diff --git a/others/vm3/meta-data b/others/vm3/meta-data new file mode 100644 index 0000000..ce225e1 --- /dev/null +++ b/others/vm3/meta-data | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | instance-id: iid-fedora-vm | ||
| 2 | local-hostname: fedora-cloudimg | ||
diff --git a/others/vm3/user-data b/others/vm3/user-data new file mode 100644 index 0000000..58817da --- /dev/null +++ b/others/vm3/user-data | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #cloud-config | ||
| 2 | users: | ||
| 3 | - name: fedora | ||
| 4 | ssh-authorized-keys: | ||
| 5 | - sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIGoBf5Lj8oDjXaXNrXtO8YVdOLgV2FN/bwiX93VxDmZ0AAAAEnNzaDptYWNtMS1yZXNpZGVudA== macm1-resident | ||
| 6 | - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHPOwh0+Bpkhg2dNKgUWsh0FKeCeI/awegY3sMb/ZAMb x@fedora | ||
| 7 | sudo: ['ALL=(ALL) NOPASSWD:ALL'] | ||
| 8 | groups: wheel | ||
| 9 | shell: /bin/bash | ||
| 10 | runcmd: | ||
| 11 | - echo "#!/bin/bash" > /home/fedora/disk-setup.sh | ||
| 12 | - echo "DISK='/dev/vda'; MOUNT_PATH='/home/ceph5-vda-200G';" >> /home/fedora/disk-setup.sh | ||
| 13 | - echo '[ ! -d $MOUNT_PATH ] && sudo mkdir -p $MOUNT_PATH;' >> /home/fedora/disk-setup.sh | ||
| 14 | - echo 'sudo blkid | grep -q $DISK || sudo mkfs.ext4 $DISK;' >> /home/fedora/disk-setup.sh | ||
| 15 | - echo 'grep -q $DISK /etc/fstab || echo "$DISK $MOUNT_PATH ext4 defaults,nofail 0 0" | sudo tee -a /etc/fstab;' >> /home/fedora/disk-setup.sh | ||
| 16 | - echo "sudo mount -a;" >> /home/fedora/disk-setup.sh | ||
| 17 | - echo "sudo systemctl daemon-reload" >> /home/fedora/disk-setup.sh | ||
| 18 | - sudo chmod +x /home/fedora/disk-setup.sh | ||
| 19 | - sudo /home/fedora/disk-setup.sh | ||
| 20 | - sudo rm -f /home/fedora/disk-setup.sh | ||
| 21 | - sudo growpart /dev/sda 1 | ||
| 22 | - sudo xfs_growfs / | ||
| 23 | - sudo dnf install -y vim git | ||
| 24 | - cd /home/fedora | ||
| 25 | - git clone https://git.0nom.ch/setup | ||
| 26 | - sudo ./setup/setup.sh | ||
| 27 | - touch /home/fedora/runcmd_done | ||
diff --git a/others/vm3/vm.sh b/others/vm3/vm.sh index c36b0ae..a043f89 100755 --- a/others/vm3/vm.sh +++ b/others/vm3/vm.sh | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | # Main entry point for VM management | 2 | # Main entry point for VM management |
| 3 | # also negotiator for executing scripts, so for storage | ||
| 3 | 4 | ||
| 4 | if [ "$(id -u)" != "0" ]; then | 5 | if [ "$(id -u)" != "0" ]; then |
| 5 | echo "This script must be run as root" | 6 | echo "This script must be run as root" |
| @@ -41,8 +42,8 @@ case $category in | |||
| 41 | shutdown) | 42 | shutdown) |
| 42 | $SCRIPT_DIR/compute/shutdown.sh "$@" | 43 | $SCRIPT_DIR/compute/shutdown.sh "$@" |
| 43 | ;; | 44 | ;; |
| 44 | delete) | 45 | rm) |
| 45 | $SCRIPT_DIR/compute/delete.sh "$@" | 46 | $SCRIPT_DIR/compute/rm.sh "$@" |
| 46 | ;; | 47 | ;; |
| 47 | *) | 48 | *) |
| 48 | echo -e "Available compute actions: \ncreate\nstart\nls\nshutdown\ndelete" | 49 | echo -e "Available compute actions: \ncreate\nstart\nls\nshutdown\ndelete" |
