-
Notifications
You must be signed in to change notification settings - Fork 3
/
mr_start.sh
executable file
·68 lines (57 loc) · 1.34 KB
/
mr_start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
SCRIPTDIR=`dirname $0`
ASSEMBLESCRIPT="${SCRIPTDIR}/mr_assemble.sh"
set -e
usage()
{
echo "$0: <MAP> <NAME>"
exit 1
}
if [ "$#" -ne "2" ]; then usage; fi
MAP="$1"
NAME="$2"
if [ `id -u` -ne "0" ]; then
echo "Got Root?"
exit 2
fi
if [ ! -r ${MAP} ]; then
echo "${MAP} is not readable!"
exit 3
fi
if [ ! -x ${ASSEMBLESCRIPT} ]; then
echo "${ASSEMBLESCRIPT} is not executable!"
exit 4
fi
if [ -b /dev/md/${NAME} ]; then
echo "/dev/md/${NAME} exists!"
exit 5
fi
LOBIN=`PATH="/sbin:/usr/sbin:$PATH" which losetup`
if [ "$?" != "0" ]; then
echo "losetup not found!"
exit 6
fi
# For each mount location in the map file
# Find the disk image that corresponds to the requested microraid ${NAME}
INDEX="0"
declare -a dimg_array
while read -r LINE; do
if [ ! -d ${LINE}/${NAME} ]; then
echo "${LINE}/${NAME} is not a directory!"; exit 7
fi
DIMG=`ls -1 ${LINE}/${NAME}/${NAME}.?.rimg`
if [ -z "${DIMG}" ]; then
echo "${LINE}/${NAME}/${NAME}.?.rimg does not exist!"; exit 8
fi
if [ ! -r ${DIMG} ]; then
echo "${DIMG} is not readable!"; exit 9
fi
if ${LOBIN} -a | grep -qw ${DIMG}; then
echo "${DIMG} appears to be looped already!"; exit 10
fi
dimg_array[${INDEX}]="${DIMG}"
INDEX=$(( INDEX+1 ))
done < ${MAP}
# Assemble all these images into a RAID device
${ASSEMBLESCRIPT} ${dimg_array[@]}
exit $?