diff --git a/src/rootfsinstall.sh b/src/rootfsinstall.sh index 8edc151..97fe203 100755 --- a/src/rootfsinstall.sh +++ b/src/rootfsinstall.sh @@ -6,6 +6,8 @@ # SYSTEMFSTYPE=ext4 +# All targets are arm currently +TARGET_ARCH=arm function usage() { echo "Usage: $0 device rootfs-archive [-rpi|-cubox] [-a archive] [-c command] [-fs fstype] [-k kernel] [-p password] [-y]" @@ -23,6 +25,7 @@ function usage() { echo "-fs fstype : filesystem type for system partition (default: ext4)" echo "-h hostname : set given hostname" echo "-k kernel : extract and use specified kernel file from ROOTFS/boot/ for boot" + echo "-i packages : install packages using package manager in chroot" echo "-p password : set given password for root user" echo "-r mode : set given default video mode where applicable (e.g. -r 1920x1080-32@60)" echo "-y : assume yes to all questions (script mode)" @@ -88,6 +91,13 @@ while [ "$1" ]; do SETHOSTNAME=$2 shift ;; + -i) [ "$2" ] || { + echo "Error: -i option requires a packages list as argument; aborting." + exit 1 + } + INSTALLPACKAGES="$2" + shift + ;; -p) [ "$2" ] || { echo "Error: -p option requires a password as argument; aborting." exit 1 @@ -128,23 +138,29 @@ else fi case $TARGETDEVICE in - bpi) BOOTFSTYPE=fat32 + bpi) ARCH=arm + BOOTFSTYPE=fat32 BOOTFSSIZE=22M BOOTFSSTART=1049k [ "$USEKERNEL" ] || USEKERNEL=uImage-sunxi KERNELDEST="@BOOT@/kernel.img" + INSTALLPACKAGES="kernel-sunxi kernel-sunxi-modules u-boot-sunxi-Bananapi $INSTALLPACKAGES" ;; - rpi) BOOTFSTYPE=fat32 + rpi) ARCH=arm + BOOTFSTYPE=fat32 BOOTFSSIZE=40M BOOTFSSTART=0 [ "$USEKERNEL" ] || USEKERNEL=zImage-3.6.11-rpi KERNELDEST="@BOOT@/kernel.img" + INSTALLPACKAGES="kernel-rpi kernel-rpi-modules raspberrypi-firmware $INSTALLPACKAGES" ;; - cubox) BOOTFSTYPE=ext3 + cubox) ARCH=arm + BOOTFSTYPE=ext3 BOOTFSSIZE=20M BOOTFSSTART=0 [ "$USEKERNEL" ] || USEKERNEL=uImage-3.6.9-cubox KERNELDEST="@BOOT@/boot/uImage" + INSTALLPACKAGES="kernel-cubox kernel-cubox-modules $INSTALLPACKAGES" ;; *) BOOTFSTYPE= if [ "$USEKERNEL" ]; then @@ -206,11 +222,11 @@ fi if [ "$BOOTFSTYPE" ]; then echo "Formatting $PARTITION1 ($BOOTFSTYPE) ..." case "$BOOTFSTYPE" in - vfat|fat32) mkfs.vfat -s 1 -F 32 -n "BOOT" $PARTITION1 || { + vfat|fat32) mkfs.vfat -s 1 -F 32 -n "boot" $PARTITION1 || { echo "ERROR: unable to format $PARTITION1; aborting." exit 1 } ;; - ext*) mke2fs -q -t $BOOTFSTYPE -j -L "BOOT" $PARTITION1 || { + ext*) mke2fs -q -t $BOOTFSTYPE -j -L "boot" $PARTITION1 || { echo "ERROR: unable to format $PARTITION1; aborting." exit 1 } ;; @@ -275,6 +291,39 @@ fi [ $? -eq 0 ] || exit $? +[ -e /usr/bin/qemu-${TARGET_ARCH}.static ] && cp /usr/bin/qemu-${TARGET_ARCH}.static $ROOTMP/usr/bin/qemu-${TARGET_ARCH} + +if [ "$ROOTPASSWORD" ]; then + echo "$ROOTPASSWORD" | chroot $ROOTMP passwd root --stdin || { + echo "ERROR: unable to set password for root; aborting." + exit 1 + } +fi + +if [ "$SETHOSTNAME" ]; then + echo "$SETHOSTNAME" > $ROOTMP/etc/hostname + sed -i "s|HOSTNAME=.*|HOSTNAME=$SETHOSTNAME|" $ROOTMP/etc/sysconfig/network + sed -i "s|\(127\.0\.0\.1\W*\)\(.*\)|\1 $SETHOSTNAME.localdomain $SETHOSTNAME localhost.localdomain localhost|" $ROOTMP/etc/hosts +fi + +if [ "$INSTALLPACKAGES" ]; then + mv $ROOTMP/etc/resolv.conf $ROOTMP/etc/resolv.conf.rootfsinstall + cp /etc/resolv.conf $ROOTMP/etc/resolv.conf + chroot $ROOTMP smart channel --enable devel-kernel + chroot $ROOTMP smart update || { + echo "ERROR: error running chroot command 'smart update'; aborting." + exit 1 + } + chroot $ROOTMP smart install -y $INSTALLPACKAGES || { + echo "ERROR: error running chroot command 'smart install $INSTALLPACKAGES'; aborting." + exit 1 + } + mv $ROOTMP/etc/resolv.conf.rootfsinstall $ROOTMP/etc/resolv.conf +fi + +# +# Prepare boot partition +# if [ "$TARGETDEVICE" = "bpi" ]; then # TODO cp $ROOTMP/boot/Bananapi-script.bin $BOOTMP/ @@ -294,7 +343,8 @@ elif [ "$TARGETDEVICE" = "rpi" ]; then for f in bootcode.bin fixup_x.dat start_x.elf; do cp $ROOTMP/boot/$f $BOOTMP/$f done - cp $ROOTMP/boot/zImage*-rpi $BOOTMP/kernel.img + IMAGE=`ls $ROOTMP/boot/zImage-*-rpi | head -n 1` + cp $IMAGE $BOOTMP/kernel.img else if [ ! "$USEKERNEL" ]; then SWHOME=`mktemp -d` @@ -390,21 +440,9 @@ if [ "$USEKERNEL" ]; then fi fi -if [ "$SETHOSTNAME" ]; then - echo "$SETHOSTNAME" > $ROOTMP/etc/hostname - sed -i "s|HOSTNAME=.*|HOSTNAME=$SETHOSTNAME|" $ROOTMP/etc/sysconfig/network - sed -i "s|\(127\.0\.0\.1\W*\)\(.*\)|\1 $SETHOSTNAME.localdomain $SETHOSTNAME localhost.localdomain localhost|" $ROOTMP/etc/hosts -fi - -[ -e /usr/bin/qemu-arm.static ] && cp /usr/bin/qemu-arm.static $ROOTMP/usr/bin/qemu-arm - -if [ "$ROOTPASSWORD" ]; then - echo "$ROOTPASSWORD" | chroot $ROOTMP passwd root --stdin || { - echo "ERROR: unable to set password for root; aborting." - exit 1 - } -fi - +# +# Final custom commands +# for c in `seq 1 ${#PRECHROOTCOMMANDS[*]}`; do PRECHROOTCOMMAND=`echo ${PRECHROOTCOMMANDS[c-1]} | sed "s|@ROOT@|$ROOTMP|g;s|@BOOT@|$BOOTMP|g"` $PRECHROOTCOMMAND || {