This repository has been archived by the owner on Nov 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbootstrap.sh
executable file
·89 lines (72 loc) · 2.17 KB
/
bootstrap.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
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
#!/usr/bin/env bash
DEFAULT_IMAGE_SIZE=4096
set -e
if [ -z "$1" ]; then
echo "Usage: ./bootstrap.sh BUILD_DIRECTORY [IMAGE_SIZE_MB]"
exit 0
fi
# Accepted host OSes else fail.
OS=$(uname)
if ! [ "$OS" = "Linux" ] && ! [ "$OS" = "FreeBSD" ]; then
echo "Host OS \"$OS\" is not supported."
exit 1
fi
# Image size in MiB
if [ -z "$2" ]; then
IMGSIZE=$DEFAULT_IMAGE_SIZE
else
IMGSIZE="$2"
fi
# Make sure BUILD_DIR is absolute
BUILD_DIR="$(realpath $1)"
# qword repo
QWORD_DIR="$(pwd)/qword"
QWORD_REPO=https://github.com/qword-os/qword.git
# Add toolchain to PATH
PATH="$BUILD_DIR/tools/cross-binutils/bin:$PATH"
PATH="$BUILD_DIR/tools/system-gcc/bin:$PATH"
set -x
[ -d "$QWORD_DIR" ] || git clone "$QWORD_REPO" "$QWORD_DIR"
make -C "$QWORD_DIR" CC="x86_64-qword-gcc"
if ! [ -f ./qword.hdd ]; then
dd if=/dev/zero bs=1M count=0 seek=$IMGSIZE of=qword.hdd
case "$OS" in
"FreeBSD")
sudo mdconfig -a -t vnode -f qword.hdd -u md9
sudo gpart create -s mbr md9
sudo gpart add -a 4k -t '!14' md9
sudo mdconfig -d -u md9
;;
"Linux")
parted -s qword.hdd mklabel msdos
parted -s qword.hdd mkpart primary 1 100%
;;
esac
echfs-utils -m -p0 qword.hdd quick-format 32768
fi
# Install limine
if ! [ -d limine ]; then
git clone https://github.com/limine-bootloader/limine.git --depth=1 --branch=v0.6.3
fi
make -C limine limine-install
limine/limine-install limine/limine.bin qword.hdd
# Prepare root
install -m 644 qword/qword.elf root/
install -m 644 /etc/localtime root/etc/
install -d root/lib
install "$BUILD_DIR/system-root/usr/lib/ld.so" root/lib/
mkdir -p mnt
if [ "$USE_FUSE" = "no" ]; then
./copy-root-to-img.sh "$BUILD_DIR"/system-root qword.hdd 0
./copy-root-to-img.sh root qword.hdd 0
else
echfs-fuse --mbr -p0 qword.hdd mnt
while ! rsync -ru --copy-links --info=progress2 "$BUILD_DIR"/system-root/* mnt; do
true
done # FIXME: This while loop only exists because of an issue in echfs-fuse that makes it fail randomly.
sync
rsync -ru --copy-links --info=progress2 root/* mnt
sync
fusermount -u mnt/
rm -rf ./mnt
fi