Fix issue with $SRC+$DST and $SRC_MNT+$DST_MNT

pull/58/head
Dan Puttick 2017-08-23 17:05:24 -04:00
parent 650ad783d7
commit ab9c9eb309
3 changed files with 22 additions and 24 deletions

View File

@ -6,11 +6,9 @@ readonly USERNAME="kitten"
readonly ID=$(/usr/bin/id -u)
# Paths used in multiple scripts
readonly SRC="src"
readonly DEV_SRC="/dev/source_key"
readonly SRC_MNT="/media/src"
readonly DST="dst"
readonly DEV_DST="/dev/dest_key"
readonly DST_MNT="/media/dst"

View File

@ -29,8 +29,8 @@ check_partitions_not_empty () {
unmount_source_partition() {
# Unmount anything that is mounted on /media/src
if [ "$(${MOUNT} | grep -c "${SRC}")" -ne 0 ]; then
${PUMOUNT} "${SRC}"
if [ "$(${MOUNT} | grep -c "${SRC_MNT}")" -ne 0 ]; then
${PUMOUNT} "${SRC_MNT}"
fi
}
@ -46,27 +46,27 @@ run_groomer() {
echo "GROOMER: Processing partition ${partition}"
unmount_source_partition
# Mount the current partition in write mode
${PMOUNT} -w ${partition} "${SRC}"
${PMOUNT} -w ${partition} "${SRC_MNT}"
# Mark any autorun.inf files as dangerous on the source device to be extra careful
ls "${SRC_MNT}" | grep -i autorun.inf | xargs -I {} mv "${SRC_MNT}"/{} "{SRC_MNT}"/DANGEROUS_{}_DANGEROUS || true
# Unmount and remount the current partition in read-only mode
${PUMOUNT} "${SRC}"
${PUMOUNT} "${SRC_MNT}"
if ${PMOUNT} -r "${partition}" "${SRC}"; then
echo "GROOMER: ${partition} mounted at /media/${SRC}"
if ${PMOUNT} -r "${partition}" "${SRC_MNT}"; then
echo "GROOMER: ${partition} mounted at ${SRC_MNT}"
# Put the filenames from the current partition in a logfile
# find "/media/${SRC}" -fls "${LOGS_DIR}/contents_partition_${partcount}.txt"
# Create a directory on ${DST} named PARTION_$PARTCOUNT
local target_dir="/media/${DST}/FROM_PARTITION_${partcount}"
# Create a directory on ${DST_MNT} named PARTION_$PARTCOUNT
local target_dir="${DST_MNT}/FROM_PARTITION_${partcount}"
mkdir -p "${target_dir}"
# local logfile="${LOGS_DIR}/processing_log.txt"
# Run the current partition through filecheck.py
# echo "==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> "${logfile}"
filecheck.py --source /media/"${SRC}" --destination "${target_dir}" || true
# echo "==== Done with /media/${SRC} to ${target_dir}. ====" >> "${logfile}"
# echo "==== Starting processing of ${SRC_MNT} to ${target_dir}. ====" >> "${logfile}"
filecheck.py --source "${SRC_MNT}" --destination "${target_dir}" || true
# echo "==== Done with ${SRC_MNT} to ${target_dir}. ====" >> "${logfile}"
# List destination files (recursively) for debugging
if [ "${DEBUG}" = true ]; then
@ -74,7 +74,7 @@ run_groomer() {
fi
else
# Previous command (mounting current partition) failed
echo "GROOMER: Unable to mount ${partition} on /media/${SRC}"
echo "GROOMER: Unable to mount ${partition} on ${SRC_MNT}"
fi
let partcount=$((partcount + 1))
done

View File

@ -7,11 +7,11 @@ clean(){
cp "${DEBUG_LOG}" "${DST_MNT}/groomer_debug_log.txt"
fi
echo "GROOMER: Cleaning up in mount_keys.sh."
rm -rf "/media/${DST}/IN_PROGRESS"*
rm -rf "${DST_MNT}/IN_PROGRESS"*
${SYNC} # Write anything in memory to disk
# Unmount source and destination
pumount "${SRC}"
pumount "${DST}"
pumount "${SRC_MNT}"
pumount "${DST_MNT}"
exit
}
@ -37,13 +37,13 @@ check_dest_exists() {
}
unmount_dest_if_mounted() {
if ${MOUNT}|grep "${DST}"; then
${PUMOUNT} "${DST}" || true
if ${MOUNT}|grep "${DST_MNT}"; then
${PUMOUNT} "${DST_MNT}" || true
fi
}
mount_dest_partition() {
if "${PMOUNT}" -w "${DEV_DST}1" "${DST}"; then # pmount automatically mounts on /media/ (at /media/dst in this case).
if "${PMOUNT}" -w "${DEV_DST}1" "${DST_MNT}"; then # pmount automatically mounts on /media/ (at /media/dst in this case).
echo "GROOMER: Destination USB device (${DEV_DST}1) mounted at ${DST_MNT}"
else
echo "GROOMER: Unable to mount ${DEV_DST}1 on ${DST_MNT}"
@ -52,11 +52,11 @@ mount_dest_partition() {
}
copy_in_progress_file() {
cp "/opt/groomer/IN_PROGRESS" "/media/${DST}/IN_PROGRESS"
cp "/opt/groomer/IN_PROGRESS" "${DST_MNT}/IN_PROGRESS"
}
prepare_dest_key() {
rm -rf "/media/${DST}/FROM_PARTITION_"* # Remove any existing "FROM_PARTITION_" directories
prepare_dest_partition() {
rm -rf "${DST_MNT}/FROM_PARTITION_"* # Remove any existing "FROM_PARTITION_" directories
# Prepare temp dirs and make sure they're empty if they already exist
mkdir -p "${TEMP}"
mkdir -p "${LOGS}"
@ -75,7 +75,7 @@ main() {
check_source_exists
check_dest_exists
unmount_dest_if_mounted
mount_dest_key
mount_dest_partition
copy_in_progress_file
prepare_dest_partition
./groomer.sh