Circlean/fs/opt/groomer/groomer.sh

119 lines
2.7 KiB
Bash
Raw Normal View History

2013-01-16 16:34:06 +01:00
#!/bin/bash
set -e
#set -x
2013-01-16 16:34:06 +01:00
2013-02-15 18:47:13 +01:00
source ./constraint.sh
if ! [ "${ID}" -ge "1000" ]; then
echo "This script cannot run as root."
exit
fi
source ./functions.sh
2013-01-16 16:34:06 +01:00
clean(){
echo Cleaning.
${SYNC}
2013-02-08 18:07:26 +01:00
# Cleanup source
${SUDO} ${UMOUNT} ${SRC}
rm -rf ${SRC}
2013-02-08 18:07:26 +01:00
# Cleanup destination
rm -rf ${TEMP}
rm -rf ${ZIPTEMP}
${SUDO} ${UMOUNT} ${DST}
rm -rf ${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
}
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
if [ ! -b ${DEV_SRC} ]; then
echo "Source device (${DEV_SRC}) does not exists."
exit
fi
2013-02-08 18:07:26 +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 "${DEV_SRC} does not have any partitions."
exit
fi
2013-02-08 18:07:26 +01:00
# Do we have a destination device
if [ ! -b ${DEV_DST} ]; then
echo "Destination device (${DEV_DST}) does not exists."
exit
fi
2013-02-08 18:07:26 +01:00
# Prepare mount points
if [ ! -d ${SRC} ]; then
mkdir ${SRC}
2013-01-16 16:34:06 +01:00
fi
if [ ! -d ${DST} ]; then
mkdir ${DST}
2013-01-16 16:34:06 +01:00
fi
2013-02-15 18:47:13 +01:00
# mount and prepare destination device
if ${MOUNT}|grep ${DST}; then
${SUDO} ${UMOUNT} ${DST} || true
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 ?
${SUDO} ${MOUNT_DST} ${ID} ${DEV_DST} ${DST}
if [ ${?} -ne 0 ]; then
echo "Unable to mount ${DEV_DST} on ${DST}"
2013-02-08 18:07:26 +01:00
exit
2013-01-16 16:34:06 +01:00
else
echo "Target USB device (${DEV_DST}) mounted at ${DST}"
rm -rf "${DST}/FROM_PARTITION_"*
2013-01-16 16:34:06 +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
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!
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
echo "Processing partition: ${partition}"
if ${MOUNT}|grep ${SRC}; then
${SUDO} ${UMOUNT} ${SRC}
fi
${SUDO} ${MOUNT_SRC} ${partition} ${SRC}
if [ ${?} -ne 0 ]; then
echo "Unable to mount ${partition} on ${SRC}"
2013-01-16 16:34:06 +01:00
else
echo "${partition} mounted at ${SRC}"
2013-02-08 18:07:26 +01:00
# Print the filenames on the current partition in a logfile
find "${SRC}" -fls "${LOGS}/Content_partition_${PARTCOUNT}.txt"
# create a directory on ${DST} named PARTION_$PARTCOUNT
target_dir="${DST}/FROM_PARTITION_${PARTCOUNT}"
echo "copying to: ${target_dir}"
mkdir -p "${target_dir}"
LOGFILE="${LOGS}/processing.txt"
2013-06-09 19:37:41 +02:00
echo "==== Starting processing of ${SRC} to ${target_dir}. ====" >> ${LOGFILE}
main ${target_dir} || true
2013-06-09 19:37:41 +02:00
echo "==== Done with ${SRC} to ${target_dir}. ====" >> ${LOGFILE}
ls -lR "${target_dir}"
2013-01-16 16:34:06 +01:00
fi
let PARTCOUNT=`expr $PARTCOUNT + 1`
2013-01-16 16:34:06 +01:00
done
# The cleanup is automatically done in the function clean called when
2013-02-08 18:07:26 +01:00
# the program quits