summaryrefslogtreecommitdiffstats
path: root/upslak.sh
diff options
context:
space:
mode:
author Eric Hameleers <alien@slackware.com>2019-05-05 17:38:06 +0200
committer Eric Hameleers <alien@slackware.com>2019-05-05 17:38:06 +0200
commitb2ad4f14e54b907ab6fd304631882f2758b616ad (patch)
tree566886ca7e95473554cfa2237254291e8997f1ad /upslak.sh
parentf634f2d298277eeec7e23daa6a975754d8139199 (diff)
downloadliveslak-b2ad4f14e54b907ab6fd304631882f2758b616ad.tar.gz
liveslak-b2ad4f14e54b907ab6fd304631882f2758b616ad.tar.xz
upslak.sh: use the OS to find partition names
This should allow usage of external storage devices like SD cards, whose partition naming conventions are different from generic USB devices. E.g. /dev/mmcblk0p1 is the first partition of /dev/mmcblk0 (note the 'p').
Diffstat (limited to 'upslak.sh')
-rw-r--r--upslak.sh23
1 files changed, 14 insertions, 9 deletions
diff --git a/upslak.sh b/upslak.sh
index 1af67fb..a3e64ee 100644
--- a/upslak.sh
+++ b/upslak.sh
@@ -122,7 +122,7 @@ USBMNT=""
EFIMNT=""
# These tools are required by the script, we will check for their existence:
-REQTOOLS="cpio gdisk inotifywait strings xz"
+REQTOOLS="cpio gdisk inotifywait lsblk strings xz"
# Compressor used on the initrd ("gzip" or "xz --check=crc32");
# Note that the kernel's XZ decompressor does not understand CRC64:
@@ -210,7 +210,7 @@ show_devices() {
echo "# Removable devices detected on this computer:"
for BD in ${MYDATA} ; do
if [ $(cat /sys/block/${BD}/removable) -eq 1 ]; then
- echo "# /dev/${BD} : $(cat /sys/block/${BD}/device/vendor) $(cat /sys/block/${BD}/device/model): $(( $(cat /sys/block/${BD}/size) / 2048)) MB"
+ echo "# /dev/${BD} : $(cat /sys/block/${BD}/device/vendor 2>/dev/null) $(cat /sys/block/${BD}/device/model 2>/dev/null): $(( $(cat /sys/block/${BD}/size) / 2048)) MB"
fi
done
echo "#"
@@ -655,12 +655,12 @@ elif [ $SCAN -eq 1 ]; then
exit 1
fi
-if [ ! -b $TARGET ]; then
+if [ ! -e /sys/block/$(basename $TARGET) ]; then
echo "*** Not a block device: '$TARGET' !"
show_devices
exit 1
-elif [ "$(echo ${TARGET%%[0-9]*})" != "$TARGET" ]; then
- echo "*** You need to point to the USB device, not a partition ($TARGET)!"
+elif lsblk -l $TARGET |grep -w $(basename $TARGET) |grep -wq part ; then
+ echo "*** You need to point to the storage device itself, not a partition ($TARGET)!"
show_devices
exit 1
fi
@@ -740,8 +740,8 @@ cat <<EOT
# We are going to update the Live OS on this device.
# ---------------------------------------------------------------------------
# Target is - '$TARGET':
-# Vendor : $(cat /sys/block/$(basename $TARGET)/device/vendor)
-# Model : $(cat /sys/block/$(basename $TARGET)/device/model)
+# Vendor : $(cat /sys/block/$(basename $TARGET)/device/vendor 2>/dev/null)
+# Model : $(cat /sys/block/$(basename $TARGET)/device/model 2>/dev/null)
# Size : $(( $(cat /sys/block/$(basename $TARGET)/size) / 2048)) MB
# ---------------------------------------------------------------------------
#
@@ -768,6 +768,11 @@ EOT
fi
# OK... the user was sure about the drive...
+# Determine the three partition names independently of storage architecture:
+TARGETP1=$(fdisk -l $TARGET |grep ^$TARGET |cut -d' ' -f1 |grep -E '[^0-9]1$')
+TARGETP2=$(fdisk -l $TARGET |grep ^$TARGET |cut -d' ' -f1 |grep -E '[^0-9]2$')
+TARGETP3=$(fdisk -l $TARGET |grep ^$TARGET |cut -d' ' -f1 |grep -E '[^0-9]3$')
+
# Create a temporary extraction directory for the initrd:
mkdir -p /mnt
IMGDIR=$(mktemp -d -p /mnt -t alienimg.XXXXXX)
@@ -799,10 +804,10 @@ else
fi
# Mount the Linux partition:
-mount -t auto ${TARGET}3 ${USBMNT}
+mount -t auto ${TARGETP3} ${USBMNT}
# Mount the EFI partition:
-mount -t vfat -o shortname=mixed ${TARGET}2 ${EFIMNT}
+mount -t vfat -o shortname=mixed ${TARGETP2} ${EFIMNT}
# Determine size of the Linux partition (in MB), and the free space:
USBPSIZE=$(get_part_mb_size ${USBMNT})