rootfsinstall: new -cp option to run a command before chroot

This commit is contained in:
Silvan Calarco 2013-11-10 15:35:54 +01:00
parent 2f231a3c9b
commit 36f4b5abeb

View File

@ -1,3 +1,4 @@
#!/bin/bash
### rootfsinstall: create partitions and fileysytems ### rootfsinstall: create partitions and fileysytems
# #
# Based on rpi-install by: Davide Madrisan # Based on rpi-install by: Davide Madrisan
@ -10,6 +11,7 @@ function usage() {
echo echo
echo "Options:" echo "Options:"
echo "-a archive : additional archive to unpack in rootfs root" echo "-a archive : additional archive to unpack in rootfs root"
echo "-cp command : command to run before chroot. Use @ROOT@ as reference to rootfs path"
echo "-c command : command to run through chroot in rootfs" echo "-c command : command to run through chroot in rootfs"
echo "-fs fstype : filesystem type for system partition (default: ext4)" echo "-fs fstype : filesystem type for system partition (default: ext4)"
echo "-h hostname : set given hostname" echo "-h hostname : set given hostname"
@ -56,6 +58,13 @@ while [ "$1" ]; do
CHROOTCOMMAND=$2 CHROOTCOMMAND=$2
shift shift
;; ;;
-cp) [ "$2" ] || {
echo "Error: -p option requires a command string as argument; aborting."
exit 1
}
PRECHROOTCOMMAND=$2
shift
;;
-k) [ "$2" ] || { -k) [ "$2" ] || {
echo "Error: -k option requires a kernel file name as argument; aborting." echo "Error: -k option requires a kernel file name as argument; aborting."
exit 1 exit 1
@ -272,14 +281,17 @@ if [ "$USEKERNEL" ]; then
else else
KERNELDEST=/tmp/$USEKERNEL KERNELDEST=/tmp/$USEKERNEL
fi fi
if [ -r boot/$USEKERNEL ]; then if [ -r $ROOTMP/boot/$USEKERNEL ]; then
cp boot/$USEKERNEL $KERNELDEST cp $ROOTMP/boot/$USEKERNEL $KERNELDEST || {
if [ -e /tmp/$USEKERNEL ]; then
echo "Extracted kernel available as $KERNELDEST"
else
echo "ERROR: unable to find or copy kernel $USEKERNEL; aborting." echo "ERROR: unable to find or copy kernel $USEKERNEL; aborting."
exit 1 exit 1
}
if [ -e /tmp/$USEKERNEL ]; then
echo "Extracted kernel is available as $KERNELDEST"
fi fi
else
echo "ERROR: can't find kernel file $ROOTMP/boot/$USERKERNEL; aborting."
exit 1
fi fi
fi fi
@ -296,6 +308,14 @@ if [ "$ROOTPASSWORD" ]; then
} }
fi fi
if [ "$PRECHROOTCOMMAND" ]; then
PRECHROOTCOMMAND=`echo $PRECHROOTCOMMAND | sed "s|@ROOT@|$ROOTMP|g"`
$PRECHROOTCOMMAND || {
echo "ERROR: error running pre-chroot command; aborting."
exit 1
}
fi
if [ "$CHROOTCOMMAND" ]; then if [ "$CHROOTCOMMAND" ]; then
chroot $ROOTMP $CHROOTCOMMAND || { chroot $ROOTMP $CHROOTCOMMAND || {
echo "ERROR: error running chroot command; aborting." echo "ERROR: error running chroot command; aborting."