2022-09-11 23:25:47 +08:00
|
|
|
#!/usr/bin/bash
|
|
|
|
#
|
|
|
|
# SPDX-FileCopyrightText: 2022 Celeste Liu <CoelacanthusHex@gmail.com>
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
# shellcheck disable=1091
|
|
|
|
. /usr/share/makepkg/util.sh
|
|
|
|
colorize
|
|
|
|
|
|
|
|
verbose=0
|
2023-02-05 12:12:11 +08:00
|
|
|
verbose_arg=
|
2025-02-07 21:59:47 +00:00
|
|
|
password='parch'
|
2022-09-11 23:25:47 +08:00
|
|
|
|
|
|
|
show_help() {
|
|
|
|
cat << EOF
|
|
|
|
Usage: ${0##*/} [-hv] [-p PASSWORD] [FILENAME]
|
2025-02-07 21:59:47 +00:00
|
|
|
Create Parch RISC-V rootfs.
|
2022-09-11 23:25:47 +08:00
|
|
|
|
|
|
|
FILENAME generated rootfs file name, use the archive suffix to decide
|
|
|
|
the compression algorithm.
|
2025-02-07 21:59:47 +00:00
|
|
|
default: 'parchriscv-$(date --rfc-3339=date).tar.zst'
|
2022-09-11 23:25:47 +08:00
|
|
|
|
|
|
|
-h display this help and exit
|
2025-02-07 21:59:47 +00:00
|
|
|
-p PASSWORD set root password to PASSWORD instead of parch
|
2022-09-11 23:25:47 +08:00
|
|
|
-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))
|
2023-02-05 12:12:11 +08:00
|
|
|
verbose_arg="--verbose"
|
2022-09-11 23:25:47 +08:00
|
|
|
;;
|
2022-09-13 12:05:55 +08:00
|
|
|
p) password=$OPTARG
|
2022-09-11 23:25:47 +08:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
show_help >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift "$(( OPTIND-1 ))"
|
2025-02-07 21:59:47 +00:00
|
|
|
filename=${1:-parchriscv-$(date --rfc-3339=date).tar.zst}
|
2022-09-11 23:25:47 +08:00
|
|
|
echo $filename
|
|
|
|
}
|
|
|
|
|
|
|
|
parse-args "$@"
|
|
|
|
|
|
|
|
msg "Building rootfs..."
|
|
|
|
mkdir -p ./rootfs
|
|
|
|
sudo chown root:root ./rootfs
|
|
|
|
sudo pacstrap \
|
2023-05-27 22:39:49 +08:00
|
|
|
-C /usr/share/devtools/pacman.conf.d/extra-riscv64.conf \
|
2022-09-11 23:25:47 +08:00
|
|
|
-M \
|
2024-10-02 21:14:18 +08:00
|
|
|
-K \
|
2022-09-11 23:25:47 +08:00
|
|
|
./rootfs \
|
|
|
|
base
|
|
|
|
|
2023-01-24 01:06:32 +08:00
|
|
|
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
|
|
|
|
|
2022-09-11 23:25:47 +08:00
|
|
|
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"\
|
2023-02-05 12:12:11 +08:00
|
|
|
$verbose_arg \
|
2022-09-11 23:25:47 +08:00
|
|
|
--xattrs --acls\
|
|
|
|
-f "$filename" -C rootfs/ .
|
|
|
|
|
|
|
|
msg "Clean up rootfs directory..."
|
|
|
|
sudo rm -rf ./rootfs
|