-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·88 lines (78 loc) · 2.48 KB
/
bootstrap.sh
File metadata and controls
executable file
·88 lines (78 loc) · 2.48 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
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
function path() { echo "$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")/$*"; }
function make_rootfs()
{
local img="$1"
shift
fallocate -l5G "$img"
mke2fs -F -t ext4 "$img" "$@"
}
function configure_locales()
{
local mnt="$1"
shift
echo "en_US.UTF-8 UTF-8" | sudo tee -a "$mnt"/etc/locale.gen
sudo chroot mnt locale-gen
}
function configure_rootfs()
{
local mnt="$1"
shift
sudo mkdir -p "$mnt"/var/lib/pacman
sudo mkdir -p "$mnt"/dev
#
# /dev/null for dirmngr
#
# create /dev/null to avoid hanging dirmngr installation
# that has "dirmngr </dev/null >&/dev/null" in it's postinstall hook
# and without this line it creates regular file with tons of lines like:
#
# dirmngr[21273]: No ldapserver file at: '/root/.gnupg/dirmngr_ldapservers.conf'
# dirmngr[21273.0]: permanently loaded certificates: 1
# dirmngr[21273.0]: runtime cached certificates: 0
# dirmngr[21273.0]: trusted certificates: 1 (0,0,0,1)
# dirmngr[21273.0]: failed to open cache dir file '/root/.gnupg/crls.d/DIR.txt': No such file or directory
# dirmngr[21273.0]: creating directory '/root/.gnupg'
# dirmngr[21273.0]: creating directory '/root/.gnupg/crls.d'
# dirmngr[21273.0]: new cache dir file '/root/.gnupg/crls.d/DIR.txt' created
# # Home: /root/.gnupg
# # Config: [none]
# OK Dirmngr 2.2.15 at your service
# ERR 167772435 Unknown IPC command <Dirmngr>
# ...
# ERR 167772435 Unknown IPC command <Dirmngr>
sudo mknod "$mnt"/dev/null c 1 3
local pkgs=(
# base
base bash glibc coreutils e2fsprogs which procps-ng util-linux
findutils grep gawk vi less sed
bzip2 gzip tar
pciutils
# net
bind-tools dhcp dhcpcd inetutils iproute2 iputils
# debug
strace tcpdump perf gdb
# stuff
tmux
)
local opts=(
# we have our own kernel
--ignore linux*
# but some packages requires api headers and without this there will
# endless loop for resolving dependency
--assume-installed linux-api-headers=$(uname -r)
-r "$mnt"
)
sudo pacman --noconfirm -Sy "${opts[@]}" "${pkgs[@]}" "$@"
sudo cp $(path init) mnt/sbin/
}
function main()
{
make_rootfs rootfs.img || return 1
mkdir -p mnt
sudo mount -o loop rootfs.img mnt
configure_rootfs mnt "$@"
configure_locales mnt
sudo umount mnt
}
main "$@"