diff options
author | Jonathan Bauer | 2015-05-06 18:13:52 +0200 |
---|---|---|
committer | Jonathan Bauer | 2015-05-06 18:13:52 +0200 |
commit | b3312f86061a0d887233f5068cbc335aa2612bed (patch) | |
tree | 32a0bace5eb6a7afeb29dae80d7f01fefecb36cc /testModule/scripts/prepare-disks | |
parent | Merge branch 'master' of git.openslx.org:openslx-ng/systemd-init (diff) | |
download | systemd-init-b3312f86061a0d887233f5068cbc335aa2612bed.tar.gz systemd-init-b3312f86061a0d887233f5068cbc335aa2612bed.tar.xz systemd-init-b3312f86061a0d887233f5068cbc335aa2612bed.zip |
current state: udev disk detection still not done!
also improved module structure and code commentary
Diffstat (limited to 'testModule/scripts/prepare-disks')
-rwxr-xr-x | testModule/scripts/prepare-disks | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/testModule/scripts/prepare-disks b/testModule/scripts/prepare-disks new file mode 100755 index 00000000..28113cc7 --- /dev/null +++ b/testModule/scripts/prepare-disks @@ -0,0 +1,98 @@ +#!/bin/bash +############################################################################### +# GLOBALS +# + +declare -rg FLAG="/tmp/openslx.disks" +declare -rg OPENSLX_SYS_MOUNT="/opt/openslx/system" + +# +# END GLOBALS +############################################################################### + +############################################################################### +# FUNCTION DEFINITIONS +# +# helper to mount the OPENSLX_SYS partition to /opt/openslx/system +# Usage: mount_sys_part <path_to_sys_partition> +mount_sys_part() { + if [ ! -b "$1" ]; then + warn "'$1' is not a block device?" + echo "!block: $1" >> /tmp/openslx.disks.log + return 1 + fi + + local OPENSLX_SYS_DEVICE="$1" + mkdir -p ${OPENSLX_SYS_MOUNT} + if ! mount -t auto "${OPENSLX_SYS_DEVICE}" "${OPENSLX_SYS_MOUNT}"; then + warn "Mounting '${OPENSLX_SYS_DEVICE}' to '${OPENSLX_SYS_MOUNT}' failed." + echo "mount phail" >> /tmp/openslx.disks.log + return 1 + fi + echo "ZOMG" >> /tmp/openslx.disks.log + return 0 + +} +# +# END FUNCTION DEFINITIONS +############################################################################### + +############################################################################### +# MAIN CODE +# + +command -v warn >/dev/null || . /lib/dracut-lib.sh + +# let check the arguments +if [ "$#" -ne 2 ]; then + warn "'$0' need 2 arguments: '$0 [OPENSLX_SYS|OPENSLX_TMP] <dev_path>'" + echo "Not enough args!" >> /tmp/openslx.disks.log + exit 1 +fi +# $1 sane? +if [ "x$1" != "xOPENSLX_SYS" ] && [ "x$1" != "xOPENSLX_TMP" ]; then + warn "First arg needs to be either 'OPENSLX_SYS' or 'OPENSLX_TMP'." + warn "Given: $1" + echo "OPENSLX? $1" >> /tmp/openslx.disks.log + exit 1 +fi +# $2 sane? +if [ ! -b "/dev/$2" ]; then + warn "Second arg appears not to be a block device!" + echo "block? $2" >> /tmp/openslx.disks.log + exit 1 +fi + +# ok all seems well +PART_TYPE="$1" +PART_DEV="/dev/$2" + +# lets check if we are already running +INSTANCES="$(grep "$PART_TYPE" "$FLAG" | busybox wc -l)" +if [ "$INSTANCES" -ge 1 ]; then + # uhoh we are not alone! + warn "'$0' already running for $PART_TYPE ... ignoring." + echo "already running for $PART_TYPE" >> /tmp/openslx.disks.log + exit 1 +fi + +# now comes the funny part. We write our pid to $FLAG in order to make sure +# we are the only instance of this script running. +echo "$PART_TYPE.$$" >> "$FLAG" + +# if we are still here, then we can go on and process the partition +echo "Processing: $PART_TYPE -> $PART_DEV" >> /tmp/openslx.disks.log + +if [ "$PART_TYPE" = "OPENSLX_TMP" ]; then + # mark it for later mounting! + echo "$PART_DEV" > /tmp/openslx.disk.tmp + exit 0 +fi +if [ "$PART_TYPE" = "OPENSLX_SYS" ]; then + # mount it now, since qemu-nbd needs it asap! + exit $(mount_sys_part "$PART_DEV") +fi + +# +# END MAIN CODE +############################################################################### |