From effd4a86a4c0eb73bcbe3329cf961a42a7582e03 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Thu, 12 Jan 2017 15:42:41 -0500 Subject: [PATCH] Fix bug with mounting DST --- fs_filecheck/etc/rc.local | 23 +++-- .../opt/groomer/{constraint.sh => config.sh} | 12 ++- fs_filecheck/opt/groomer/groomer.sh | 94 +++++++++++-------- fs_filecheck/opt/groomer/init.sh | 9 +- shell_utils/copy_groomer_to_image.sh | 2 +- 5 files changed, 85 insertions(+), 55 deletions(-) rename fs_filecheck/opt/groomer/{constraint.sh => config.sh} (68%) diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index 8efd17c..fba908f 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -16,18 +16,27 @@ clean(){ echo "GROOMER: rc.local done, shutting down." - sleep 60 + sleep 30 /sbin/shutdown -P -h now } -trap clean EXIT TERM INT - echo "GROOMER: end of boot, running rc.local." -# if [ -e /dev/sda ]; then -# if [ -e /dev/sdb ]; then +# Print the IP address (this doesn't work currently?) +# _IP=$(hostname -I) || true +# if [ "$_IP" ]; then +# printf "My IP address is %s\n" "$_IP" +# fi -cd /opt/groomer -./init.sh +if [ -e /dev/sda ]; then + if [ -e /dev/sdb ]; then + # avoid possible misuse - turn off eth0 (ethernet port) + /sbin/ifconfig eth0 down + trap clean EXIT TERM INT + cd /opt/groomer + /usr/sbin/led & + ./init.sh + fi +fi exit 0 diff --git a/fs_filecheck/opt/groomer/constraint.sh b/fs_filecheck/opt/groomer/config.sh similarity index 68% rename from fs_filecheck/opt/groomer/constraint.sh rename to fs_filecheck/opt/groomer/config.sh index d46a055..bde4fa8 100644 --- a/fs_filecheck/opt/groomer/constraint.sh +++ b/fs_filecheck/opt/groomer/config.sh @@ -1,6 +1,7 @@ DEV_SRC='/dev/sda' -DEV_SRCONE='/dev/sda1' -DEV_DST='/dev/sdb1' +DEV_SRC_ONE='/dev/sda1' +DEV_DST='/dev/sdb' +DEV_DST_ONE='/dev/sdb1' # User allowed to do the following commands without password USERNAME='kitten' @@ -13,13 +14,14 @@ SRC="src" DST="dst" SRC_MNT="/media/src" DST_MNT="/media/dst" -TEMP="${DST}/temp" -ZIPTEMP="${DST}/ziptemp" -LOGS="${DST}/logs" +TEMP="${DST_MNT}/temp" +ZIPTEMP="${DST_MNT}/ziptemp" +LOGS="${DST_MNT}/logs" GROOM_LOG="/tmp/groom_log.txt" # commands SYNC='/bin/sync' +TIMIDITY='/usr/bin/timidity' MOUNT='/bin/mount' PMOUNT='/usr/bin/pmount -A -s' PUMOUNT='/usr/bin/pumount' diff --git a/fs_filecheck/opt/groomer/groomer.sh b/fs_filecheck/opt/groomer/groomer.sh index 71a78f2..10d57a8 100755 --- a/fs_filecheck/opt/groomer/groomer.sh +++ b/fs_filecheck/opt/groomer/groomer.sh @@ -1,9 +1,11 @@ #!/bin/bash +# set -e (exit when a line returns non-0 status) and -x (xtrace) flags set -e set -x -source ./constraint.sh +source ./config.sh + if ! [ "${ID}" -ge "1000" ]; then echo "GROOMER: This script cannot run as root." exit @@ -12,8 +14,9 @@ fi clean(){ echo "GROOMER: Cleaning up after groomer.sh." - cp ${GROOM_LOG} "${DST_MNT}/groomer_log.txt" - + cp ${GROOM_LOG} "${DST_MNT}/groomer_log_dst.txt" + cp ${GROOM_LOG} "${SRC_MNT}/groomer_log_src.txt" + # Write anything in memory to disk ${SYNC} @@ -30,53 +33,66 @@ clean(){ trap clean EXIT TERM INT -# De we have a source device +# De we have a source device? if [ ! -b ${DEV_SRC} ]; then echo "GROOMER: Source device (${DEV_SRC}) does not exist." + exit fi +# Do we have a destination device +if [ ! -b ${DEV_DST} ]; then + echo "GROOMER: Destination device (${DEV_DST}) does not exist." + exit +fi + +# Make sure destination device isn't already mounted +if ${MOUNT}|grep ${DST}; then + ${PUMOUNT} ${DST} || true +fi + +# uid= only works on a vfat FS. What should wedo if we get an ext* FS ? +# What does this ^ comment mean? + +# Mount the first partition of DST (/dev/sdb1) +# pmount automatically mount on /media/, so at /media/dst in this case +${PMOUNT} -w ${DEV_DST_ONE} ${DST} +if [ ${?} -ne 0 ]; then + echo "GROOMER: Unable to mount ${DEV_DST_ONE} on ${DST_MNT}" + exit +else + echo "GROOMER: Destination USB device (${DEV_DST_ONE}) mounted at ${DST_MNT}" + + # Remove any existing "FROM_PARTITION_" directories + rm -rf "/media/${DST}/FROM_PARTITION_"* + + # prepare temp dirs and make sure they're empty if they already exist + mkdir -p "${TEMP}" + mkdir -p "${ZIPTEMP}" + mkdir -p "${LOGS}" + rm -rf "${TEMP}/"* + rm -rf "${ZIPTEMP}/"* + rm -rf "${LOGS}/"* +fi + +sleep 30 + +${PMOUNT} -w ${DEV_SRC_ONE} ${SRC} + +sleep 10 + +# Groom da kitteh! + +# List all block devices (uncomment for diagnostics) +# lsblk -n -o name,fstype,mountpoint,label,uuid -r + # Find the partition names on the source device DEV_PARTITIONS=`ls "${DEV_SRC}"* | grep "${DEV_SRC}[1-9][0-6]*" || true` if [ -z "${DEV_PARTITIONS}" ]; then echo "GROOMER: ${DEV_SRC} does not have any partitions." -fi - -# Do we have a destination device -if [ ! -b "${DEV_DST}" ]; then - echo "GROOMER: Destination device (/dev/${DEV_DST}) does not exist." -fi - -# mount and prepare destination device -if ${MOUNT}|grep ${DST}; then - ${PUMOUNT} ${DST} || true -fi -# uid= only works on a vfat FS. What should wedo if we get an ext* FS ? -${PMOUNT} -w ${DEV_DST} ${DST} -if [ ${?} -ne 0 ]; then - echo "GROOMER: Unable to mount ${DEV_DST} on ${DST_MNT}" exit -else - echo "GROOMER: Target USB device (${DEV_DST}) mounted at ${DST_MNT}" - - # rm -rf "/media/${DST}/FROM_PARTITION_"* - - # prepare temp dirs and make sure it's empty - # mkdir -p "${TEMP}" - # mkdir -p "${ZIPTEMP}" - # mkdir -p "${LOGS}" - - # rm -rf "${TEMP}/"* - # rm -rf "${ZIPTEMP}/"* - # rm -rf "${LOGS}/"* fi -${PMOUNT} -w ${DEV_SRCONE} ${SRC} - -# Groom da kitteh! - -# Find the FS types -# lsblk -n -o name,fstype,mountpoint,label,uuid -r - +sleep 10 # PARTCOUNT=1 # for partition in ${DEV_PARTITIONS} # do diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index 8558dc7..357d446 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -1,9 +1,10 @@ #!/bin/bash +# set -e (exit when a line returns non-0 status) and -x (xtrace) flags set -e set -x -source ./constraint.sh +source ./config.sh if [ ${ID} -ne 0 ]; then echo "GROOMER: This script has to be run as root." @@ -17,6 +18,8 @@ clean(){ trap clean EXIT TERM INT -fdisk -l |& tee ${GROOM_LOG} +lsblk -n -o name,fstype,mountpoint,label,uuid -r |& tee ${GROOM_LOG} -su ${USERNAME} -c ./groomer.sh |& tee ${GROOM_LOG} +sleep 30 + +su ${USERNAME} -c ./groomer.sh |& tee -a ${GROOM_LOG} diff --git a/shell_utils/copy_groomer_to_image.sh b/shell_utils/copy_groomer_to_image.sh index 1955d69..0651aa2 100755 --- a/shell_utils/copy_groomer_to_image.sh +++ b/shell_utils/copy_groomer_to_image.sh @@ -7,5 +7,5 @@ set -x cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt/rpi/opt/groomer/init.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/constraint.sh /mnt/rpi/opt/groomer/constraint.sh +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/config.sh /mnt/rpi/opt/groomer/config.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local \ No newline at end of file