-
Notifications
You must be signed in to change notification settings - Fork 0
/
wizard
executable file
·147 lines (127 loc) · 4.23 KB
/
wizard
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
KERNEL_LOCATION=/firecracker/kernel
FILESYSTEM_LOCATION=/firecracker/fs
CONFIG_LOCATION=/firecracker/configs
download_kernel() {
print_message "🐧️ Downloading Linux kernel binary..."
ARCH="$(uname -m)"
wget -O $KERNEL_LOCATION/kernel https://s3.amazonaws.com/spec.ccfc.min/firecracker-ci/v1.5/${ARCH}/vmlinux-5.10.186
print_message "✅ Kernel binary has downloaded and been written to $KERNEL_LOCATION/kernel"
}
# Creates the ext4 filesystem for the VM
# You can think of this similar to a Docker image - which is what we build the fs from!
create_fs() {
print_message "💿 Preparing filesystem preparation..."
cp $PWD/fs/rootfs.Dockerfile $FILESYSTEM_LOCATION/Dockerfile
. $PWD/fs/fs.sh
}
install_docker() {
print_message "🐋 Installing Docker... This might take a while as we will setup all dependencies"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install \
bison \
build-essential \
flex \
git \
libelf-dev \
libncurses5-dev \
libssl-dev -y
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common -y
sudo apt-get install \
docker-ce \
docker-ce-cli \
containerd.io -y
sudo groupadd docker # this may report that the group already exists
sudo usermod -aG docker $USER
print_message "✅ Docker has been installed succcessfully"
}
# Generates the Firecracker configuration file
setup_cfg() {
source $PWD/config/launch.sh
print_message "Configuring VM with kernel path of $KERNEL_LOCATION/kernel & $FILESYSTEM_LOCATION/alpine-base-root.ext4"
gen_config $FILESYSTEM_LOCATION $KERNEL_LOCATION
print_message "✅ Configuration JSON written to $CONFIG_LOCATION/alpine-config.json"
}
# Puts Firecracker on path
install_fc() {
print_message "🔥 Beginning Firecracker installation"
source $PWD/installer/install_fc.sh
install
print_message "✅ Firecracker successfully installed onto your PATH (/usr/bin/firecracker)"
}
run_fc() {
print_message "🔥 Preparing to run Firecracker..."
print_message "If this step fails, then just remove the socket and re-run..."
firecracker --no-api --config-file $CONFIG_LOCATION/alpine-config.json
print_message "✅ Firecracker running!"
}
display_menu() {
echo "🧙🔥 Firecracker Setup Wizard"
echo ""
echo "1) Download Linux kernel binary"
echo "2) Install Firecracker"
echo "3) Install Docker"
echo "4) Setup Firecracker filesystem"
echo "5) Setup Firecracker config JSON"
echo "6) Run Firecracker"
echo "7) ✨ Setup everything"
echo "8) Exit"
}
print_message() {
local message=$1
local len=${#message}
local dashes=$(printf '%*s' "$len" | tr ' ' '-')
echo "$dashes"
echo "$message"
echo "$dashes"
}
setup_everything() {
print_message "EXPERIMENTAL: Automating the entire setup process!"
download_kernel
install_fc
install_docker
create_fs
setup_cfg
print_message "✅ Setup complete - You may now run Firecracker from the wizard menu"
}
check_root() {
if [ "$(id -u)" != "0" ]; then
print_message "👋 This script must be run as root!"
exit 1
fi
}
clear
# sudo only for this script!
check_root
# pre-gen the necessary directories
print_message "⚠️ Creating the necessary directories underneath /firecracker/*"
mkdir -p /firecracker/{kernel,fs,configs,releases}
# USER needs r/w privleges for /dev/kvm
print_message "⚠️ Installing the acl package before we begin so we can set permissions for /dev/kvm"
sudo apt-get install -y acl
sudo setfacl -m u:${USER}:rw /dev/kvm
while true; do
display_menu
read -p "Pick a number ➡️ " choice
case $choice in
1) download_kernel ;;
2) install_fc ;;
3) install_docker ;;
4) create_fs ;;
5) setup_cfg ;;
6) run_fc ;;
7) setup_everything ;;
8) break ;;
*) echo "Invalid option, please try again." ;;
esac
done