2013-04-21 07:55:33 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#-
|
2015-01-19 13:07:53 -01:00
|
|
|
# Copyright (c) 2013-2015 Juan Romero Pardines.
|
2017-07-24 00:55:41 +00:00
|
|
|
# Copyright (c) 2017 Google
|
2013-04-21 07:55:33 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#-
|
|
|
|
|
|
|
|
readonly PROGNAME=$(basename $0)
|
|
|
|
readonly ARCH=$(uname -m)
|
|
|
|
|
2013-11-12 14:48:59 -01:00
|
|
|
trap 'die "Interrupted! exiting..."' INT TERM HUP
|
2013-04-21 07:55:33 +00:00
|
|
|
|
2014-06-01 10:29:55 +00:00
|
|
|
|
2013-04-21 07:55:33 +00:00
|
|
|
info_msg() {
|
|
|
|
printf "\033[1m$@\n\033[m"
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "FATAL: $@"
|
2013-11-12 14:48:59 -01:00
|
|
|
umount_pseudofs
|
2013-04-21 07:55:33 +00:00
|
|
|
[ -d "$rootfs" ] && rm -rf $rootfs
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2014-01-28 14:35:45 -01:00
|
|
|
cat <<_EOF
|
|
|
|
Usage: $PROGNAME [options] <platform>
|
|
|
|
|
2017-07-24 00:55:41 +00:00
|
|
|
Supported platforms: i686, i686-musl, x86_64, x86_64-musl, GCP, GCP-musl
|
2015-07-18 14:43:51 +00:00
|
|
|
dockstar, bananapi, beaglebone, cubieboard2, cubietruck,
|
2017-01-14 16:41:15 -01:00
|
|
|
odroid-c2, odroid-u2, rpi, rpi2 (armv7), rpi3 (aarch64),
|
|
|
|
usbarmory, ci20
|
|
|
|
|
2014-01-28 14:35:45 -01:00
|
|
|
|
|
|
|
Options
|
2014-06-01 10:29:55 +00:00
|
|
|
-b <syspkg> Set an alternative base-system package (defaults to base-system)
|
2015-06-12 08:09:48 +00:00
|
|
|
-c <dir> Set XBPS cache directory (defaults to \$PWD/xbps-cachedir-<arch>)
|
2014-01-28 14:35:45 -01:00
|
|
|
-C <file> Full path to the XBPS configuration file
|
|
|
|
-h Show this help
|
|
|
|
-p <pkgs> Additional packages to install into the rootfs (separated by blanks)
|
2014-06-01 10:29:55 +00:00
|
|
|
-r <repo> Set XBPS repository (may be set multiple times)
|
2016-01-18 14:18:30 -01:00
|
|
|
-k <cmd> Call "cmd <ROOTFSPATH>" after building the rootfs
|
2014-01-28 14:35:45 -01:00
|
|
|
-V Show version
|
|
|
|
_EOF
|
2013-11-12 14:48:59 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
mount_pseudofs() {
|
|
|
|
for f in dev proc sys; do
|
|
|
|
[ ! -d $rootfs/$f ] && mkdir -p $rootfs/$f
|
|
|
|
mount -r --bind /$f $rootfs/$f
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
umount_pseudofs() {
|
2016-12-10 10:30:13 -01:00
|
|
|
if [ -d "${rootfs}" ]; then
|
|
|
|
for f in dev proc sys; do
|
|
|
|
umount -f $rootfs/$f >/dev/null 2>&1
|
|
|
|
done
|
|
|
|
fi
|
2013-11-12 14:48:59 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
run_cmd_target() {
|
|
|
|
info_msg "Running $@ for target $_ARCH ..."
|
2016-04-20 14:19:55 +00:00
|
|
|
case "${_TARGET_ARCH}" in
|
|
|
|
i686*|x86_64*) eval XBPS_ARCH=${_TARGET_ARCH} "$@";;
|
|
|
|
*) eval XBPS_TARGET_ARCH=${_TARGET_ARCH:=${_ARCH}} "$@";;
|
|
|
|
esac
|
2013-11-12 14:48:59 -01:00
|
|
|
[ $? -ne 0 ] && die "Failed to run $@"
|
2013-04-21 07:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
run_cmd() {
|
|
|
|
info_msg "Running $@ ..."
|
2014-01-22 08:31:28 -01:00
|
|
|
eval "$@"
|
2013-04-21 07:55:33 +00:00
|
|
|
[ $? -ne 0 ] && die "Failed to run $@"
|
|
|
|
}
|
|
|
|
|
|
|
|
register_binfmt() {
|
|
|
|
if [ "$ARCH" = "${_ARCH}" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2014-12-05 04:22:16 -01:00
|
|
|
mountpoint -q /proc/sys/fs/binfmt_misc || modprobe -q binfmt_misc; mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
|
2013-04-21 07:55:33 +00:00
|
|
|
case "${_ARCH}" in
|
2015-07-18 14:43:51 +00:00
|
|
|
armv*)
|
2013-04-21 07:55:33 +00:00
|
|
|
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' > /proc/sys/fs/binfmt_misc/register
|
2016-04-26 09:00:14 +00:00
|
|
|
;;
|
2016-04-29 13:38:21 +00:00
|
|
|
aarch*)
|
|
|
|
echo ':qemu-arm64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64-static:' > /proc/sys/fs/binfmt_misc/register
|
|
|
|
;;
|
2016-04-26 09:00:14 +00:00
|
|
|
mipsel*)
|
|
|
|
echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mipsel-static:' > /proc/sys/fs/binfmt_misc/register
|
2013-04-21 07:55:33 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
die "Unknown target architecture!"
|
|
|
|
;;
|
|
|
|
esac
|
2016-04-26 09:00:14 +00:00
|
|
|
cp -f $(which $QEMU_BIN) $rootfs/usr/bin || die "failed to copy $QEMU_BIN to the rootfs"
|
2013-04-21 07:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# main()
|
|
|
|
#
|
2016-01-18 14:18:30 -01:00
|
|
|
while getopts "b:C:c:hp:r:k:V" opt; do
|
2013-04-21 07:55:33 +00:00
|
|
|
case $opt in
|
2014-06-01 10:29:55 +00:00
|
|
|
b) PKGBASE="$OPTARG";;
|
2014-01-22 08:36:24 -01:00
|
|
|
C) XBPS_CONFFILE="-C $OPTARG";;
|
2014-06-01 10:29:55 +00:00
|
|
|
c) XBPS_CACHEDIR="--cachedir=$OPTARG";;
|
2014-01-22 08:15:17 -01:00
|
|
|
h) usage; exit 0;;
|
2013-11-10 06:41:43 -01:00
|
|
|
p) EXTRA_PKGS="$OPTARG";;
|
2015-05-20 17:18:05 +00:00
|
|
|
r) XBPS_REPOSITORY="$XBPS_REPOSITORY --repository=$OPTARG";;
|
2016-01-18 14:18:30 -01:00
|
|
|
k) POST_HOOK="$OPTARG";;
|
2013-08-11 10:16:29 +00:00
|
|
|
V) echo "$PROGNAME @@MKLIVE_VERSION@@"; exit 0;;
|
2013-04-21 07:55:33 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
2014-01-28 14:35:45 -01:00
|
|
|
PLATFORM="$1"
|
2015-02-06 12:00:15 -01:00
|
|
|
SUBPLATFORM=$PLATFORM
|
2015-06-12 08:09:48 +00:00
|
|
|
|
|
|
|
case "$PLATFORM" in
|
2016-04-20 14:19:55 +00:00
|
|
|
i686*) _TARGET_ARCH="$PLATFORM"; _ARCH="i686";;
|
|
|
|
x86_64*) _TARGET_ARCH="$PLATFORM"; _ARCH="x86_64";;
|
2017-07-24 00:55:41 +00:00
|
|
|
GCP) _TARGET_ARCH="x86_64"; _ARCH="x86_64";;
|
|
|
|
GCP-musl) _TARGET_ARCH="x86_64-musl"; _ARCH="x86_64";;
|
2015-07-18 14:43:51 +00:00
|
|
|
dockstar) _TARGET_ARCH="armv5tel"; _ARCH="armv5tel";;
|
2015-06-12 08:09:48 +00:00
|
|
|
rpi-musl) _TARGET_ARCH="armv6l-musl"; _ARCH="armv6l";;
|
2015-06-12 08:28:40 +00:00
|
|
|
rpi) _TARGET_ARCH="armv6l"; _ARCH="armv6l";;
|
2017-01-14 16:41:15 -01:00
|
|
|
rpi3-musl) _TARGET_ARCH="aarch64-musl"; _ARCH="aarch64";;
|
|
|
|
rpi3) _TARGET_ARCH="aarch64"; _ARCH="aarch64";;
|
2016-04-26 09:00:14 +00:00
|
|
|
ci20-musl) _TARGET_ARCH="mipselhf-musl"; _ARCH="mipsel-musl";;
|
|
|
|
ci20) _TARGET_ARCH="mipselhf"; _ARCH="mipsel";;
|
2016-04-29 13:38:21 +00:00
|
|
|
odroid-c2-musl) _TARGET_ARCH="aarch64-musl"; _ARCH="aarch64";;
|
|
|
|
odroid-c2) _TARGET_ARCH="aarch64"; _ARCH="aarch64";;
|
2015-06-12 08:09:48 +00:00
|
|
|
*-musl) _TARGET_ARCH="armv7l-musl"; _ARCH="armv7l";;
|
|
|
|
*) _TARGET_ARCH="armv7l"; _ARCH="armv7l";;
|
|
|
|
esac
|
|
|
|
|
2017-01-14 16:41:15 -01:00
|
|
|
: ${XBPS_REPOSITORY:=--repository=http://repo.voidlinux.eu/current --repository=http://repo.voidlinux.eu/current/musl --repository=http://repo.voidlinux.eu/current/aarch64}
|
2015-06-12 08:09:48 +00:00
|
|
|
: ${XBPS_CACHEDIR:=--cachedir=$PWD/xbps-cachedir-${_TARGET_ARCH}}
|
2016-04-20 12:36:57 +00:00
|
|
|
case "$PLATFORM" in
|
|
|
|
i686*|x86_64*) PKGBASE="base-voidstrap";;
|
|
|
|
*) PKGBASE="base-system";;
|
|
|
|
esac
|
2014-01-28 14:35:45 -01:00
|
|
|
|
|
|
|
if [ -z "$PLATFORM" ]; then
|
|
|
|
echo "$PROGNAME: platform was not set!"
|
|
|
|
usage; exit 1
|
|
|
|
fi
|
|
|
|
|
2015-02-06 12:00:15 -01:00
|
|
|
|
2015-06-11 09:36:14 +00:00
|
|
|
case "$PLATFORM" in
|
2015-06-12 08:09:48 +00:00
|
|
|
bananapi*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-arm-static;;
|
|
|
|
beaglebone*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-arm-static;;
|
|
|
|
cubieboard2*|cubietruck*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-arm-static;;
|
2015-07-18 14:43:51 +00:00
|
|
|
dockstar*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-arm-static;;
|
2015-06-12 08:09:48 +00:00
|
|
|
odroid-u2*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-arm-static;;
|
2017-01-14 16:41:15 -01:00
|
|
|
rpi3*) SUBPLATFORM=rpi3; QEMU_BIN=qemu-aarch64-static;;
|
2015-06-12 08:09:48 +00:00
|
|
|
rpi2*) SUBPLATFORM=rpi; QEMU_BIN=qemu-arm-static;;
|
|
|
|
rpi*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-arm-static;;
|
|
|
|
usbarmory*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-arm-static;;
|
2016-04-26 09:00:14 +00:00
|
|
|
ci20*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-mipsel-static;;
|
2016-09-24 15:21:43 +00:00
|
|
|
odroid-c2*) SUBPLATFORM=${PLATFORM%-musl}; QEMU_BIN=qemu-aarch64-static;;
|
2015-06-12 08:09:48 +00:00
|
|
|
i686*) QEMU_BIN=qemu-i386-static;;
|
|
|
|
x86_64*) QEMU_BIN=qemu-x86_64-static;;
|
2017-07-24 00:55:41 +00:00
|
|
|
GCP*) SUBPLATFORM=${PLATFORM%-*}; QEMU_BIN=qemu-x86_64-static;;
|
2014-01-28 14:35:45 -01:00
|
|
|
*) die "$PROGNAME: invalid platform!";;
|
|
|
|
esac
|
|
|
|
|
2013-04-21 07:55:33 +00:00
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
|
|
die "need root perms to continue, exiting."
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check for required binaries.
|
|
|
|
#
|
2013-11-12 14:48:59 -01:00
|
|
|
for f in chroot tar xbps-install xbps-reconfigure xbps-query; do
|
2013-04-21 07:55:33 +00:00
|
|
|
if ! $f --version >/dev/null 2>&1; then
|
|
|
|
die "$f binary is missing in your system, exiting."
|
|
|
|
fi
|
|
|
|
done
|
2015-02-12 07:14:22 -01:00
|
|
|
if ! $QEMU_BIN -version >/dev/null 2>&1; then
|
|
|
|
die "$QEMU_BIN binary is missing in your system, exiting."
|
|
|
|
fi
|
2013-04-21 07:55:33 +00:00
|
|
|
#
|
|
|
|
# Check if package base-system is available.
|
|
|
|
#
|
2016-12-10 10:30:13 -01:00
|
|
|
rootfs=$(mktemp -d) || die "failed to create tempdir, exiting..."
|
2014-01-21 21:13:26 -01:00
|
|
|
mkdir -p $rootfs/var/db/xbps/keys
|
2014-06-25 06:23:37 +00:00
|
|
|
cp keys/*.plist $rootfs/var/db/xbps/keys
|
2014-01-21 21:13:26 -01:00
|
|
|
|
2014-06-01 10:29:55 +00:00
|
|
|
run_cmd_target "xbps-install -S $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $rootfs"
|
|
|
|
run_cmd_target "xbps-query -R -r $rootfs $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -ppkgver $PKGBASE"
|
2013-04-21 07:55:33 +00:00
|
|
|
|
|
|
|
chmod 755 $rootfs
|
|
|
|
|
2015-01-31 12:42:36 -01:00
|
|
|
case "$PLATFORM" in
|
2016-04-20 12:36:57 +00:00
|
|
|
i686*|x86_64*) PKGS="${PKGBASE}" ;;
|
2015-02-06 12:00:15 -01:00
|
|
|
*) PKGS="${PKGBASE} ${SUBPLATFORM}-base" ;;
|
2015-01-31 12:42:36 -01:00
|
|
|
esac
|
2013-11-12 14:48:59 -01:00
|
|
|
[ -n "$EXTRA_PKGS" ] && PKGS="${PKGS} ${EXTRA_PKGS}"
|
|
|
|
|
|
|
|
mount_pseudofs
|
2013-04-21 07:55:33 +00:00
|
|
|
#
|
|
|
|
# Install base-system to the rootfs directory.
|
|
|
|
#
|
2014-06-01 10:29:55 +00:00
|
|
|
run_cmd_target "xbps-install -S $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $rootfs -y ${PKGS}"
|
2013-11-12 14:48:59 -01:00
|
|
|
|
|
|
|
# Enable en_US.UTF-8 locale and generate it into the target rootfs.
|
2015-05-26 09:00:52 +00:00
|
|
|
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
|
2013-04-21 07:55:33 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Reconfigure packages for target architecture: must be reconfigured
|
|
|
|
# thru the qemu user mode binary.
|
|
|
|
#
|
2014-01-21 21:13:26 -01:00
|
|
|
if [ -n "${_ARCH}" ]; then
|
|
|
|
info_msg "Reconfiguring packages for ${_ARCH} ..."
|
2015-01-31 12:42:36 -01:00
|
|
|
case "$PLATFORM" in
|
2017-07-24 00:55:41 +00:00
|
|
|
i686*|x86_64*|GCP*)
|
2016-04-20 14:19:55 +00:00
|
|
|
run_cmd "XBPS_ARCH=${PLATFORM} xbps-reconfigure -r $rootfs base-files"
|
2015-01-31 12:42:36 -01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
register_binfmt
|
2015-06-07 10:31:30 +00:00
|
|
|
run_cmd "xbps-reconfigure -r $rootfs base-files"
|
|
|
|
run_cmd "chroot $rootfs env -i xbps-reconfigure -f base-files"
|
2016-04-29 07:23:38 +00:00
|
|
|
rmdir $rootfs/usr/lib32 2>/dev/null
|
2015-01-31 12:42:36 -01:00
|
|
|
rm -f $rootfs/lib32 $rootfs/lib64 $rootfs/usr/lib64
|
|
|
|
;;
|
|
|
|
esac
|
2013-11-12 14:48:59 -01:00
|
|
|
run_cmd "chroot $rootfs xbps-reconfigure -a"
|
2013-04-21 07:55:33 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Setup default root password.
|
|
|
|
#
|
2013-11-12 14:48:59 -01:00
|
|
|
run_cmd "chroot $rootfs sh -c 'echo "root:voidlinux" | chpasswd -c SHA512'"
|
2016-01-18 14:18:30 -01:00
|
|
|
if [ -n "$POST_HOOK" ]; then
|
|
|
|
run_cmd "$POST_HOOK $rootfs"
|
|
|
|
fi
|
2013-11-12 14:48:59 -01:00
|
|
|
umount_pseudofs
|
2013-04-21 07:55:33 +00:00
|
|
|
#
|
|
|
|
# Cleanup rootfs.
|
|
|
|
#
|
|
|
|
rm -f $rootfs/etc/.pwd.lock 2>/dev/null
|
2014-06-01 10:29:55 +00:00
|
|
|
rm -rf $rootfs/var/cache/* 2>/dev/null
|
2013-04-21 07:55:33 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Generate final tarball.
|
|
|
|
#
|
|
|
|
arch=$ARCH
|
2014-07-29 06:33:04 +00:00
|
|
|
if [ -n "${_ARCH}" ]; then
|
|
|
|
rm -f $rootfs/usr/bin/$QEMU_BIN
|
|
|
|
arch=${_ARCH}
|
2013-04-21 07:55:33 +00:00
|
|
|
fi
|
|
|
|
|
2014-01-28 14:35:45 -01:00
|
|
|
tarball=void-${PLATFORM}-rootfs-$(date '+%Y%m%d').tar.xz
|
2016-12-10 10:30:13 -01:00
|
|
|
run_cmd "tar -cp --posix --xattrs -C $rootfs . | xz -T0 -9 > $tarball "
|
2014-12-05 05:06:39 -01:00
|
|
|
|
2013-04-21 07:55:33 +00:00
|
|
|
rm -rf $rootfs
|
|
|
|
|
2014-01-28 14:35:45 -01:00
|
|
|
info_msg "Successfully created $tarball ($PLATFORM)"
|
2013-04-21 07:55:33 +00:00
|
|
|
|
|
|
|
# vim: set ts=4 sw=4 et:
|