123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- #!/bin/sh
- readonly PROGNAME=$(basename "$0")
- readonly ARCH=$(uname -m)
- readonly REQTOOLS="xbps-install xbps-reconfigure tar xz"
- . ./lib.sh
- trap 'die "Interrupted! exiting..."' INT TERM HUP
- usage() {
- cat <<_EOF
- Usage: $PROGNAME [options] <platform> <base-tarball>
- Supported platforms: i686, x86_64, GCP, bananapi, beaglebone,
- cubieboard2, cubietruck, odroid-c2, odroid-u2,
- rpi-armv6l, rpi-armv7l, rpi-aarch64, ci20,
- pinebookpro, pinephone, rock64
- Options
- -b <syspkg> Set an alternative base-system package (defaults to base-system)
- -p <pkgs> Additional packages to install into the rootfs (separated by blanks)
- -k <cmd> Call "cmd <ROOTFSPATH>" after building the rootfs
- -c <dir> Set XBPS cache directory (defaults to \$PWD/xbps-cachedir-<arch>)
- -C <file> Full path to the XBPS configuration file
- -r <repo> Set XBPS repository (may be set multiple times)
- -x <num> Use <num> threads to compress the image (dynamic if unset)
- -o <file> Filename to write the PLATFORMFS archive to
- -n Do not compress the image, instead print out the rootfs directory
- -h Show this help
- -V Show version
- _EOF
- }
- BASEPKG=base-system
- COMPRESSION="y"
- while getopts "b:p:k:c:C:r:x:o:nhV" opt; do
- case $opt in
- b) BASEPKG="$OPTARG" ;;
- p) EXTRA_PKGS="$OPTARG" ;;
- k) POST_CMD="$OPTARG" ;;
- c) XBPS_CACHEDIR="--cachedir=$OPTARG" ;;
- C) XBPS_CONFFILE="-C $OPTARG" ;;
- r) XBPS_REPOSITORY="--repository=$OPTARG $XBPS_REPOSITORY" ;;
- x) COMPRESSOR_THREADS="$OPTARG" ;;
- o) FILENAME="$OPTARG" ;;
- n) COMPRESSION="n" ;;
- V) version; exit 0;;
- *) usage; exit 0 ;;
- esac
- done
- shift $((OPTIND - 1))
- PLATFORM="$1"
- BASE_TARBALL="$2"
- if [ "$(id -u)" -ne 0 ]; then
- die "need root perms to continue, exiting."
- fi
- check_tools
- case "$PLATFORM" in
- bananapi*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- beaglebone*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- cubieboard2*|cubietruck*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- odroid-u2*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- odroid-c2*) PKGS="$BASEPKG ${PLATFORM%-musl}-base" ;;
- rpi*) PKGS="$BASEPKG rpi-base" ;;
- ci20*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- i686*) PKGS="$BASEPKG" ;;
- x86_64*) PKGS="$BASEPKG" ;;
- GCP*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- pinebookpro*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- pinephone*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- rock64*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;;
- *) die "$PROGNAME: invalid platform!";;
- esac
- set_target_arch_from_platform
- set_cachedir
- if [ -n "$EXTRA_PKGS" ] ; then
- PKGS="$PKGS $EXTRA_PKGS"
- fi
- ROOTFS=$(mktemp -d) || die "failed to create tempdir, exiting..."
- if [ ! -e "$BASE_TARBALL" ]; then
- die "no valid base tarball given, exiting."
- fi
- info_msg "Expanding base tarball $BASE_TARBALL into $ROOTFS for $PLATFORM build."
- tar xf "$BASE_TARBALL" --xattrs --xattrs-include='*' -C "$ROOTFS"
- run_cmd_target "xbps-install -SU $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -y $PKGS"
- run_cmd_chroot "$ROOTFS" "xbps-reconfigure -a"
- if [ ! -f "$ROOTFS/boot/uInitrd" ] ||
- [ ! -f "$ROOTFS/boot/initrd" ] &&
- [ -z "${XBPS_TARGET_ARCH##*arm*}" ] &&
- [ -x "$ROOTFS/usr/bin/dracut" ] &&
- [ -x "$ROOTFS/usr/bin/mkimage" ]; then
-
-
-
-
-
- KERNELVERSION=$(ls "$ROOTFS/usr/lib/modules/")
-
-
-
- set_dracut_args_from_platform
-
-
-
-
- info_msg "Building initrd for kernel version $KERNELVERSION"
- run_cmd_chroot "$ROOTFS" "env -i /usr/bin/dracut $dracut_args /boot/initrd $KERNELVERSION"
- [ $? -ne 0 ] && die "Failed to generate the initramfs"
- run_cmd_chroot "$ROOTFS" "env -i /usr/bin/mkimage -A arm -O linux -T ramdisk -C gzip -a 0 -e 0 -n 'Void Linux' -d /boot/initrd /boot/uInitrd"
- fi
- cleanup_chroot
- rm -rf "$ROOTFS/var/cache/*" 2>/dev/null
- if [ -n "$POST_CMD" ]; then
- info_msg "Running user supplied command: $POST_CMD"
- run_cmd $POST_CMD $ROOTFS
- fi
- if [ "$COMPRESSION" = "y" ]; then
-
-
- tarball=${FILENAME:-void-${PLATFORM}-PLATFORMFS-$(date -u '+%Y%m%d').tar.xz}
- run_cmd "tar cp --posix --xattrs --xattrs-include='*' -C $ROOTFS . | xz -T${COMPRESSOR_THREADS:-0} -9 > $tarball "
- [ $? -ne 0 ] && die "Failed to compress tarball"
-
-
- rm -rf "$ROOTFS"
-
-
-
-
- info_msg "Successfully created $tarball ($PLATFORM)"
- else
-
- info_msg "Successfully created rootfs under $ROOTFS"
- fi
|