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

94 lines
3.0 KiB
Bash
Raw Normal View History

2015-11-06 17:40:33 +01:00
#!/bin/bash
2017-01-31 21:44:13 +01:00
clean(){
2017-08-10 17:51:05 +02:00
if [ "${DEBUG}" = true ]; then
2017-01-31 21:44:13 +01:00
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
2017-08-10 17:51:05 +02:00
rm -rf "${TEMP}"
2015-11-06 17:40:33 +01:00
}
2017-08-10 17:51:05 +02:00
check_not_root() {
if ! [ "${ID}" -ge "1000" ]; then
echo "GROOMER: groomer.sh cannot run as root."
exit
fi
}
2015-11-06 17:40:33 +01:00
2017-08-10 17:51:05 +02:00
check_partitions_not_empty () {
local partitions=$1
if [ -z "${partitions}" ]; then
echo "GROOMER: ${DEV_SRC} does not have any partitions."
exit
fi
}
2017-01-12 21:42:41 +01:00
2017-08-10 17:51:05 +02:00
unmount_source_partition() {
# Unmount anything that is mounted on /media/src
2017-08-10 17:51:05 +02:00
if [ "$(${MOUNT} | grep -c "${SRC}")" -ne 0 ]; then
${PUMOUNT} "${SRC}"
fi
2017-08-10 17:51:05 +02:00
}
run_groomer() {
local dev_partitions
# Find the partition names on the device
let dev_partitions=$(ls "${DEV_SRC}"* | grep "${DEV_SRC}[1-9][0-6]*" || true)
check_has_partitions dev_partitions
local partcount=1
local partition
for partition in ${dev_partitions}
do
echo "GROOMER: Processing partition ${partition}"
unmount_source_partition
# Mount the current partition in write mode
${PMOUNT} -w ${partition} "${SRC}"
# 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}"
if ${PMOUNT} -r "${partition}" "${SRC}"; then
echo "GROOMER: ${partition} mounted at /media/${SRC}"
2017-08-10 17:51:05 +02:00
# Put the filenames from the current partition in a logfile
# find "/media/${SRC}" -fls "${LOGS_DIR}/contents_partition_${partcount}.txt"
2017-08-10 17:51:05 +02:00
# Create a directory on ${DST} named PARTION_$PARTCOUNT
local target_dir="/media/${DST}/FROM_PARTITION_${partcount}"
mkdir -p "${target_dir}"
# local logfile="${LOGS_DIR}/processing_log.txt"
2017-08-10 17:51:05 +02:00
# Run the current partition through filecheck.py
# echo "==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> "${logfile}"
2017-08-10 17:51:05 +02:00
filecheck.py --source /media/"${SRC}" --destination "${target_dir}" || true
# echo "==== Done with /media/${SRC} to ${target_dir}. ====" >> "${logfile}"
2017-08-10 17:51:05 +02:00
# List destination files (recursively) for debugging
2017-08-10 23:44:11 +02:00
if [ "${DEBUG}" = true ]; then
ls -lR "${target_dir}"
fi
2017-08-10 17:51:05 +02:00
else
# Previous command (mounting current partition) failed
echo "GROOMER: Unable to mount ${partition} on /media/${SRC}"
fi
let partcount=$((partcount + 1))
done
}
2017-08-10 17:51:05 +02:00
main() {
set -eu # exit when a line returns non-0 status, treat unset variables as errors
trap clean EXIT TERM INT # run clean when the script ends or is interrupted
source ./config.sh # get config values
if [ "${DEBUG}" = true ]; then
set -x
fi
2017-08-10 17:51:05 +02:00
run_groomer
}
2015-11-06 17:40:33 +01:00
2017-08-10 17:51:05 +02:00
main