-
Notifications
You must be signed in to change notification settings - Fork 10
/
mkrootfs
executable file
·84 lines (71 loc) · 1.99 KB
/
mkrootfs
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
#!/usr/bin/bash
#
# SPDX-FileCopyrightText: 2022 Celeste Liu <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
# shellcheck disable=1091
. /usr/share/makepkg/util.sh
colorize
verbose=0
verbose_arg=
password='archriscv'
show_help() {
cat << EOF
Usage: ${0##*/} [-hv] [-p PASSWORD] [FILENAME]
Create Arch RISC-V rootfs.
FILENAME generated rootfs file name, use the archive suffix to decide
the compression algorithm.
default: 'archriscv-$(date --rfc-3339=date).tar.zst'
-h display this help and exit
-p PASSWORD set root password to PASSWORD instead of archriscv
-v verbose mode
EOF
}
parse-args() {
local OPTIND=1
while getopts 'hvp:' opt; do
case $opt in
h)
show_help
exit 0
;;
v) verbose=$((verbose+1))
verbose_arg="--verbose"
;;
p) password=$OPTARG
;;
*)
show_help >&2
exit 1
;;
esac
done
shift "$(( OPTIND-1 ))"
filename=${1:-archriscv-$(date --rfc-3339=date).tar.zst}
echo $filename
}
parse-args "$@"
msg "Building rootfs..."
mkdir -p ./rootfs
sudo chown root:root ./rootfs
sudo pacstrap \
-C /usr/share/devtools/pacman.conf.d/extra-riscv64.conf \
-M \
-K \
./rootfs \
base
msg "Set default mirror to https://riscv.mirror.pkgbuild.com"
sudo sed -E -i 's|#(Server = https://riscv\.mirror\.pkgbuild\.com/repo/\$repo)|\1|' ./rootfs/etc/pacman.d/mirrorlist
msg "Clean up pacman package cache..."
yes y | sudo pacman \
--sysroot ./rootfs \
--sync --clean --clean
msg "Set root password (Default: archriscv)..."
sudo usermod --root $(realpath ./rootfs) --password $(openssl passwd -6 "$password") root
msg "Compressing rootfs..."
sudo bsdtar --create \
--auto-compress --options "compression-level=9"\
$verbose_arg \
--xattrs --acls\
-f "$filename" -C rootfs/ .
msg "Clean up rootfs directory..."
sudo rm -rf ./rootfs