parch-riscv/mkrootfs

80 lines
1.8 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
varbose_arg=
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))
varbose_arg="--verbose"
;;
p) password=${OPTARG:-archriscv}
;;
*)
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-extra-riscv64.conf \
-M \
./rootfs \
base
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"\
$varbose_arg \
--xattrs --acls\
-f "$filename" -C rootfs/ .
msg "Clean up rootfs directory..."
sudo rm -rf ./rootfs