-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubuntu-lts.sh
executable file
·59 lines (47 loc) · 1.93 KB
/
ubuntu-lts.sh
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
#!/bin/bash
CURL_LAST_LTS_RELEASE=$(curl -s https://changelogs.ubuntu.com/meta-release-lts | grep Dist: | tail -n1)
LAST_LTS_RELEASE=${CURL_LAST_LTS_RELEASE:6}
DIR=$(
cd "$(dirname "$0")" || exit 1
pwd
)
echo ""
echo "This script will download and setup an vm with the newest Ubuntu LTS Version ($LAST_LTS_RELEASE)"
echo ""
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit
fi
if [ ! -f "$DIR/ssh-keys.pub" ]; then
echo "Warning ssh-keys.pub doesn't exists"
echo "Will abort now"
exit
fi
echo "Check and re-download Image $LAST_LTS_RELEASE-server-cloudimg-amd64.img if there is a newer img file"
wget -N "https://cloud-images.ubuntu.com/$LAST_LTS_RELEASE/current/$LAST_LTS_RELEASE-server-cloudimg-amd64.img" -P /tmp/
echo "Enter VM ID"
read -r VM_ID
echo "Enter VM Name"
read -r VM_NAME
echo "Ensure libguestfs-tools is installed"
apt install libguestfs-tools -y
echo "Create copy of $LAST_LTS_RELEASE-server-cloudimg-amd64 for image modification"
cp -r "/tmp/$LAST_LTS_RELEASE-server-cloudimg-amd64.img" "/tmp/$LAST_LTS_RELEASE-server-cloudimg-amd64.modified.img"
echo "Install qemu-guest-agent on Ubuntu image"
virt-customize -a "/tmp/$LAST_LTS_RELEASE-server-cloudimg-amd64.modified.img" --install qemu-guest-agent
echo "Create Proxmox VM image from Ubuntu Cloud Image"
qm create "$VM_ID" --memory 1024 --balloon 0 --cores 2 --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-pci
qm set "$VM_ID" --scsi0 local-lvm:0,import-from="/tmp/$LAST_LTS_RELEASE-server-cloudimg-amd64.modified.img"
qm set "$VM_ID" --agent enabled=1,fstrim_cloned_disks=1
echo "Create Cloud-Init Disk and configure boot"
qm set "$VM_ID" --ide2 local-lvm:cloudinit
qm set "$VM_ID" --boot order=scsi0
echo "Configure vm"
qm set "$VM_ID" \
--name "$VM_NAME" \
--onboot 1 \
--ciuser "devops" \
--sshkeys "$DIR/ssh-keys.pub" \
--ipconfig0 "ip=dhcp,ip6=dhcp"
echo "Cleanup: delete modified cloudimg"
rm -f "/tmp/$LAST_LTS_RELEASE-server-cloudimg-amd64.modified.img"