Split part of groomer.sh into mount_dest.sh

pull/46/head
Dan Puttick 2017-01-13 17:05:37 -05:00
parent effd4a86a4
commit a8a670c08e
6 changed files with 140 additions and 123 deletions

View File

@ -16,7 +16,6 @@
clean(){ clean(){
echo "GROOMER: rc.local done, shutting down." echo "GROOMER: rc.local done, shutting down."
sleep 30
/sbin/shutdown -P -h now /sbin/shutdown -P -h now
} }

33
fs_filecheck/opt/groomer/config.sh Normal file → Executable file
View File

@ -1,27 +1,28 @@
DEV_SRC='/dev/sda' USERNAME="kitten"
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'
MUSIC="/opt/midi/"
ID=`/usr/bin/id -u` ID=`/usr/bin/id -u`
# Paths used in multiple scripts # Paths used in multiple scripts
SRC="src" SRC="src"
DST="dst" DEV_SRC="/dev/sda"
DEV_SRC_ONE="/dev/sda1"
SRC_MNT="/media/src" SRC_MNT="/media/src"
DST="dst"
DEV_DST="/dev/sdb"
DEV_DST_ONE="/dev/sdb1"
DST_MNT="/media/dst" DST_MNT="/media/dst"
TEMP="${DST_MNT}/temp" TEMP="${DST_MNT}/temp"
ZIPTEMP="${DST_MNT}/ziptemp" ZIPTEMP="${DST_MNT}/ziptemp"
LOGS="${DST_MNT}/logs" LOGS="${DST_MNT}/logs"
GROOM_LOG="/tmp/groom_log.txt" GROOM_LOG="/tmp/groom_log.txt"
MUSIC="/opt/midi/"
# commands
SYNC='/bin/sync' # Commands
TIMIDITY='/usr/bin/timidity' SYNC="/bin/sync"
MOUNT='/bin/mount' TIMIDITY="/usr/bin/timidity"
PMOUNT='/usr/bin/pmount -A -s' MOUNT="/bin/mount"
PUMOUNT='/usr/bin/pumount' PMOUNT="/usr/bin/pmount -A -s"
PUMOUNT="/usr/bin/pumount"

View File

@ -4,87 +4,25 @@
set -e set -e
set -x set -x
# Import constants from config file
source ./config.sh source ./config.sh
if ! [ "${ID}" -ge "1000" ]; then if ! [ "${ID}" -ge "1000" ]; then
echo "GROOMER: This script cannot run as root." echo "GROOMER: groomer.sh cannot run as root."
exit exit
fi fi
clean(){ clean(){
echo "GROOMER: Cleaning up after groomer.sh."
cp ${GROOM_LOG} "${DST_MNT}/groomer_log_dst.txt"
cp ${GROOM_LOG} "${SRC_MNT}/groomer_log_src.txt"
# Write anything in memory to disk # Write anything in memory to disk
${SYNC} ${SYNC}
# Unmount source # Remove temporary files from destination key
pumount ${SRC}
# Clean up and unmount destination
rm -rf ${TEMP} rm -rf ${TEMP}
rm -rf ${ZIPTEMP} rm -rf ${ZIPTEMP}
pumount ${DST}
exit
} }
trap clean EXIT TERM INT trap clean EXIT TERM INT
# 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 # Find the partition names on the source device
DEV_PARTITIONS=`ls "${DEV_SRC}"* | grep "${DEV_SRC}[1-9][0-6]*" || true` DEV_PARTITIONS=`ls "${DEV_SRC}"* | grep "${DEV_SRC}[1-9][0-6]*" || true`
if [ -z "${DEV_PARTITIONS}" ]; then if [ -z "${DEV_PARTITIONS}" ]; then
@ -92,42 +30,46 @@ if [ -z "${DEV_PARTITIONS}" ]; then
exit exit
fi fi
sleep 10 PARTCOUNT=1
# PARTCOUNT=1 for partition in ${DEV_PARTITIONS}
# for partition in ${DEV_PARTITIONS} do
# do echo "GROOMER: Processing partition ${partition}"
# # Processing a partition # Unmount anything that is mounted on /media/src
# echo "GROOMER: Processing partition ${partition}" if [ `${MOUNT} | grep -c ${SRC}` -ne 0 ]; then
# if [ `${MOUNT} | grep -c ${SRC}` -ne 0 ]; then ${PUMOUNT} ${SRC}
# ${PUMOUNT} ${SRC} fi
# fi
# ${PMOUNT} -w ${partition} ${SRC} # Mount the current partition in write mode
# ls "/media/${SRC}" | grep -i autorun.inf | xargs -I {} mv "/media/${SRC}"/{} "/media/${SRC}"/DANGEROUS_{}_DANGEROUS || true ${PMOUNT} -w ${partition} ${SRC}
# ${PUMOUNT} ${SRC} # Mark any autorun.inf files as dangerous on the source device
# ${PMOUNT} -r ${partition} ${SRC} ls ${SRC_MNT} | grep -i autorun.inf | xargs -I {} mv "${SRC_MNT}"/{} "{SRC_MNT}"/DANGEROUS_{}_DANGEROUS || true
# if [ ${?} -ne 0 ]; then # Unmount and remount the current partition in read-only mode
# echo "GROOMER: Unable to mount ${partition} on /media/${SRC}" ${PUMOUNT} ${SRC}
# else ${PMOUNT} -r ${partition} ${SRC}
# echo "GROOMER: ${partition} mounted at /media/${SRC}" if [ ${?} -ne 0 ]; then
# Previous command (mounting this partition) failed
echo "GROOMER: Unable to mount ${partition} on /media/${SRC}"
else
echo "GROOMER: ${partition} mounted at /media/${SRC}"
# # Print the filenames on the current partition in a logfile # Put the filenames from the current partition in a logfile
# find "/media/${SRC}" -fls "${LOGS}/Content_partition_${PARTCOUNT}.txt" find "/media/${SRC}" -fls "${LOGS}/contents_partition_${PARTCOUNT}.txt"
# # create a directory on ${DST} named PARTION_$PARTCOUNT # Create a directory on ${DST} named PARTION_$PARTCOUNT
# target_dir="/media/${DST}/FROM_PARTITION_${PARTCOUNT}" target_dir="/media/${DST}/FROM_PARTITION_${PARTCOUNT}"
# echo "GROOMER: Copying to ${target_dir}" mkdir -p "${target_dir}"
# mkdir -p "${target_dir}" LOGFILE="${LOGS}/processing.txt"
# LOGFILE="${LOGS}/processing.txt"
# echo "GROOMER: ==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE} # Run the current partition through filecheck.py
# filecheck.py --source /media/${SRC} --destination ${target_dir} || true echo "GROOMER: ==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE}
# echo "GROOMER: ==== Done with /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE} filecheck.py --source /media/${SRC} --destination ${target_dir} || true
echo "GROOMER: ==== Done with /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE}
# ls -lR "${target_dir}" # List destination files (recursively) for debugging
# fi ls -lR "${target_dir}"
# let PARTCOUNT=`expr $PARTCOUNT + 1` fi
# done let PARTCOUNT=`expr $PARTCOUNT + 1`
done
# The cleanup is automatically done in the function clean called when # The cleanup is automatically done in the function clean called when
# the program quits # the program exits

