115 lines
3.4 KiB
Bash
115 lines
3.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Build: Bootstrap a base Hyperbola GNU plus Linux-libre system
|
|
|
|
set -e -u -o pipefail
|
|
|
|
# Check if the user is root (superuser)
|
|
if [[ $(id -u) -ne 0 ]]; then
|
|
echo "This script must be run as root (superuser) because it uses 'mknod' to make device nodes, which requires superuser privileges."
|
|
exit 1
|
|
fi
|
|
|
|
# Display usage message
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: bash $0 [options]
|
|
|
|
Options:
|
|
-a, --arch ARCH Specify architecture (default: x86_64)
|
|
-d, --delete-chroot Delete the chroot environment after processing (default: yes)
|
|
-r, --release VERSION Specify version (default: v0.4.3)
|
|
-u, --url URL Specify repository URL (default: https://mirror.fsf.org/hyperbola/gnu-plus-linux-libre/stable)
|
|
-owu, --owner-user-id ID Owner user ID for the tar file (default: 1000)
|
|
-owg, --owner-group-id ID Owner group ID for the tar file (default: 1000)
|
|
-h, --help Display this help message
|
|
EOF
|
|
}
|
|
|
|
SCRIPT=$(readlink -f "$0")
|
|
SCRIPT_PWD=$(dirname "$SCRIPT")
|
|
CHROOT_DELETE='y'
|
|
|
|
RESULTPATH="${SCRIPT_PWD}"
|
|
ARCH="x86_64"
|
|
RELEASE="v0.4.3"
|
|
REPO_URL="https://mirror.fsf.org/hyperbola/gnu-plus-linux-libre/stable"
|
|
TAR_OWNER_USER_ID="1000"
|
|
TAR_OWNER_GROUP_ID="1000"
|
|
|
|
# Parse command-line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
key="${1}"
|
|
case $key in
|
|
-a|--arch)
|
|
ARCH="${2}"
|
|
shift 2
|
|
;;
|
|
-d|--delete-chroot)
|
|
CHROOT_DELETE="${2}"
|
|
shift 2
|
|
;;
|
|
-r|--release)
|
|
RELEASE="${2}"
|
|
shift 2
|
|
;;
|
|
-u|--url)
|
|
REPO_URL="${2}"
|
|
shift 2
|
|
;;
|
|
-owu|--owner-user-id)
|
|
TAR_OWNER_USER_ID="${2}"
|
|
shift 2
|
|
;;
|
|
-owg|--owner-group-id)
|
|
TAR_OWNER_GROUP_ID="${2}"
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
usage && exit 0
|
|
;;
|
|
*)
|
|
echo "Unrecognized option: $key"
|
|
usage && exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Set ROOTFS
|
|
ROOTFS="$ARCH"
|
|
|
|
# Remove old archives
|
|
rm -fv "${RESULTPATH}/hyperbola-bootstrap-${ARCH}.tar.gz" "${RESULTPATH}/hyperbola-bootstrap-${ARCH}.tar.gz.sha512sum"
|
|
|
|
# Make bootstrap for Hyperbola
|
|
bash "${SCRIPT_PWD}/hyper-bootstrap_${RELEASE}.sh" -a "${ARCH}" -r "${REPO_URL}" "${ROOTFS}"
|
|
|
|
# Clean up package cache
|
|
(cd "${ROOTFS}" && rm -rf var/cache/*)
|
|
|
|
# Rename pacnew files
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Rename files ending in .pacnew...' '\e[m'
|
|
find "${ROOTFS}" -type f -name "*.pacnew" -exec sh -c 'mv -f "$1" "${1%.pacnew}"' _ {} \;
|
|
|
|
# Make new tarball
|
|
printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' "Make hyperbola-bootstrap-${ARCH}.tar.gz..." '\e[m'
|
|
(cd "${RESULTPATH}/${ROOTFS}" && tar --create --gzip --numeric-owner --xattrs --acls --file="${SCRIPT_PWD}/hyperbola-bootstrap-${ARCH}.tar.gz" *)
|
|
|
|
# Make sha512sum
|
|
(cd ${RESULTPATH} && sha512sum "hyperbola-bootstrap-${ARCH}.tar.gz" >| "hyperbola-bootstrap-${ARCH}.tar.gz.sha512sum")
|
|
|
|
# Fix permission Tarballs
|
|
(cd ${RESULTPATH} && chown ${TAR_OWNER_USER_ID}:${TAR_OWNER_GROUP_ID} hyperbola-bootstrap-x86_64.tar.gz*)
|
|
|
|
# Clean chroot temp
|
|
case $CHROOT_DELETE in
|
|
y|yes) rm -rf "${RESULTPATH}/${ROOTFS}" || true && echo -e "\e[1;32m==>\e[0m\033[1m Temporal chroot deleted! \e[m" ;;
|
|
n|not) echo 'Temporal chroot available' ;;
|
|
*) echo 'Invalid option "$@"' ;;
|
|
esac
|
|
|
|
# Report result
|
|
echo "REPO: ${REPO_URL}"
|
|
echo "ROOTFS: ${ROOTFS}"
|
|
echo "RESULTPATH: ${RESULTPATH}"
|