-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprepare-image.sh
More file actions
executable file
·58 lines (48 loc) · 1.82 KB
/
Copy pathprepare-image.sh
File metadata and controls
executable file
·58 lines (48 loc) · 1.82 KB
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
#!/bin/bash
if ! [ $# -eq 1 ]; then
echo "Usage: $0 <fedora-cloud-image.qcow2>"
exit 1
fi
IMAGE=image.qcow2
# Resize the disk? By default it's a 2GB HDD
RESIZE_DISK=true
DISK_SIZE=10G
echo "$(date -R) Cleaniung up..."
rm -rf $IMAGE
cp $1 $IMAGE
echo "$(date -R) Modifying the image..."
guestfish -a $IMAGE -i --network --selinux > image.log <<_EOF_
# Load selinux policy
sh "/usr/sbin/load_policy -i"
# Remove cloud-init
sh "yum -y remove cloud-init"
# Update the system
sh "yum -y update"
# Install Docker and Open vSwitch and bridge-utils and DHCPd
sh "yum -y install docker-io openvswitch bridge-utils dhcp"
# Disable the docker0 bridge creation
sh "echo -e '.include /usr/lib/systemd/system/docker.service\n\n[Service]\nExecStart=\nExecStart=/usr/bin/docker -d -b=none' > /etc/systemd/system/docker.service"
# Run Docker on boot
ln-s /usr/lib/systemd/system/docker.service /etc/systemd/system/multi-user.target.wants/docker.service
# Run Open vSwitch on boot
ln-s /usr/lib/systemd/system/openvswitch.service /etc/systemd/system/multi-user.target.wants/openvswitch.service
# Create fedora user
sh "useradd -m fedora"
# Reset the fedora user password
sh "echo 'fedora:fedora' | chpasswd"
# Give the fedora users administrative rights
sh "echo 'fedora ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/fedora"
# Add the fedora user to docker group
sh "usermod -a -G docker fedora"
# Upload the network configuration script
upload network.sh /home/fedora/network.sh
sh "chmod +x /home/fedora/network.sh"
_EOF_
if $RESIZE_DISK; then
echo "$(date -R) Resizing the disk..."
virt-filesystems --long -h --all -a $IMAGE >> image.log
qemu-img create -f qcow2 -o preallocation=metadata $IMAGE.new $DISK_SIZE >> image.log
virt-resize --quiet --expand /dev/sda1 $IMAGE $IMAGE.new >> image.log
mv $IMAGE.new $IMAGE
fi
echo "$(date -R) Image '$IMAGE' created!"