#!/usr/bin/bash # # SPDX-FileCopyrightText: 2022 Celeste Liu # SPDX-License-Identifier: GPL-3.0-or-later # shellcheck disable=1091 . /usr/share/makepkg/util.sh colorize verbose=0 verbose_arg= password='parch' show_help() { cat << EOF Usage: ${0##*/} [-hv] [-p PASSWORD] [FILENAME] Create Parch RISC-V rootfs. FILENAME generated rootfs file name, use the archive suffix to decide the compression algorithm. default: 'parchriscv-$(date --rfc-3339=date).tar.zst' -h display this help and exit -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)) verbose_arg="--verbose" ;; p) password=$OPTARG ;; *) show_help >&2 exit 1 ;; esac done shift "$(( OPTIND-1 ))" 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 parch-branding fastfetch 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 "Adding Parch Mirror to Rootfs" echo -e "[ppr]\nSigLevel = Never\nServer = https://mirror.parchlinux.com/repos/ppr/riscv64/" | sudo tee -a ./rootfs/etc/pacman.conf > /dev/null 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