Rename DEV_SRC and DEV_DST to SRC_DEV, DST_DEV

* New order is more consistent with rest of script
* This patch also has a few other small bugfixes
pull/58/head
Dan Puttick 2017-10-01 21:37:10 -04:00
parent 410f5fce0e
commit d9438d03c0
3 changed files with 17 additions and 25 deletions

View File

@ -6,10 +6,10 @@ readonly USERNAME="kitten"
readonly ID=$(/usr/bin/id -u) readonly ID=$(/usr/bin/id -u)
# Paths used in multiple scripts # Paths used in multiple scripts
readonly DEV_SRC="/dev/source_key" readonly SRC_DEV="/dev/source_key"
readonly SRC_MNT="/media/src" readonly SRC_MNT="/media/src"
readonly DEV_DST="/dev/dest_key" readonly DST_DEV="/dev/dest_key"
readonly DST_MNT="/media/dst" readonly DST_MNT="/media/dst"
readonly TEMP="${DST_MNT}/temp" readonly TEMP="${DST_MNT}/temp"

View File

@ -19,10 +19,10 @@ check_not_root() {
fi fi
} }
check_partitions_not_empty () { check_has_partitions () {
local partitions=$1 local partitions=$1
if [ -z "${partitions}" ]; then if [ -z "${partitions}" ]; then
echo "GROOMER: ${DEV_SRC} does not have any partitions." echo "GROOMER: ${SRC_DEV} does not have any partitions."
exit exit
fi fi
} }
@ -37,7 +37,7 @@ unmount_source_partition() {
run_groomer() { run_groomer() {
local dev_partitions local dev_partitions
# Find the partition names on the device # Find the partition names on the device
let dev_partitions=$(ls "${DEV_SRC}"* | grep "${DEV_SRC}[1-9][0-6]*" || true) dev_partitions=$(ls "${SRC_DEV}"* | grep "${SRC_DEV}[1-9][0-6]*" || true)
check_has_partitions dev_partitions check_has_partitions dev_partitions
local partcount=1 local partcount=1
local partition local partition
@ -48,25 +48,19 @@ run_groomer() {
# Mount the current partition in write mode # Mount the current partition in write mode
${PMOUNT} -w ${partition} "${SRC_MNT}" ${PMOUNT} -w ${partition} "${SRC_MNT}"
# Mark any autorun.inf files as dangerous on the source device to be extra careful # 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 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 # Unmount and remount the current partition in read-only mode
${PUMOUNT} "${SRC_MNT}" ${PUMOUNT} "${SRC_MNT}"
if ${PMOUNT} -r "${partition}" "${SRC_MNT}"; then if ${PMOUNT} -r "${partition}" "${SRC_MNT}"; then
echo "GROOMER: ${partition} mounted at ${SRC_MNT}" 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_MNT} named PARTION_$PARTCOUNT # Create a directory on ${DST_MNT} named PARTION_$PARTCOUNT
local target_dir="${DST_MNT}/FROM_PARTITION_${partcount}" local target_dir="${DST_MNT}/FROM_PARTITION_${partcount}"
mkdir -p "${target_dir}" mkdir -p "${target_dir}"
# local logfile="${LOGS_DIR}/processing_log.txt"
# Run the current partition through filecheck.py # Run the current partition through filecheck.py
# echo "==== Starting processing of ${SRC_MNT} to ${target_dir}. ====" >> "${logfile}"
filecheck.py --source "${SRC_MNT}" --destination "${target_dir}" || true filecheck.py --source "${SRC_MNT}" --destination "${target_dir}" || true
# echo "==== Done with ${SRC_MNT} to ${target_dir}. ====" >> "${logfile}"
# List destination files (recursively) for debugging # List destination files (recursively) for debugging
if [ "${DEBUG}" = true ]; then if [ "${DEBUG}" = true ]; then

View File

@ -7,7 +7,7 @@ clean(){
cp "${DEBUG_LOG}" "${DST_MNT}/groomer_debug_log.txt" cp "${DEBUG_LOG}" "${DST_MNT}/groomer_debug_log.txt"
fi fi
echo "GROOMER: Cleaning up in mount_keys.sh." echo "GROOMER: Cleaning up in mount_keys.sh."
rm -rf "${DST_MNT}/IN_PROGRESS"* rm -rf "${DST_MNT}/IN_PROGRESS.txt"*
${SYNC} # Write anything in memory to disk ${SYNC} # Write anything in memory to disk
# Unmount source and destination # Unmount source and destination
pumount "${SRC_MNT}" pumount "${SRC_MNT}"
@ -23,15 +23,15 @@ check_not_root() {
} }
check_source_exists() { check_source_exists() {
if [ ! -b "${DEV_SRC}" ]; then if [ ! -b "${SRC_DEV}" ]; then
echo "GROOMER: Source device (${DEV_SRC}) does not exist." echo "GROOMER: Source device (${SRC_DEV}) does not exist."
exit exit
fi fi
} }
check_dest_exists() { check_dest_exists() {
if [ ! -b "${DEV_DST}" ]; then if [ ! -b "${DST_DEV}" ]; then
echo "GROOMER: Destination device (${DEV_DST}) does not exist." echo "GROOMER: Destination device (${DST_DEV}) does not exist."
exit exit
fi fi
} }
@ -43,25 +43,23 @@ unmount_dest_if_mounted() {
} }
mount_dest_partition() { mount_dest_partition() {
if "${PMOUNT}" -w "${DEV_DST}1" "${DST_MNT}"; then # pmount automatically mounts on /media/ (at /media/dst in this case). if ${PMOUNT} -w "${DST_DEV}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}" echo "GROOMER: Destination USB device (${DST_DEV}1) mounted at ${DST_MNT}"
else else
echo "GROOMER: Unable to mount ${DEV_DST}1 on ${DST_MNT}" echo "GROOMER: Unable to mount ${DST_DEV}1 on ${DST_MNT}"
exit exit
fi fi
} }
copy_in_progress_file() { copy_in_progress_file() {
cp "/opt/groomer/IN_PROGRESS" "${DST_MNT}/IN_PROGRESS" cp "/opt/groomer/IN_PROGRESS.txt" "${DST_MNT}/IN_PROGRESS.txt"
} }
prepare_dest_partition() { prepare_dest_partition() {
rm -rf "${DST_MNT}/FROM_PARTITION_"* # Remove any existing "FROM_PARTITION_" directories 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 # Prepare temp dir and make sure it's empty if it already exists:
mkdir -p "${TEMP}" mkdir -p "${TEMP}"
mkdir -p "${LOGS}"
rm -rf "${TEMP:?}/"* rm -rf "${TEMP:?}/"*
rm -rf "${LOGS:?}/"*
} }
main() { main() {
@ -81,4 +79,4 @@ main() {
./groomer.sh ./groomer.sh
} }
main main