parch-riscv/mkrootfs

85 lines
2 KiB
Text
Raw Normal View History

#!/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'
show_help() {
cat << EOF
Usage: ${0##*/} [-hv] [-p PASSWORD] [FILENAME]
2025-02-07 21:59:47 +00:00
Create Parch RISC-V rootfs.
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'
-h display this help and exit
2025-02-07 21:59:47 +00:00
-p PASSWORD set root password to PASSWORD instead of parch
-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"
;;
p) password=$OPTARG
;;
*)
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}
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"\
2023-02-05 12:12:11 +08:00
$verbose_arg \
--xattrs --acls\
-f "$filename" -C rootfs/ .
msg "Clean up rootfs directory..."
sudo rm -rf ./rootfs