mirror of https://github.com/CIRCL/Circlean
Hardening the init script further.
parent
880e1f3a28
commit
81b29d7851
|
@ -7,36 +7,56 @@ set -x
|
||||||
DEV_SRC='/dev/sdf'
|
DEV_SRC='/dev/sdf'
|
||||||
DEV_DST='/dev/sdg1'
|
DEV_DST='/dev/sdg1'
|
||||||
HOME=testing
|
HOME=testing
|
||||||
|
############
|
||||||
|
|
||||||
|
|
||||||
|
SRC=${HOME}/src
|
||||||
|
DST=${HOME}/dst
|
||||||
|
|
||||||
|
TEMP=${DST}/temp
|
||||||
|
ZIPTEMP=${DST}/ziptemp
|
||||||
|
LOGS=${DST}/logs
|
||||||
|
|
||||||
|
|
||||||
clean(){
|
clean(){
|
||||||
echo Cleaning.
|
echo Cleaning.
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
trap clean EXIT TERM INT
|
trap clean EXIT TERM INT
|
||||||
|
|
||||||
# groom da kitteh!
|
# De we have a source device
|
||||||
|
|
||||||
if [ ! -b ${DEV_SRC} ]; then
|
if [ ! -b ${DEV_SRC} ]; then
|
||||||
echo 'Source device ('${DEV_SRC}') does not exists.'
|
echo 'Source device ('${DEV_SRC}') does not exists.'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
# Find the partition names on the source device
|
||||||
DEV_PARTITIONS=`ls ${DEV_SRC}* | grep ${DEV_SRC}'[1-9][0-6]*' || true`
|
DEV_PARTITIONS=`ls ${DEV_SRC}* | grep ${DEV_SRC}'[1-9][0-6]*' || true`
|
||||||
if [ -z ${DEV_PARTITIONS} ]; then
|
if [ -z ${DEV_PARTITIONS} ]; then
|
||||||
echo ${DEV_SRC} 'does not have any partitions.'
|
echo ${DEV_SRC} 'does not have any partitions.'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Do we have a destination device
|
||||||
if [ ! -b ${DEV_DST} ]; then
|
if [ ! -b ${DEV_DST} ]; then
|
||||||
echo 'Destination device ('${DEV_DST}') does not exists.'
|
echo 'Destination device ('${DEV_DST}') does not exists.'
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Prepare mount points
|
||||||
SRC=${HOME}/src
|
|
||||||
DST=${HOME}/dst
|
|
||||||
|
|
||||||
if [ ! -d $SRC ]; then
|
if [ ! -d $SRC ]; then
|
||||||
mkdir $SRC
|
mkdir $SRC
|
||||||
fi
|
fi
|
||||||
|
@ -44,57 +64,53 @@ if [ ! -d $DST ]; then
|
||||||
mkdir $DST
|
mkdir $DST
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Mount and prepare destination device
|
||||||
if mount|grep $DST; then
|
if mount|grep $DST; then
|
||||||
umount $DST || true
|
umount $DST || true
|
||||||
fi
|
fi
|
||||||
|
mount -o noexec ${DEV_DST} ${DST}
|
||||||
TEMP=${DST}/temp
|
|
||||||
ZIPTEMP=${DST}/ziptemp
|
|
||||||
FL=${DST}/filelist.txt
|
|
||||||
|
|
||||||
mount ${DEV_DST} $DST
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo Unable to mount ${DEV_DST} on $DST
|
echo Unable to mount ${DEV_DST} on ${DST}
|
||||||
exit 1
|
exit
|
||||||
else
|
else
|
||||||
echo 'Target USB device ('${DEV_DST}') mounted at $DST'
|
echo 'Target USB device ('${DEV_DST}') mounted at '${DST}
|
||||||
rm -rf $DST/FROM_PARTITION_*
|
rm -rf ${DST}/FROM_PARTITION_*
|
||||||
|
|
||||||
# mount temp and make sure it's empty
|
# mount temp and make sure it's empty
|
||||||
mkdir -p $TEMP
|
mkdir -p ${TEMP}
|
||||||
mkdir -p $ZIPTEMP
|
mkdir -p ${ZIPTEMP}
|
||||||
|
mkdir -p ${LOGS}
|
||||||
|
|
||||||
rm -rf ${TEMP}/*
|
rm -rf ${TEMP}/*
|
||||||
rm -rf ${ZIPTEMP}/*
|
rm -rf ${ZIPTEMP}/*
|
||||||
|
rm -rf ${LOGS}/*
|
||||||
echo Full file list from source USB > $FL
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Groom da kitteh!
|
||||||
|
|
||||||
COPYDIRTYPDF=0
|
COPYDIRTYPDF=0
|
||||||
PARTCOUNT=1
|
PARTCOUNT=1
|
||||||
for partition in $DEV_PARTITIONS
|
for partition in ${DEV_PARTITIONS}
|
||||||
do
|
do
|
||||||
|
# Processing a partition
|
||||||
echo Processing partition: ${partition}
|
echo Processing partition: ${partition}
|
||||||
if mount|grep $SRC; then
|
if mount|grep $SRC; then
|
||||||
umount $SRC 2> /dev/null
|
umount $SRC
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount -r $partition $SRC
|
mount -o noexec -r $partition $SRC
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo Unable to mount ${partition} on $SRC
|
echo Unable to mount ${partition} on $SRC
|
||||||
else
|
else
|
||||||
echo $partition mounted at $SRC
|
echo $partition mounted at $SRC
|
||||||
|
|
||||||
echo PARTITION $PARTCOUNT >> $FL
|
# Print the filenames on the current partition in a logfile
|
||||||
# FIXME: eval probably insecure
|
find ${SRC}/* -fls ${LOGS}/${PARTCOUNT}
|
||||||
find ${SRC}/* -printf 'echo "%p" | sed s:'${SRC}':: >> '${FL}' \n' | \
|
|
||||||
while read l; do eval $l; done
|
|
||||||
|
|
||||||
# create a director on sdb named PARTION_n
|
# create a directory on $DST named PARTION_$PARTCOUNT
|
||||||
targetDir=${DST}/FROM_PARTITION_${PARTCOUNT}
|
targetDir=${DST}/FROM_PARTITION_${PARTCOUNT}
|
||||||
echo copying to: $targetDir
|
echo copying to: $target_dir
|
||||||
mkdir -p $targetDir
|
mkdir -p $target_dir
|
||||||
|
|
||||||
#if [ $COPYDIRTYPDF -eq 1 ]; then
|
#if [ $COPYDIRTYPDF -eq 1 ]; then
|
||||||
# pdfCopyDirty $SRC $targetDir
|
# pdfCopyDirty $SRC $targetDir
|
||||||
|
@ -113,12 +129,5 @@ do
|
||||||
let PARTCOUNT=$PARTCOUNT+1
|
let PARTCOUNT=$PARTCOUNT+1
|
||||||
done
|
done
|
||||||
|
|
||||||
#cleanup
|
# The cleanup is automatically done in the finction clean called when
|
||||||
rm -rf ${TEMP}*
|
# the program quits
|
||||||
rm -rf ${ZIPTEMP}*
|
|
||||||
sync
|
|
||||||
umount $SRC
|
|
||||||
umount $DST
|
|
||||||
|
|
||||||
#/sbin/shutdown -h now
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue