summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/mkefidisk.sh
diff options
context:
space:
mode:
authorDarren Hart <dvhart@linux.intel.com>2014-07-16 14:16:01 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-07-19 00:09:00 +0100
commitfd8a230e1acda64e7cd1ad4fb7668b9c58b9228a (patch)
treecb4fde12588cef05cccd931a36f45f3717c1a301 /scripts/contrib/mkefidisk.sh
parentda682642bae01e9717e5afdad4db62f4c7f406db (diff)
downloadpoky-fd8a230e1acda64e7cd1ad4fb7668b9c58b9228a.tar.gz
mkefidisk.sh: Improve logging
Add logging functions: error, warn, info, and success, using tput to add color highlighting. Use these routines throughout the script, replacing echo statements and adding "|| error" in several places to eliminate silent failures. Add a simple exit block which checks for issues encountered while running. (From OE-Core rev: b5a3f6465a7fd8e821b81da053bf7e11535f1652) Signed-off-by: Darren Hart <dvhart@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/contrib/mkefidisk.sh')
-rwxr-xr-xscripts/contrib/mkefidisk.sh92
1 files changed, 60 insertions, 32 deletions
diff --git a/scripts/contrib/mkefidisk.sh b/scripts/contrib/mkefidisk.sh
index 98c43f5d87..530b7842bb 100755
--- a/scripts/contrib/mkefidisk.sh
+++ b/scripts/contrib/mkefidisk.sh
@@ -28,6 +28,29 @@ BOOT_SIZE=20
28# 5% for swap 28# 5% for swap
29SWAP_RATIO=5 29SWAP_RATIO=5
30 30
31# Logging routines
32WARNINGS=0
33ERRORS=0
34CLEAR="$(tput sgr0)"
35INFO="$(tput bold)"
36RED="$(tput setaf 1)$(tput bold)"
37GREEN="$(tput setaf 2)$(tput bold)"
38YELLOW="$(tput setaf 3)$(tput bold)"
39info() {
40 echo "${INFO}$1${CLEAR}"
41}
42error() {
43 ERRORS=$((ERRORS+1))
44 echo "${RED}$1${CLEAR}"
45}
46warn() {
47 WARNINGS=$((WARNINGS+1))
48 echo "${YELLOW}$1${CLEAR}"
49}
50success() {
51 echo "${GREEN}$1${CLEAR}"
52}
53
31usage() { 54usage() {
32 echo "Usage: $(basename $0) DEVICE HDDIMG TARGET_DEVICE" 55 echo "Usage: $(basename $0) DEVICE HDDIMG TARGET_DEVICE"
33 echo " DEVICE: The device to write the image to, e.g. /dev/sdh" 56 echo " DEVICE: The device to write the image to, e.g. /dev/sdh"
@@ -37,7 +60,7 @@ usage() {
37 60
38image_details() { 61image_details() {
39 IMG=$1 62 IMG=$1
40 echo "Image details" 63 info "Image details"
41 echo "=============" 64 echo "============="
42 echo " image: $(stat --printf '%N\n' $IMG)" 65 echo " image: $(stat --printf '%N\n' $IMG)"
43 echo " size: $(stat -L --printf '%s bytes\n' $IMG)" 66 echo " size: $(stat -L --printf '%s bytes\n' $IMG)"
@@ -50,7 +73,7 @@ device_details() {
50 DEV=$1 73 DEV=$1
51 BLOCK_SIZE=512 74 BLOCK_SIZE=512
52 75
53 echo "Device details" 76 info "Device details"
54 echo "==============" 77 echo "=============="
55 echo " device: $DEVICE" 78 echo " device: $DEVICE"
56 if [ -f "/sys/class/block/$DEV/device/vendor" ]; then 79 if [ -f "/sys/class/block/$DEV/device/vendor" ]; then
@@ -74,14 +97,13 @@ device_details() {
74unmount_device() { 97unmount_device() {
75 grep -q $DEVICE /proc/mounts 98 grep -q $DEVICE /proc/mounts
76 if [ $? -eq 0 ]; then 99 if [ $? -eq 0 ]; then
77 echo -n "$DEVICE listed in /proc/mounts, attempting to unmount..." 100 warn "$DEVICE listed in /proc/mounts, attempting to unmount..."
78 umount $DEVICE* 2>/dev/null 101 umount $DEVICE* 2>/dev/null
79 grep -q $DEVICE /proc/mounts 102 grep -q $DEVICE /proc/mounts
80 if [ $? -eq 0 ]; then 103 if [ $? -eq 0 ]; then
81 echo "FAILED" 104 error "Failed to unmount $DEVICE"
82 exit 1 105 exit 1
83 fi 106 fi
84 echo "OK"
85 fi 107 fi
86} 108}
87 109
@@ -104,13 +126,13 @@ if [ $? -eq 0 ]; then
104fi 126fi
105 127
106if [ ! -w "$DEVICE" ]; then 128if [ ! -w "$DEVICE" ]; then
107 echo "ERROR: Device $DEVICE does not exist or is not writable" 129 error "Device $DEVICE does not exist or is not writable"
108 usage 130 usage
109 exit 1 131 exit 1
110fi 132fi
111 133
112if [ ! -e "$HDDIMG" ]; then 134if [ ! -e "$HDDIMG" ]; then
113 echo "ERROR: HDDIMG $HDDIMG does not exist" 135 error "HDDIMG $HDDIMG does not exist"
114 usage 136 usage
115 exit 1 137 exit 1
116fi 138fi
@@ -127,7 +149,7 @@ unmount_device
127# 149#
128image_details $HDDIMG 150image_details $HDDIMG
129device_details $(basename $DEVICE) 151device_details $(basename $DEVICE)
130echo -n "Prepare EFI image on $DEVICE [y/N]? " 152echo -n "${INFO}Prepare EFI image on $DEVICE [y/N]?${CLEAR} "
131read RESPONSE 153read RESPONSE
132if [ "$RESPONSE" != "y" ]; then 154if [ "$RESPONSE" != "y" ]; then
133 echo "Image creation aborted" 155 echo "Image creation aborted"
@@ -208,17 +230,16 @@ unmount_device
208echo "" 230echo ""
209echo "Formatting $BOOTFS as vfat..." 231echo "Formatting $BOOTFS as vfat..."
210if [ ! "${DEVICE#/dev/loop}" = "${DEVICE}" ]; then 232if [ ! "${DEVICE#/dev/loop}" = "${DEVICE}" ]; then
211 mkfs.vfat -I $BOOTFS -n "EFI" 233 mkfs.vfat -I $BOOTFS -n "EFI" || error "Failed to format $BOOTFS"
212else 234else
213 mkfs.vfat $BOOTFS -n "EFI" 235 mkfs.vfat $BOOTFS -n "EFI" || error "Failed to format $BOOTFS"
214
215fi 236fi
216 237
217echo "Formatting $ROOTFS as ext3..." 238echo "Formatting $ROOTFS as ext3..."
218mkfs.ext3 -F $ROOTFS -L "ROOT" 239mkfs.ext3 -F $ROOTFS -L "ROOT" || error "Failed to format $ROOTFS"
219 240
220echo "Formatting swap partition...($SWAP)" 241echo "Formatting swap partition...($SWAP)"
221mkswap $SWAP 242mkswap $SWAP || error "Failed to prepare swap"
222 243
223 244
224# 245#
@@ -228,7 +249,7 @@ echo ""
228echo "Mounting images and device in preparation for installation..." 249echo "Mounting images and device in preparation for installation..."
229TMPDIR=$(mktemp -d mkefidisk-XXX) 250TMPDIR=$(mktemp -d mkefidisk-XXX)
230if [ $? -ne 0 ]; then 251if [ $? -ne 0 ]; then
231 echo "ERROR: Failed to create temporary mounting directory." 252 error "Failed to create temporary mounting directory."
232 exit 1 253 exit 1
233fi 254fi
234HDDIMG_MNT=$TMPDIR/hddimg 255HDDIMG_MNT=$TMPDIR/hddimg
@@ -240,17 +261,15 @@ mkdir $HDDIMG_ROOTFS_MNT
240mkdir $ROOTFS_MNT 261mkdir $ROOTFS_MNT
241mkdir $BOOTFS_MNT 262mkdir $BOOTFS_MNT
242 263
243mount -o loop $HDDIMG $HDDIMG_MNT 264mount -o loop $HDDIMG $HDDIMG_MNT || error "Failed to mount $HDDIMG"
244if [ $? -ne 0 ]; then echo "ERROR: Failed to mount $HDDIMG"; fi
245 265
246mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT 266mount -o loop $HDDIMG_MNT/rootfs.img $HDDIMG_ROOTFS_MNT || error "Failed to mount rootfs.img"
247if [ $? -ne 0 ]; then echo "ERROR: Failed to mount rootfs.img"; fi
248 267
249mount $ROOTFS $ROOTFS_MNT 268mount $ROOTFS $ROOTFS_MNT || error "Failed to mount $ROOTFS on $ROOTFS_MNT"
250mount $BOOTFS $BOOTFS_MNT 269mount $BOOTFS $BOOTFS_MNT || error "Failed to mount $BOOTFS on $BOOTFS_MNT"
251 270
252echo "Copying ROOTFS files..." 271echo "Copying ROOTFS files..."
253cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT 272cp -a $HDDIMG_ROOTFS_MNT/* $ROOTFS_MNT || error "Root FS copy failed"
254 273
255echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab 274echo "$TARGET_SWAP swap swap defaults 0 0" >> $ROOTFS_MNT/etc/fstab
256 275
@@ -259,14 +278,14 @@ if [ -d $ROOTFS_MNT/etc/udev/ ] ; then
259 echo "$TARGET_DEVICE" >> $ROOTFS_MNT/etc/udev/mount.blacklist 278 echo "$TARGET_DEVICE" >> $ROOTFS_MNT/etc/udev/mount.blacklist
260fi 279fi
261 280
262umount $ROOTFS_MNT 281umount $ROOTFS_MNT || error "Failed to unmount $ROOTFS_MNT"
263umount $HDDIMG_ROOTFS_MNT 282umount $HDDIMG_ROOTFS_MNT || error "Failed to unmount $HDDIMG_ROOTFS_MNT"
264 283
265echo "Preparing boot partition..." 284echo "Preparing boot partition..."
266EFIDIR="$BOOTFS_MNT/EFI/BOOT" 285EFIDIR="$BOOTFS_MNT/EFI/BOOT"
267cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT 286cp $HDDIMG_MNT/vmlinuz $BOOTFS_MNT || error "Failed to copy vmlinuz"
268# Copy the efi loader and configs (booti*.efi and grub.cfg if it exists) 287# Copy the efi loader and configs (booti*.efi and grub.cfg if it exists)
269cp -r $HDDIMG_MNT/EFI $BOOTFS_MNT 288cp -r $HDDIMG_MNT/EFI $BOOTFS_MNT || error "Failed to copy EFI dir"
270# Silently ignore a missing gummiboot loader dir (we might just be a GRUB image) 289# Silently ignore a missing gummiboot loader dir (we might just be a GRUB image)
271cp -r $HDDIMG_MNT/loader $BOOTFS_MNT 2> /dev/null 290cp -r $HDDIMG_MNT/loader $BOOTFS_MNT 2> /dev/null
272 291
@@ -281,7 +300,7 @@ cp -r $HDDIMG_MNT/loader $BOOTFS_MNT 2> /dev/null
281# Look for a GRUB installation 300# Look for a GRUB installation
282GRUB_CFG="$EFIDIR/grub.cfg" 301GRUB_CFG="$EFIDIR/grub.cfg"
283if [ -e "$GRUB_CFG" ]; then 302if [ -e "$GRUB_CFG" ]; then
284 echo "Configuring GRUB" 303 info "Configuring GRUB"
285 # Delete the install entry 304 # Delete the install entry
286 sed -i "/menuentry 'install'/,/^}/d" $GRUB_CFG 305 sed -i "/menuentry 'install'/,/^}/d" $GRUB_CFG
287 # Delete the initrd lines 306 # Delete the initrd lines
@@ -297,7 +316,7 @@ fi
297GUMMI_ENTRIES="$BOOTFS_MNT/loader/entries" 316GUMMI_ENTRIES="$BOOTFS_MNT/loader/entries"
298GUMMI_CFG="$GUMMI_ENTRIES/boot.conf" 317GUMMI_CFG="$GUMMI_ENTRIES/boot.conf"
299if [ -d "$GUMMI_ENTRIES" ]; then 318if [ -d "$GUMMI_ENTRIES" ]; then
300 echo "Configuring Gummiboot" 319 info "Configuring Gummiboot"
301 # remove the install target if it exists 320 # remove the install target if it exists
302 rm $GUMMI_ENTRIES/install.conf &> /dev/null 321 rm $GUMMI_ENTRIES/install.conf &> /dev/null
303 322
@@ -311,12 +330,21 @@ fi
311 330
312# Ensure we have at least one EFI bootloader configured 331# Ensure we have at least one EFI bootloader configured
313if [ ! -e $GRUB_CFG ] && [ ! -e $GUMMI_CFG ]; then 332if [ ! -e $GRUB_CFG ] && [ ! -e $GUMMI_CFG ]; then
314 echo "ERROR: No EFI bootloader configuration found" 333 error "No EFI bootloader configuration found"
315fi 334fi
316 335
317umount $BOOTFS_MNT 336umount $BOOTFS_MNT || error "Failed to unmount $BOOTFS_MNT"
318umount $HDDIMG_MNT 337umount $HDDIMG_MNT || error "Failed to unmount $HDDIMG_MNT"
319rm -rf $TMPDIR 338rm -rf $TMPDIR || error "Failed to cleanup $TMPDIR"
320sync 339sync
321 340
322echo "Installation complete" 341if [ $WARNINGS -ne 0 ] && [ $ERRORS -eq 0 ]; then
342 echo "${YELLOW}Installation completed with warnings${CLEAR}"
343 echo "${YELLOW}Warnings: $WARNINGS${CLEAR}"
344elif [ $ERRORS -ne 0 ]; then
345 echo "${RED}Installation encountered errors${CLEAR}"
346 echo "${RED}Errors: $ERRORS${CLEAR}"
347 echo "${YELLOW}Warnings: $WARNINGS${CLEAR}"
348else
349 success "Installation completed successfully"
350fi