#!/bin/sh set -x setglobal MOUNTPOINT = $1 test -z $MOUNTPOINT && echo "No mountpoint specified" && exit 1 mkdir -p $MOUNTPOINT proc mount_drive { # TODO fix for multiple disks, cdroms etc setglobal DEVS = $[find /dev -maxdepth 1 -type b ! -name 'loop*' ! -name 'nbd*' | grep -v '[0-9]$' | sed 's@.*/dev/@@' | sort] for DEV in [$DEVS] { setglobal DRIVE = ""/dev/$(DEV)"" # see if it has a partition table if sfdisk -d $(DRIVE) >/dev/null !2 >/dev/null { # 83 is Linux partition identifier setglobal DATA = $[sfdisk -J $DRIVE | jq -e -r '.partitiontable.partitions | map(select(.type=="83")) | .[0].node] if test $Status -eq 0 { mount $DATA $MOUNTPOINT && return } } } echo "WARNING: Failed to mount a persistent volume (is there one?)" } mount_drive