View File

@ -4,6 +4,7 @@
set -e set -e
set -x set -x
# Import constants from config file
source ./config.sh source ./config.sh
if [ ${ID} -ne 0 ]; then if [ ${ID} -ne 0 ]; then
@ -18,8 +19,7 @@ clean(){
trap clean EXIT TERM INT trap clean EXIT TERM INT
lsblk -n -o name,fstype,mountpoint,label,uuid -r |& tee ${GROOM_LOG} # List block storage devices (for debugging)
lsblk |& tee ${GROOM_LOG}
sleep 30 su ${USERNAME} -c ./mount_dest.sh |& tee -a ${GROOM_LOG}
su ${USERNAME} -c ./groomer.sh |& tee -a ${GROOM_LOG}

View File

@ -0,0 +1,77 @@
#!/bin/bash
# set -e (exit when a line returns non-0 status) and -x (xtrace) flags
set -e
set -x
# Import constants from config file
source ./config.sh
if ! [ "${ID}" -ge "1000" ]; then
echo "GROOMER: mount_keys.sh cannot run as root."
exit
fi
clean(){
echo "GROOMER: Cleaning up in mount_keys.sh."
# Copy the temporary logfile to the destination key
cp ${GROOM_LOG} "${DST_MNT}/groomer_log_dst.txt"
# Write anything in memory to disk
${SYNC}
# Unmount source and destination
pumount ${SRC}
# Clean up and unmount destination
pumount ${DST}
exit
}
trap clean EXIT TERM INT
# Check that a device is available on /dev/sda
if [ ! -b ${DEV_SRC} ]; then
echo "GROOMER: Source device (${DEV_SRC}) does not exist."
exit
fi
# Check that a device is available on /dev/sdb
if [ ! -b ${DEV_DST} ]; then
echo "GROOMER: Destination device (${DEV_DST}) does not exist."
exit
fi
# If there is already a device mounted on /media/dst, unmount it
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 mounts on /media/ (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
# Now that destination is mounted and prepared, run the groomer
./groomer.sh

View File

@ -1,11 +1,9 @@
#!/bin/bash #!/bin/bash
set -e
set -x set -x
# mount /dev/sdb2 /mnt/rpi
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/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/groomer.sh /mnt/rpi/opt/groomer/groomer.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/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 cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/mount_dest.sh /mnt/rpi/opt/groomer/mount_dest.sh
cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local