aboutsummaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-02-15 21:30:16 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-02-15 21:30:16 -0200
commitcd5fb92fdf78fcf3770a7767035ce9fc1e31f172 (patch)
tree8244d02b053426be5e7cd576e34c2fb391a4b244 /share
parent699db157b56831505a7a8025697837cb3a4d2bed (diff)
downloadhydra-cd5fb92fdf78fcf3770a7767035ce9fc1e31f172.tar.gz
hydra-cd5fb92fdf78fcf3770a7767035ce9fc1e31f172.tar.bz2
Now bootless image can record image directly to device
Diffstat (limited to 'share')
-rwxr-xr-xshare/hydra/bootless79
1 files changed, 63 insertions, 16 deletions
diff --git a/share/hydra/bootless b/share/hydra/bootless
index 511b317..cc34e1f 100755
--- a/share/hydra/bootless
+++ b/share/hydra/bootless
@@ -77,20 +77,9 @@ EOF
usbdevice=`echo ${device} | sed -e s/[0-9]\$//g`
# Issue a warning
- cat <<EOF
-
-******************
-* ATTENTION!!! *
-******************
-
-If you continue, all data in device "${device}" will be destroyed!
-
-EOF
-
- echo -n "Are you sure you want to continue? Type uppercase \"YES\": "
- read go
+ hydra_bootless_warning ${device}
- if [ "${go}" != "YES" ]; then
+ if [ "$?" != "0" ]; then
echo "Aborting..."
exit 1
fi
@@ -313,18 +302,48 @@ function hydra_bootless_device {
fi
}
+function hydra_bootless_warning {
+ local device=$1
+ local go
+
+ echo "******************"
+ echo "* ATTENTION!!! *"
+ echo "******************"
+ echo ""
+ echo "If you continue, all data in device \"${device}\" will be destroyed!"
+ echo ""
+ echo -n "Are you sure you want to continue? Type uppercase \"YES\": "
+ read go
+
+ if [ "${go}" != "YES" ]; then
+ false
+ else
+ true
+ fi
+}
+
# Generate a bootless disk image
-# TODO: optionally copy to removable media
function hydra_bootless_image {
local output="$1"
+ local device="$2"
- if [ -z "$output" ]; then
+ # Fix parameters
+ if echo ${output} | grep -q "/dev/"; then
+ output="bootless.img"
+ device="$1"
+ elif [ -z "$output" ]; then
output="bootless.img"
fi
# Set folder
hydra_bootless_folder
+ # Set sudo config
+ local sudo
+ if [ "`whoami`" != 'root' ]; then
+ sudo="sudo"
+ fi
+
# Copy data
tmpdir=`mktemp -d`
$sudo rsync -Cav ${BOOTLESS_DIR}/ ${tmpdir}/boot/
@@ -332,9 +351,37 @@ function hydra_bootless_image {
# Make rescue disk
grub-mkrescue -o ${output} ${tmpdir}
+ # Optionally copy to removable media
+ if [ ! -z "$device" ]; then
+ # Issue a warning
+ hydra_bootless_warning ${device}
+
+ if [ "$?" != "0" ]; then
+ echo "Skipping copy of ${output} to ${device}..."
+ else
+ # Check if device is mounted
+ if [ "`mount | grep ${device}`" != "" ]; then
+ echo "Error: device \"${device}\" is mounted."
+ echo "Skipping copy of ${output} to ${device}..."
+ else
+ $sudo dd if=${output} of=${device}
+ fi
+ fi
+
+ fi
+
# Cleanup
rm -rf ${tmpdir}
- echo "Image saved at ${output}"
+
+ # Finish
+ if [ -z "$device" ]; then
+ echo "Image saved at ${output}"
+ else
+ echo "Removing image ${output}..."
+ rm ${output}
+ fi
+
+ echo "Done."
}
# Usage