diff options
| author | Your Name <you@example.com> | 2024-12-29 20:10:29 +0800 |
|---|---|---|
| committer | Your Name <you@example.com> | 2024-12-29 20:10:29 +0800 |
| commit | 6f49e7a01ed42cb1227e5070f5d1095342e9bc29 (patch) | |
| tree | d7f46b53cdd0b0ea70855c364ee5f4f58521923b /others/vm3 | |
| parent | 26d1a94dfd4eeb91b259bfd9d4b8f8d1cdfabd98 (diff) | |
debian12-support
Diffstat (limited to 'others/vm3')
| -rwxr-xr-x | others/vm3/.config/cloud-init-generator/debian12.sh | 60 | ||||
| -rw-r--r-- | others/vm3/.docs.swp | bin | 16384 -> 0 bytes | |||
| -rwxr-xr-x | others/vm3/compute/create.sh | 13 | ||||
| -rwxr-xr-x | others/vm3/compute/ls.sh (renamed from others/vm3/compute/list.sh) | 0 | ||||
| -rw-r--r-- | others/vm3/docs | 2 | ||||
| -rwxr-xr-x | others/vm3/vm.sh | 6 |
6 files changed, 45 insertions, 36 deletions
diff --git a/others/vm3/.config/cloud-init-generator/debian12.sh b/others/vm3/.config/cloud-init-generator/debian12.sh index 0bdb418..245f73c 100755 --- a/others/vm3/.config/cloud-init-generator/debian12.sh +++ b/others/vm3/.config/cloud-init-generator/debian12.sh | |||
| @@ -18,36 +18,36 @@ if [ $# -ne 1 ]; then | |||
| 18 | echo "Usage: $0 <vm-name>" | 18 | echo "Usage: $0 <vm-name>" |
| 19 | exit 1 | 19 | exit 1 |
| 20 | fi | 20 | fi |
| 21 | sudo mkdir -p "$dir_path" | 21 | sudo mkdir -p "$dir_path" # make image store dir |
| 22 | sudo mkdir -p "$config_dir" | 22 | sudo mkdir -p "$config_dir" |
| 23 | |||
| 23 | [ ! -f "$src_file" ] && echo "source image does not exist! downloading..." && sudo wget -O "$src_file" "$image_url" | 24 | [ ! -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: sudo | ||
| 36 | shell: /bin/bash | ||
| 37 | runcmd: | ||
| 38 | - sudo growpart /dev/sda 1 | ||
| 39 | - sudo resize2fs /dev/sda1 | ||
| 40 | - sudo apt-get update | ||
| 41 | - sudo apt-get install -y vim git | ||
| 42 | - cd /home/user | ||
| 43 | - #git clone https://git.0nom.ch/setup | ||
| 44 | - #sudo ./setup/setup.sh | ||
| 45 | - touch /home/user/runcmd_done | ||
| 46 | EOF | ||
| 47 | cat > "$meta_data" << EOF | ||
| 48 | instance-id: vm_id | ||
| 49 | local-hostname: $1 | ||
| 50 | EOF | ||
| 51 | genisoimage -output "$seed_iso" -volid cidata -joliet -rock "$user_data" "$meta_data" &> /dev/null || { echo "Failed to create seed.iso."; exit 1; } | ||
| 52 | echo "Configuration files generated successfully" | ||
| 53 | 25 | ||
| 26 | |||
| 27 | # First create a command that will generate all the ssh-inject options | ||
| 28 | SSH_INJECT_OPTS=$(find ${sshkeysdir} -name "*.pub" -exec echo "--ssh-inject user:file:{}" \;) | ||
| 29 | |||
| 30 | flag_file="${dir_path}/debian12_customized" | ||
| 31 | |||
| 32 | # Check if customization has already been done | ||
| 33 | if [ -f "$flag_file" ]; then | ||
| 34 | echo "Image already customized, skipping customization..." | ||
| 35 | else | ||
| 36 | echo "Customizing image..." | ||
| 37 | export LIBGUESTFS_BACKEND=direct | ||
| 38 | sudo -E virt-customize -a /var/lib/libvirt/images/.image_store/debian12.qcow2 \ | ||
| 39 | --run-command 'useradd -m -s /bin/bash user' \ | ||
| 40 | $SSH_INJECT_OPTS \ | ||
| 41 | --update \ | ||
| 42 | --install openssh-server,git \ | ||
| 43 | --run-command 'echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/user' \ | ||
| 44 | --run-command 'sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config' \ | ||
| 45 | --run-command 'sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config' \ | ||
| 46 | --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 'tee -a /etc/bashrc > /dev/null << "EOF" | ||
| 48 | LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS | ||
| 49 | PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\'' | ||
| 50 | EOF' && \ | ||
| 51 | # Create flag file after successful customization | ||
| 52 | sudo touch "$flag_file" | ||
| 53 | fi | ||
diff --git a/others/vm3/.docs.swp b/others/vm3/.docs.swp deleted file mode 100644 index 3eb0602..0000000 --- a/others/vm3/.docs.swp +++ /dev/null | |||
| Binary files differ | |||
diff --git a/others/vm3/compute/create.sh b/others/vm3/compute/create.sh index 3e6c088..a1d84f6 100755 --- a/others/vm3/compute/create.sh +++ b/others/vm3/compute/create.sh | |||
| @@ -88,11 +88,18 @@ if [[ ${os,,} == *"freebsd"* ]]; then | |||
| 88 | ostype="generic" | 88 | ostype="generic" |
| 89 | fi | 89 | fi |
| 90 | 90 | ||
| 91 | # Define the disk options based on OS type | ||
| 92 | if [ "$os" = "debian12" ]; then | ||
| 93 | disk_opts="--disk path=$new_vm,format=qcow2" | ||
| 94 | else | ||
| 95 | disk_opts="--disk path=$new_vm,format=qcow2 --disk path=$seed_iso,device=cdrom" | ||
| 96 | fi | ||
| 97 | |||
| 98 | # Use the conditional disk options in virt-install | ||
| 91 | sudo virt-install --name $vmname \ | 99 | sudo virt-install --name $vmname \ |
| 92 | --vcpus $vcpu \ | 100 | --vcpus $vcpu \ |
| 93 | --memory "$((ram_gb * 1024))"\ | 101 | --memory "$((ram_gb * 1024))" \ |
| 94 | --disk path=$new_vm,format=qcow2 \ | 102 | $disk_opts \ |
| 95 | --disk path=$seed_iso,device=cdrom \ | ||
| 96 | --os-type $ostype \ | 103 | --os-type $ostype \ |
| 97 | --os-variant $os \ | 104 | --os-variant $os \ |
| 98 | --virt-type kvm \ | 105 | --virt-type kvm \ |
diff --git a/others/vm3/compute/list.sh b/others/vm3/compute/ls.sh index b62ef14..b62ef14 100755 --- a/others/vm3/compute/list.sh +++ b/others/vm3/compute/ls.sh | |||
diff --git a/others/vm3/docs b/others/vm3/docs index e350e4e..ca8ec36 100644 --- a/others/vm3/docs +++ b/others/vm3/docs | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | 1 | ||
| 2 | todo | 2 | todo |
| 3 | make theseediso cloud init stuff happen inside the vm storage directory so that multiple poeple can use it ast the same time on the same system | 3 | make theseediso cloud init stuff happen inside the vm storage directory so that multiple poeple can use it ast the same time on the same system |
| 4 | fedora debian freebsd opensuse | ||
| 5 | change deployment for non-fedora to manually make a base image and copy ssh stuff over, then duplicate it however you want | ||
| 4 | 6 | ||
| 5 | 7 | ||
| 6 | 8 | ||
diff --git a/others/vm3/vm.sh b/others/vm3/vm.sh index 30168ba..c36b0ae 100755 --- a/others/vm3/vm.sh +++ b/others/vm3/vm.sh | |||
| @@ -35,8 +35,8 @@ case $category in | |||
| 35 | start) | 35 | start) |
| 36 | $SCRIPT_DIR/compute/start.sh "$@" | 36 | $SCRIPT_DIR/compute/start.sh "$@" |
| 37 | ;; | 37 | ;; |
| 38 | list) | 38 | ls) |
| 39 | $SCRIPT_DIR/compute/list.sh "$@" | 39 | $SCRIPT_DIR/compute/ls.sh "$@" |
| 40 | ;; | 40 | ;; |
| 41 | shutdown) | 41 | shutdown) |
| 42 | $SCRIPT_DIR/compute/shutdown.sh "$@" | 42 | $SCRIPT_DIR/compute/shutdown.sh "$@" |
| @@ -45,7 +45,7 @@ case $category in | |||
| 45 | $SCRIPT_DIR/compute/delete.sh "$@" | 45 | $SCRIPT_DIR/compute/delete.sh "$@" |
| 46 | ;; | 46 | ;; |
| 47 | *) | 47 | *) |
| 48 | echo -e "Available compute actions: \ncreate\nstart\nlist\nshutdown\ndelete" | 48 | echo -e "Available compute actions: \ncreate\nstart\nls\nshutdown\ndelete" |
| 49 | exit 1 | 49 | exit 1 |
| 50 | ;; | 50 | ;; |
| 51 | esac | 51 | esac |
