2013-01-16 16:34:06 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2013-02-08 15:38:13 +01:00
|
|
|
set -e
|
2014-03-26 16:40:19 +01:00
|
|
|
set -x
|
2013-01-16 16:34:06 +01:00
|
|
|
|
2015-10-09 21:18:33 +02:00
|
|
|
# To make debugging easier
|
|
|
|
echo "KittenGroomer: in groomer.sh" 1>&2
|
|
|
|
|
2013-02-15 18:47:13 +01:00
|
|
|
source ./constraint.sh
|
2013-02-17 02:16:55 +01:00
|
|
|
if ! [ "${ID}" -ge "1000" ]; then
|
|
|
|
echo "This script cannot run as root."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2013-02-22 17:35:23 +01:00
|
|
|
source ./functions.sh
|
2013-01-16 16:34:06 +01:00
|
|
|
|
2013-02-08 15:38:13 +01:00
|
|
|
clean(){
|
|
|
|
echo Cleaning.
|
2013-02-17 02:16:55 +01:00
|
|
|
${SYNC}
|
2013-02-08 18:07:26 +01:00
|
|
|
|
|
|
|
# Cleanup source
|
2014-07-30 21:49:00 +02:00
|
|
|
pumount ${SRC}
|
2013-02-08 18:07:26 +01:00
|
|
|
|
|
|
|
# Cleanup destination
|
|
|
|
rm -rf ${TEMP}
|
|
|
|
rm -rf ${ZIPTEMP}
|
2014-07-30 21:49:00 +02:00
|
|
|
pumount ${DST}
|
2013-02-08 18:07:26 +01:00
|
|
|
|
2013-02-15 18:47:13 +01:00
|
|
|
exit
|
2013-01-16 16:34:06 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 15:38:13 +01:00
|
|
|
trap clean EXIT TERM INT
|
2013-01-16 16:34:06 +01:00
|
|
|
|
2013-02-08 18:07:26 +01:00
|
|
|
# De we have a source device
|
2013-02-08 15:38:13 +01:00
|
|
|
if [ ! -b ${DEV_SRC} ]; then
|
2013-02-17 02:16:55 +01:00
|
|
|
echo "Source device (${DEV_SRC}) does not exists."
|
2013-02-08 15:38:13 +01:00
|
|
|
exit
|
|
|
|
fi
|
2013-02-08 18:07:26 +01:00
|
|
|
# Find the partition names on the source device
|
2013-02-17 02:16:55 +01:00
|
|
|
DEV_PARTITIONS=`ls "${DEV_SRC}"* | grep "${DEV_SRC}[1-9][0-6]*" || true`
|
2014-03-26 16:40:19 +01:00
|
|
|
if [ -z "${DEV_PARTITIONS}" ]; then
|
2013-02-17 02:16:55 +01:00
|
|
|
echo "${DEV_SRC} does not have any partitions."
|
2013-02-08 15:38:13 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2013-02-08 18:07:26 +01:00
|
|
|
# Do we have a destination device
|
2014-07-30 21:49:00 +02:00
|
|
|
if [ ! -b "/dev/${DEV_DST}" ]; then
|
|
|
|
echo "Destination device (/dev/${DEV_DST}) does not exists."
|
2013-02-08 15:38:13 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2013-02-15 18:47:13 +01:00
|
|
|
# mount and prepare destination device
|
2013-02-17 02:16:55 +01:00
|
|
|
if ${MOUNT}|grep ${DST}; then
|
2014-07-30 21:49:00 +02:00
|
|
|
${PUMOUNT} ${DST} || true
|
2013-02-08 15:38:13 +01:00
|
|
|
fi
|
2013-02-15 18:47:13 +01:00
|
|
|
# uid= only works on a vfat FS. What should wedo if we get an ext* FS ?
|
2014-07-30 21:49:00 +02:00
|
|
|
${PMOUNT} -w ${DEV_DST} ${DST}
|
2013-02-17 02:16:55 +01:00
|
|
|
if [ ${?} -ne 0 ]; then
|
2014-07-30 21:49:00 +02:00
|
|
|
echo "Unable to mount /dev/${DEV_DST} on /media/${DST}"
|
2013-02-08 18:07:26 +01:00
|
|
|
exit
|
2013-01-16 16:34:06 +01:00
|
|
|
else
|
2014-07-30 21:49:00 +02:00
|
|
|
echo "Target USB device (/dev/${DEV_DST}) mounted at /media/${DST}"
|
|
|
|
rm -rf "/media/${DST}/FROM_PARTITION_"*
|
2013-01-16 16:34:06 +01:00
|
|
|
|
2013-02-17 02:16:55 +01:00
|
|
|
# prepare temp dirs and make sure it's empty
|
|
|
|
mkdir -p "${TEMP}"
|
|
|
|
mkdir -p "${ZIPTEMP}"
|
|
|
|
mkdir -p "${LOGS}"
|
2013-01-16 16:34:06 +01:00
|
|
|
|
2013-02-17 02:16:55 +01:00
|
|
|
rm -rf "${TEMP}/"*
|
|
|
|
rm -rf "${ZIPTEMP}/"*
|
|
|
|
rm -rf "${LOGS}/"*
|
2013-01-16 16:34:06 +01:00
|
|
|
fi
|
|
|
|
|
2013-02-08 18:07:26 +01:00
|
|
|
# Groom da kitteh!
|
|
|
|
|
2015-04-02 17:40:39 +02:00
|
|
|
# Find the FS types
|
|
|
|
# lsblk -n -o name,fstype,mountpoint,label,uuid -r
|
|
|
|
|
2013-01-16 16:34:06 +01:00
|
|
|
PARTCOUNT=1
|
2013-02-08 18:07:26 +01:00
|
|
|
for partition in ${DEV_PARTITIONS}
|
2013-01-16 16:34:06 +01:00
|
|
|
do
|
2013-02-08 18:07:26 +01:00
|
|
|
# Processing a partition
|
2013-02-17 02:16:55 +01:00
|
|
|
echo "Processing partition: ${partition}"
|
2014-03-26 16:40:19 +01:00
|
|
|
if [ `${MOUNT} | grep -c ${SRC}` -ne 0 ]; then
|
2014-07-30 21:49:00 +02:00
|
|
|
${PUMOUNT} ${SRC}
|
2013-02-08 15:38:13 +01:00
|
|
|
fi
|
|
|
|
|
2014-07-30 21:49:00 +02:00
|
|
|
${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}
|
2013-02-17 02:16:55 +01:00
|
|
|
if [ ${?} -ne 0 ]; then
|
2014-07-30 21:49:00 +02:00
|
|
|
echo "Unable to mount ${partition} on /media/${SRC}"
|
2013-01-16 16:34:06 +01:00
|
|
|
else
|
2014-07-30 21:49:00 +02:00
|
|
|
echo "${partition} mounted at /media/${SRC}"
|
2013-02-08 15:38:13 +01:00
|
|
|
|
2013-02-08 18:07:26 +01:00
|
|
|
# Print the filenames on the current partition in a logfile
|
2014-07-30 21:49:00 +02:00
|
|
|
find "/media/${SRC}" -fls "${LOGS}/Content_partition_${PARTCOUNT}.txt"
|
2013-02-08 15:38:13 +01:00
|
|
|
|
2013-02-17 02:16:55 +01:00
|
|
|
# create a directory on ${DST} named PARTION_$PARTCOUNT
|
2014-07-30 21:49:00 +02:00
|
|
|
target_dir="/media/${DST}/FROM_PARTITION_${PARTCOUNT}"
|
2013-02-17 02:16:55 +01:00
|
|
|
echo "copying to: ${target_dir}"
|
|
|
|
mkdir -p "${target_dir}"
|
2013-08-04 18:30:59 +02:00
|
|
|
LOGFILE="${LOGS}/processing.txt"
|
2013-02-08 15:38:13 +01:00
|
|
|
|
2015-10-09 21:18:33 +02:00
|
|
|
echo "==== Starting processing of /media/${SRC} to ${target_dir}. ====" 1>&2
|
2014-07-30 21:49:00 +02:00
|
|
|
echo "==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE}
|
2015-05-26 19:06:02 +02:00
|
|
|
generic.py --source /media/${SRC} --destination ${target_dir} || true
|
2015-10-09 21:18:33 +02:00
|
|
|
echo "==== Done with /media/${SRC} to ${target_dir}. ====" 1>&2
|
2014-07-30 21:49:00 +02:00
|
|
|
echo "==== Done with /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE}
|
2013-02-22 17:35:23 +01:00
|
|
|
|
2013-02-25 01:27:15 +01:00
|
|
|
ls -lR "${target_dir}"
|
2013-01-16 16:34:06 +01:00
|
|
|
fi
|
2013-03-30 19:38:11 +01:00
|
|
|
let PARTCOUNT=`expr $PARTCOUNT + 1`
|
2013-01-16 16:34:06 +01:00
|
|
|
done
|
|
|
|
|
2015-10-09 21:18:33 +02:00
|
|
|
# To make debugging easier
|
|
|
|
echo "KittenGroomer: done with groomer.sh" 1>&2
|
|
|
|
|
2013-02-17 02:16:55 +01:00
|
|
|
# The cleanup is automatically done in the function clean called when
|
2013-02-08 18:07:26 +01:00
|
|
|
# the program quits
|