Circlean/circlean_fs/root_partition/opt/groomer/groomer.sh

80 lines
2.5 KiB
Bash
Raw Normal View History

2015-11-06 17:40:33 +01:00
#!/bin/bash
2017-01-12 21:42:41 +01:00
# set -e (exit when a line returns non-0 status) and -x (xtrace) flags
2015-11-06 17:40:33 +01:00
set -e
set -x
# Import constants from config file
2017-01-12 21:42:41 +01:00
source ./config.sh
2015-11-06 17:40:33 +01:00
if ! [ "${ID}" -ge "1000" ]; then
echo "GROOMER: groomer.sh cannot run as root."
2015-11-06 17:40:33 +01:00
exit
fi
2017-01-31 21:44:13 +01:00
clean(){
if [ ${DEBUG} = true ]; then
sleep 20
fi
2017-01-12 20:00:51 +01:00
# Write anything in memory to disk
${SYNC}
2015-11-06 17:40:33 +01:00
# Remove temporary files from destination key
2015-11-06 17:40:33 +01:00
rm -rf ${TEMP}
rm -rf ${ZIPTEMP}
}
trap clean EXIT TERM INT
2017-01-24 04:32:20 +01:00
# Find the partition names on the device available at /dev/source_key
2017-01-12 21:42:41 +01:00
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."
exit
fi
PARTCOUNT=1
for partition in ${DEV_PARTITIONS}
do
echo "GROOMER: Processing partition ${partition}"
# Unmount anything that is mounted on /media/src
if [ `${MOUNT} | grep -c ${SRC}` -ne 0 ]; then
${PUMOUNT} ${SRC}
fi
# Mount the current partition in write mode
${PMOUNT} -w ${partition} ${SRC}
# Mark any autorun.inf files as dangerous on the source device
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}
${PMOUNT} -r ${partition} ${SRC}
if [ ${?} -ne 0 ]; then
2017-01-13 23:56:16 +01:00
# Previous command (mounting current partition) failed
echo "GROOMER: Unable to mount ${partition} on /media/${SRC}"
else
echo "GROOMER: ${partition} mounted at /media/${SRC}"
# Put the filenames from the current partition in a logfile
find "/media/${SRC}" -fls "${LOGS}/contents_partition_${PARTCOUNT}.txt"
# Create a directory on ${DST} named PARTION_$PARTCOUNT
target_dir="/media/${DST}/FROM_PARTITION_${PARTCOUNT}"
mkdir -p "${target_dir}"
2017-01-31 21:44:13 +01:00
LOGFILE="${LOGS}/processing_log.txt"
# Run the current partition through filecheck.py
2017-01-13 23:56:16 +01:00
echo "==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE}
filecheck.py --source /media/${SRC} --destination ${target_dir} || true
2017-01-13 23:56:16 +01:00
echo "==== Done with /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE}
# List destination files (recursively) for debugging
ls -lR "${target_dir}"
fi
let PARTCOUNT=`expr $PARTCOUNT + 1`
done
2015-11-06 17:40:33 +01:00
# The cleanup is automatically done in the function clean called when
# the program exits