blob: c498efa48765de8b6541bb86e4b68a8c1423c8fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#!/bin/bash
# generates configuration for FreeBSD VM deployment
# requires the name of the vm as an argument
image_url="https://download.freebsd.org/releases/VM-IMAGES/14.2-RELEASE/amd64/Latest/FreeBSD-14.2-RELEASE-amd64-BASIC-CLOUDINIT.zfs.qcow2.xz"
sshkeysdir="/root/k"
scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
dir_path="/var/lib/libvirt/images/.image_store"
src_file="${dir_path}/freebsd14.0.qcow2"
config_dir="/var/lib/libvirt/images/.temp"
user_data="${config_dir}/user-data"
meta_data="${config_dir}/meta-data"
seed_iso="${config_dir}/seed.iso"
if [ $# -ne 1 ]; then
echo "Usage: $0 <vm-name>"
exit 1
fi
sudo mkdir -p "$dir_path"
sudo mkdir -p "$config_dir"
# Download and extract FreeBSD image if it doesn't exist
if [ ! -f "$src_file" ]; then
echo "source image does not exist! downloading..."
sudo wget -O "${src_file}.xz" "$image_url"
sudo xz -d "${src_file}.xz"
fi
cat > "$user_data" << EOF
#cloud-config
users:
- name: user
passwd: 'yourpassword'
lock_passwd: false
ssh-authorized-keys:
EOF
for key in $sshkeysdir/*.pub; do
echo " - $(cat "$key")" >> $user_data
done
cat >> "$user_data" << 'EOF'
groups: wheel
shell: /bin/tcsh
# FreeBSD specific configuration
package_update: true
package_upgrade: true
packages:
- vim-console
- git
- doas
write_files:
- path: /usr/local/etc/doas.conf
content: |
permit nopass :wheel
permissions: '0600'
runcmd:
- pw usermod user -s /bin/tcsh
- env ASSUME_ALWAYS_YES=YES pkg update
- env ASSUME_ALWAYS_YES=YES pkg upgrade
- env ASSUME_ALWAYS_YES=YES pkg install vim-console git doas
- touch /home/user/runcmd_done
EOF
cat > "$meta_data" << EOF
instance-id: vm_id
local-hostname: $1
EOF
genisoimage -output "$seed_iso" -volid cidata -joliet -rock "$user_data" "$meta_data" &> /dev/null || { echo "Failed to create seed.iso."; exit 1; }
echo "Configuration files generated successfully"
|