summaryrefslogtreecommitdiff
path: root/others/vm3/.config
diff options
context:
space:
mode:
authorYour Name <you@example.com>2024-12-29 20:10:29 +0800
committerYour Name <you@example.com>2024-12-29 20:10:29 +0800
commit6f49e7a01ed42cb1227e5070f5d1095342e9bc29 (patch)
treed7f46b53cdd0b0ea70855c364ee5f4f58521923b /others/vm3/.config
parent26d1a94dfd4eeb91b259bfd9d4b8f8d1cdfabd98 (diff)
debian12-support
Diffstat (limited to 'others/vm3/.config')
-rwxr-xr-xothers/vm3/.config/cloud-init-generator/debian12.sh60
1 files changed, 30 insertions, 30 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