Circlean/filesystem/opt/groomer/groomer.sh

134 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
#Constraints
DEV_SRC='/dev/sdf'
DEV_DST='/dev/sdg1'
HOME=testing
2013-02-08 18:07:26 +01:00
############
SRC=${HOME}/src
DST=${HOME}/dst
TEMP=${DST}/temp
ZIPTEMP=${DST}/ziptemp
LOGS=${DST}/logs
2013-01-16 16:34:06 +01:00
clean(){
echo Cleaning.
2013-02-08 18:07:26 +01:00
sync
# Cleanup source
umount $SRC
rm -rf $SRC
# Cleanup destination
rm -rf ${TEMP}
rm -rf ${ZIPTEMP}
umount $DST
rm -rf $DST
# Only if running on a rPi
#/sbin/shutdown -h now
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
2013-01-16 16:34:06 +01:00
if [ ! -d $SRC ]; then
mkdir $SRC
fi
if [ ! -d $DST ]; then
mkdir $DST
fi
2013-02-08 18:07:26 +01:00
# Mount and prepare destination device
if mount|grep $DST; then
umount $DST || true
fi
2013-02-08 18:07:26 +01:00
mount -o noexec ${DEV_DST} ${DST}
2013-01-16 16:34:06 +01:00
if [ $? -ne 0 ]; then
2013-02-08 18:07:26 +01:00
echo Unable to mount ${DEV_DST} on ${DST}
exit
2013-01-16 16:34:06 +01:00
else
2013-02-08 18:07:26 +01:00
echo 'Target USB device ('${DEV_DST}') mounted at '${DST}
rm -rf ${DST}/FROM_PARTITION_*
2013-01-16 16:34:06 +01:00
# mount temp and make sure it's empty
2013-02-08 18:07:26 +01:00
mkdir -p ${TEMP}
mkdir -p ${ZIPTEMP}
mkdir -p ${LOGS}
2013-01-16 16:34:06 +01:00
rm -rf ${TEMP}/*
rm -rf ${ZIPTEMP}/*
2013-02-08 18:07:26 +01:00
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
COPYDIRTYPDF=0
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
2013-02-08 18:07:26 +01:00
umount $SRC
fi
2013-02-08 18:07:26 +01:00
mount -o noexec -r $partition $SRC
2013-01-16 16:34:06 +01:00
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}/${PARTCOUNT}
2013-02-08 18:07:26 +01:00
# create a directory on $DST named PARTION_$PARTCOUNT
targetDir=${DST}/FROM_PARTITION_${PARTCOUNT}
2013-02-08 18:07:26 +01:00
echo copying to: $target_dir
mkdir -p $target_dir
#if [ $COPYDIRTYPDF -eq 1 ]; then
# pdfCopyDirty $SRC $targetDir
#else
# pdfCopyClean $SRC $targetDir
#fi
# copy stuff
#copySafeFiles $SRC $targetDir
#convertCopyFiles $SRC $targetDir $TEMP
#rm -rf ${TEMP}/*
# unpack and process archives
#unpackZip $SRC $targetDir $TEMP
2013-01-16 16:34:06 +01:00
fi
let PARTCOUNT=$PARTCOUNT+1
done
2013-02-08 18:07:26 +01:00
# The cleanup is automatically done in the finction clean called when
# the program quits