summaryrefslogtreecommitdiff
path: root/others
diff options
context:
space:
mode:
Diffstat (limited to 'others')
-rwxr-xr-xothers/vm3/.config/cloud-init-generator/debian12.sh60
-rw-r--r--others/vm3/.docs.swpbin16384 -> 0 bytes
-rwxr-xr-xothers/vm3/compute/create.sh13
-rwxr-xr-xothers/vm3/compute/ls.sh (renamed from others/vm3/compute/list.sh)0
-rw-r--r--others/vm3/docs2
-rwxr-xr-xothers/vm3/vm.sh6
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
20fi 20fi
21sudo mkdir -p "$dir_path" 21sudo mkdir -p "$dir_path" # make image store dir
22sudo mkdir -p "$config_dir" 22sudo 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"
24cat > "$user_data" << EOF
25#cloud-config
26users:
27 - name: user
28 ssh-authorized-keys:
29EOF
30for key in $sshkeysdir/*.pub; do
31 echo " - $(cat "$key")" >> $user_data
32done
33cat >> "$user_data" << 'EOF'
34 sudo: ['ALL=(ALL) NOPASSWD:ALL']
35 groups: sudo
36 shell: /bin/bash
37runcmd:
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
46EOF
47cat > "$meta_data" << EOF
48instance-id: vm_id
49local-hostname: $1
50EOF
51genisoimage -output "$seed_iso" -volid cidata -joliet -rock "$user_data" "$meta_data" &> /dev/null || { echo "Failed to create seed.iso."; exit 1; }
52echo "Configuration files generated successfully"
53 25
26
27# First create a command that will generate all the ssh-inject options
28SSH_INJECT_OPTS=$(find ${sshkeysdir} -name "*.pub" -exec echo "--ssh-inject user:file:{}" \;)
29
30flag_file="${dir_path}/debian12_customized"
31
32# Check if customization has already been done
33if [ -f "$flag_file" ]; then
34 echo "Image already customized, skipping customization..."
35else
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"
48LS_COLORS=$LS_COLORS:'\''di=38;5;135:ex=00;32:'\'' ; export LS_COLORS
49PS1='\''[\[\033[01;32m\]\u\[\033[00m\]@\h \[\033[38;5;135m\]\W\[\033[00m\]]\$ '\''
50EOF' && \
51 # Create flag file after successful customization
52 sudo touch "$flag_file"
53fi
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"
89fi 89fi
90 90
91# Define the disk options based on OS type
92if [ "$os" = "debian12" ]; then
93 disk_opts="--disk path=$new_vm,format=qcow2"
94else
95 disk_opts="--disk path=$new_vm,format=qcow2 --disk path=$seed_iso,device=cdrom"
96fi
97
98# Use the conditional disk options in virt-install
91sudo virt-install --name $vmname \ 99sudo 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
2todo 2todo
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