-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·77 lines (63 loc) · 2.88 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·77 lines (63 loc) · 2.88 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -e
BOLD="\033[1m"
NORMAL="\033[0m"
BRANCH=""
echo -e "${BOLD}BareMetal-App Setup${NORMAL}\n"
echo -e "- Running clean"
./clean.sh
# Pre-flight checks: make sure required utilities are installed
echo -e "- Pre-flight check"
for cmd in git curl unzip tar gcc nasm make patch jq mkfs.ext2; do
if ! command -v "$cmd" > /dev/null 2>&1; then
echo "Error: required command '$cmd' not found. Please install it before running this script." >&2
exit 1
fi
done
echo -e "${BOLD}Pulling repositories${NORMAL}"
CLONE_ARGS=()
if [ -n "$BRANCH" ]; then
CLONE_ARGS=(--branch "$BRANCH")
fi
echo -e "- BareMetal-AppPort"
git clone --quiet "${CLONE_ARGS[@]}" https://github.com/ReturnInfinity/BareMetal-AppPort
echo -e "- BareMetal-Firecracker"
git clone --quiet "${CLONE_ARGS[@]}" https://github.com/ReturnInfinity/BareMetal-Firecracker
# Makre sure libBareMetal is up to date in AppPort
cp BareMetal-Firecracker/src/libBareMetal.* BareMetal-AppPort/port/
mkdir BareMetal-AppPort/build/
cp files/* BareMetal-AppPort/build
cd BareMetal-AppPort
./setup.sh
cd ..
DISK="$PWD/disk.img"
DISKSIZE=128M
# Create the disk image if it doesn't already exist, formatted as a
# plain EXT2 filesystem: BareMetal-AppPort/port/ext4_shim.c mounts it
# through lwext4 rather than reading/writing raw sectors directly (as
# the old BMFS format did). -b 4096 is required, not cosmetic --
# BareMetal-AppPort/port/lwext4_port/blockdev_baremetal.c presents the
# disk to lwext4 as a block device with a fixed 4096-byte physical
# block size (matching the kernel's b_nvs_read/b_nvs_write sector
# size); an EXT2 image built with a smaller logical block size (e.g.
# mkfs.ext2's own 1024-byte default) makes lwext4's logical-to-
# physical block count computation truncate to 0, silently turning
# every block read/write into a no-op -- which surfaces as a confusing
# ENOSPC on the very first file an app creates, not a mount failure.
if [ ! -f "$DISK" ]; then
echo "Creating $DISKSIZE EXT2 disk image at $DISK"
mkfs.ext2 -q -F -b 4096 "$DISK" "$DISKSIZE"
fi
# Installs the CA bundle apps' HTTPS traffic verifies against
# (port/tls_shim.c, curltest.c) onto the fresh image -- see
# BareMetal-AppPort/port/mbedtls_port/install-cacert.sh's own header
# for why this (unlike Python's stdlib/main.py) is a one-time setup.sh
# step rather than something 1-build.sh/3-upload.sh redo per deploy.
echo -e "- Installing CA trust store"
BareMetal-AppPort/port/mbedtls_port/install-cacert.sh "$DISK"
echo -e "- Copying examples from BareMetal-AppPort"
cp -r BareMetal-AppPort/examples .
echo -e "\n${BOLD}Complete!${NORMAL}\n"
echo -e "- Run ${BOLD}./1-build.sh YOURPROGRAM.c/.py${NORMAL} or ${BOLD}./1-build.sh yourcrate/src/main.rs${NORMAL} to build your program into a unikernel."
echo -e "- Run ${BOLD}./2-run.sh${NORMAL} to run your program in a BareMetal microVM."
echo -e "- Run ${BOLD}./3-upload.sh${NORMAL} to upload your program to BareMetal Cloud."