123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- #!/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] <arch>
- Supported architectures: i686, i686-musl, x86_64, x86_64-musl,
- armv5tel, armv5tel-musl, armv6l, armv6l-musl, armv7l, armv7l-musl
- aarch64, aarch64-musl,
- mipsel, mipsel-musl
- ppc, ppc-musl
- ppc64le, ppc64le-musl, ppc64, ppc64-musl
- Options
- -b <syspkg> Set an alternative base-system package (defaults to base-voidstrap)
- -c <dir> Set XBPS cache directory (defaults to \$PWD/xbps-cachedir-<arch>)
- -C <file> Full path to the XBPS configuration file
- -h Show this help
- -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 ROOTFS archive to
- -V Show version
- _EOF
- }
- SYSPKG="base-voidstrap"
- while getopts "b:C:c:hr:x:o:V" opt; do
- case $opt in
- b) SYSPKG="$OPTARG";;
- C) XBPS_CONFFILE="-C $OPTARG";;
- c) XBPS_CACHEDIR="--cachedir=$OPTARG";;
- r) XBPS_REPOSITORY="$XBPS_REPOSITORY --repository=$OPTARG";;
- x) COMPRESSOR_THREADS="$OPTARG" ;;
- o) FILENAME="$OPTARG" ;;
- V) version; exit 0;;
- *) usage; exit 0;;
- esac
- done
- shift $((OPTIND - 1))
- XBPS_TARGET_ARCH="$1"
- set_cachedir
- if [ "$(id -u)" -ne 0 ]; then
- die "need root perms to continue, exiting."
- fi
- check_tools
- if [ -z "$XBPS_TARGET_ARCH" ]; then
- echo "$PROGNAME: arch was not set!"
- usage; exit 1
- fi
- ROOTFS=$(mktemp -d) || die "failed to create tempdir, exiting..."
- mkdir -p "$ROOTFS/var/db/xbps/keys"
- cp keys/*.plist "$ROOTFS/var/db/xbps/keys"
- run_cmd_target "xbps-install -S $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS"
- chmod 755 "$ROOTFS"
- register_binfmt
- mount_pseudofs
- run_cmd_target "xbps-install -SU $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -y $SYSPKG"
- if [ -e "$ROOTFS/etc/default/libc-locales" ]; then
- LOCALE=en_US.UTF-8
- sed -e "s/\#\(${LOCALE}.*\)/\1/g" -i "$ROOTFS/etc/default/libc-locales"
- fi
- info_msg "Reconfiguring packages for ${XBPS_TARGET_ARCH} ..."
- if is_target_native "$XBPS_TARGET_ARCH"; then
- run_cmd_target "xbps-reconfigure --rootdir $ROOTFS base-files"
- else
- run_cmd "xbps-reconfigure --rootdir $ROOTFS base-files"
- fi
- run_cmd_chroot "$ROOTFS" "env -i xbps-reconfigure -f base-files"
- run_cmd_chroot "$ROOTFS" "xbps-reconfigure -a"
- info_msg "Setting the default root password ('voidlinux')"
- if [ ! -f "$ROOTFS/etc/shadow" ] ; then
- run_cmd_chroot "$ROOTFS" pwconv
- fi
- echo root:voidlinux | run_cmd_chroot "$ROOTFS" "chpasswd -c SHA512" || die "Could not set default credentials"
- rm -f "$ROOTFS/etc/.pwd.lock"
- cleanup_chroot
- rm -rf "$ROOTFS/var/cache/*" 2>/dev/null
- : "${FILENAME:=void-${XBPS_TARGET_ARCH}-ROOTFS-$(date -u '+%Y%m%d').tar.xz}"
- run_cmd "tar cp --posix --xattrs --xattrs-include='*' -C $ROOTFS . | xz -T${COMPRESSOR_THREADS:-0} -9 > $FILENAME "
- rm -rf "$ROOTFS"
- info_msg "Successfully created $FILENAME ($XBPS_TARGET_ARCH)"
|