rootfsinstall: new -cp option to run a command before chroot
This commit is contained in:
parent
2f231a3c9b
commit
36f4b5abeb
@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
### rootfsinstall: create partitions and fileysytems
|
||||
#
|
||||
# Based on rpi-install by: Davide Madrisan
|
||||
@ -10,6 +11,7 @@ function usage() {
|
||||
echo
|
||||
echo "Options:"
|
||||
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 "-fs fstype : filesystem type for system partition (default: ext4)"
|
||||
echo "-h hostname : set given hostname"
|
||||
@ -56,6 +58,13 @@ while [ "$1" ]; do
|
||||
CHROOTCOMMAND=$2
|
||||
shift
|
||||
;;
|
||||
-cp) [ "$2" ] || {
|
||||
echo "Error: -p option requires a command string as argument; aborting."
|
||||
exit 1
|
||||
}
|
||||
PRECHROOTCOMMAND=$2
|
||||
shift
|
||||
;;
|
||||
-k) [ "$2" ] || {
|
||||
echo "Error: -k option requires a kernel file name as argument; aborting."
|
||||
exit 1
|
||||
@ -272,14 +281,17 @@ if [ "$USEKERNEL" ]; then
|
||||
else
|
||||
KERNELDEST=/tmp/$USEKERNEL
|
||||
fi
|
||||
if [ -r boot/$USEKERNEL ]; then
|
||||
cp boot/$USEKERNEL $KERNELDEST
|
||||
if [ -e /tmp/$USEKERNEL ]; then
|
||||
echo "Extracted kernel available as $KERNELDEST"
|
||||
else
|
||||
if [ -r $ROOTMP/boot/$USEKERNEL ]; then
|
||||
cp $ROOTMP/boot/$USEKERNEL $KERNELDEST || {
|
||||
echo "ERROR: unable to find or copy kernel $USEKERNEL; aborting."
|
||||
exit 1
|
||||
}
|
||||
if [ -e /tmp/$USEKERNEL ]; then
|
||||
echo "Extracted kernel is available as $KERNELDEST"
|
||||
fi
|
||||
else
|
||||
echo "ERROR: can't find kernel file $ROOTMP/boot/$USERKERNEL; aborting."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -296,6 +308,14 @@ if [ "$ROOTPASSWORD" ]; then
|
||||
}
|
||||
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
|
||||
chroot $ROOTMP $CHROOTCOMMAND || {
|
||||
echo "ERROR: error running chroot command; aborting."
|
||||
|
Loading…
Reference in New Issue
Block a user