Skip to content

Commit

Permalink
Adjust exit codes of nested scripts to avoid collision
Browse files Browse the repository at this point in the history
  • Loading branch information
Fullaxx committed Apr 30, 2020
1 parent de4558c commit c84ac6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
12 changes: 6 additions & 6 deletions mr_assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ set -e

if [ `id -u` -ne "0" ]; then
echo "Got Root?"
exit 1
exit 21
fi

LOBIN=`PATH="/sbin:/usr/sbin:$PATH" which losetup`
if [ "$?" != "0" ]; then
echo "losetup not found!"
exit 2
exit 22
fi

MDBIN=`PATH="/sbin:/usr/sbin:$PATH" which mdadm`
if [ "$?" != "0" ]; then
echo "mdadm not found!"
exit 3
exit 23
fi

# Loop all our images and create an array upon success
Expand Down Expand Up @@ -46,15 +46,15 @@ NEWRAID=`grep -w ${FIRSTDEV} /proc/mdstat | awk '{print $1}'`

if [ -z "${NEWRAID}" ]; then
echo "${FIRSTDEV} does not appear to be attached to a raid device!"
exit 4
exit 24
fi

if ${MDBIN} --detail /dev/${NEWRAID} | grep 'State :' | cut -d: -f2- | grep -qw inactive; then
echo "/dev/${NEWRAID} has been partially assembled, but did not run (state: inactive)"
echo "You will have to run manually and troubleshoot:"
echo "mdadm -R /dev/${NEWRAID}"
echo "mdadm --detail /dev/${NEWRAID}"
exit 5
exit 25
fi

#RAIDCOUNT=`ls -1 /dev/md/ 2>/dev/null | wc -l`
Expand All @@ -80,4 +80,4 @@ done

# We couldn't find the named raid device?
echo "raid device not found under /dev/md/"
exit 6
exit 26
14 changes: 7 additions & 7 deletions mr_detach.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ set -e

if [ "$#" -ne "2" ]; then
echo "$0: <MAP> <NAME>"
exit 1
exit 21
fi

MAP="$1"
NAME="$2"

if [ `id -u` -ne "0" ]; then
echo "Got Root?"
exit 2
exit 22
fi

if [ ! -r ${MAP} ]; then
echo "${MAP} is not readable!"
exit 3
exit 23
fi

LOBIN=`PATH="/sbin:/usr/sbin:$PATH" which losetup`
if [ "$?" != "0" ]; then
echo "losetup not found!"
exit 4
exit 24
fi

echo "Searching for ${NAME} ..."
Expand All @@ -35,7 +35,7 @@ RAIDCOUNT="0"
declare -a loop_array
while read -r LINE; do
if [ ! -d ${LINE}/${NAME} ]; then
echo "${LINE}/${NAME} is not a directory!"; exit 5
echo "${LINE}/${NAME} is not a directory!"; exit 25
fi
DIMG=`ls -1 ${LINE}/${NAME}/${NAME}.?.rimg`

Expand Down Expand Up @@ -64,13 +64,13 @@ echo
# If ${NAME} is not active, we could exit 0 here?
if [ "${INDEX}" == "0" ]; then
echo "${NAME} does not appear to be active"
exit 6
exit 26
fi

# RAIDCOUNT should equal zero b/c the raid should have been dismantled by now
if [ "${RAIDCOUNT}" != "0" ]; then
echo "RAID appears to be active, Cowardly refusing to continue!"
exit 7
exit 27
fi

# echo "${loop_array[@]}"
Expand Down
7 changes: 1 addition & 6 deletions mr_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,4 @@ done < ${MAP}

# Assemble all these images into a RAID device
${ASSEMBLESCRIPT} ${dimg_array[@]}

# IS THIS UNNECESSARY ??
#if [ ! -b /dev/md/*${NAME} ]; then
# echo "Could not find block device for ${NAME}"
# exit 6
#fi
exit $?

0 comments on commit c84ac6b

Please sign in to comment.