Circlean/fs_filecheck/opt/groomer/groomer.sh

134 lines
3.6 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
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: This script cannot run as root."
2015-11-06 17:40:33 +01:00
exit
fi
clean(){
echo "GROOMER: Cleaning up after groomer.sh."
2015-11-06 17:40:33 +01:00
2017-01-12 21:42:41 +01:00
cp ${GROOM_LOG} "${DST_MNT}/groomer_log_dst.txt"
cp ${GROOM_LOG} "${SRC_MNT}/groomer_log_src.txt"
2017-01-12 20:00:51 +01:00
# Write anything in memory to disk
${SYNC}
2015-11-06 17:40:33 +01:00
2017-01-12 20:00:51 +01:00
# Unmount source
pumount ${SRC}
2017-01-11 17:34:09 +01:00
2017-01-12 20:00:51 +01:00
# Clean up and unmount destination
2015-11-06 17:40:33 +01:00
rm -rf ${TEMP}
rm -rf ${ZIPTEMP}
pumount ${DST}
exit
}
trap clean EXIT TERM INT
2017-01-12 21:42:41 +01:00
# De we have a source device?
2015-11-06 17:40:33 +01:00
if [ ! -b ${DEV_SRC} ]; then
echo "GROOMER: Source device (${DEV_SRC}) does not exist."
2017-01-12 21:42:41 +01:00
exit
2015-11-06 17:40:33 +01:00
fi
# Do we have a destination device
2017-01-12 21:42:41 +01:00
if [ ! -b ${DEV_DST} ]; then
echo "GROOMER: Destination device (${DEV_DST}) does not exist."
exit
2015-11-06 17:40:33 +01:00
fi
2017-01-12 21:42:41 +01:00
# Make sure destination device isn't already mounted
2015-11-06 17:40:33 +01:00
if ${MOUNT}|grep ${DST}; then
${PUMOUNT} ${DST} || true
fi
2017-01-12 21:42:41 +01:00
2015-11-06 17:40:33 +01:00
# uid= only works on a vfat FS. What should wedo if we get an ext* FS ?
2017-01-12 21:42:41 +01:00
# 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}
2015-11-06 17:40:33 +01:00
if [ ${?} -ne 0 ]; then
2017-01-12 21:42:41 +01:00
echo "GROOMER: Unable to mount ${DEV_DST_ONE} on ${DST_MNT}"
2015-11-06 17:40:33 +01:00
exit
else
2017-01-12 21:42:41 +01:00
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}/"*
2015-11-06 17:40:33 +01:00
fi
2017-01-12 21:42:41 +01:00
sleep 30
${PMOUNT} -w ${DEV_SRC_ONE} ${SRC}
sleep 10
2015-11-06 17:40:33 +01:00
# Groom da kitteh!
2017-01-12 21:42:41 +01:00
# List all block devices (uncomment for diagnostics)
2015-11-06 17:40:33 +01:00
# lsblk -n -o name,fstype,mountpoint,label,uuid -r
2017-01-12 21:42:41 +01:00
# Find the partition names on the source device
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
sleep 10
2017-01-11 17:34:09 +01:00
# PARTCOUNT=1
# for partition in ${DEV_PARTITIONS}
# do
# # Processing a partition
# echo "GROOMER: Processing partition ${partition}"
# if [ `${MOUNT} | grep -c ${SRC}` -ne 0 ]; then
# ${PUMOUNT} ${SRC}
# fi
# ${PMOUNT} -w ${partition} ${SRC}
# ls "/media/${SRC}" | grep -i autorun.inf | xargs -I {} mv "/media/${SRC}"/{} "/media/${SRC}"/DANGEROUS_{}_DANGEROUS || true
# ${PUMOUNT} ${SRC}
# ${PMOUNT} -r ${partition} ${SRC}
# if [ ${?} -ne 0 ]; then
# 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
# find "/media/${SRC}" -fls "${LOGS}/Content_partition_${PARTCOUNT}.txt"
# # create a directory on ${DST} named PARTION_$PARTCOUNT
# target_dir="/media/${DST}/FROM_PARTITION_${PARTCOUNT}"
# echo "GROOMER: Copying to ${target_dir}"
# mkdir -p "${target_dir}"
# LOGFILE="${LOGS}/processing.txt"
# echo "GROOMER: ==== Starting processing of /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}"
# 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 quits