From d5e73354c210c305a3861d9f01c8300832e5a32a Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Fri, 6 Jan 2017 14:11:07 -0500 Subject: [PATCH 01/14] Created simple_mount_image.sh --- shell_utils/simple_mount_image.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 shell_utils/simple_mount_image.sh diff --git a/shell_utils/simple_mount_image.sh b/shell_utils/simple_mount_image.sh new file mode 100644 index 0000000..6c6bf3b --- /dev/null +++ b/shell_utils/simple_mount_image.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +IMAGE='2016-05-12_CIRCLean.img' +OFFSET=$((512 * 131072)) + +mkdir /mnt/rpi +mount -v -o offset=${OFFSET} -t ext4 ${IMAGE} /mnt/rpi From fca8ac922c586bdc906f1d8bc64545436acbf18f Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Tue, 10 Jan 2017 22:03:33 -0500 Subject: [PATCH 02/14] Clean up echo statements and add echo statements --- fs_filecheck/etc/rc.local | 6 +++++- fs_filecheck/opt/groomer/constraint.sh | 2 +- fs_filecheck/opt/groomer/groomer.sh | 30 +++++++++++++++----------- fs_filecheck/opt/groomer/init.sh | 8 +++---- shell_utils/copy_groomer_to_image.sh | 13 +++++++++++ 5 files changed, 40 insertions(+), 19 deletions(-) create mode 100755 shell_utils/copy_groomer_to_image.sh diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index cb0d793..1ff88b8 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -15,10 +15,12 @@ # been modified to start the grooming process on boot. clean(){ - echo 'Rc Local done, quit.' + echo "GROOMER: rc.local done, shutting down." /sbin/shutdown -P -h now } +echo "GROOMER: end of boot, running rc.local." + # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then @@ -36,4 +38,6 @@ if [ -e /dev/sda ]; then fi fi +sleep 60 + exit 0 diff --git a/fs_filecheck/opt/groomer/constraint.sh b/fs_filecheck/opt/groomer/constraint.sh index fcf899e..da7a4fe 100644 --- a/fs_filecheck/opt/groomer/constraint.sh +++ b/fs_filecheck/opt/groomer/constraint.sh @@ -13,7 +13,7 @@ DST="dst" TEMP="/media/${DST}/temp" ZIPTEMP="/media/${DST}/ziptemp" LOGS="/media/${DST}/logs" - +GROOM_LOG="/var/tmp/groomer_log.txt" # commands SYNC='/bin/sync' diff --git a/fs_filecheck/opt/groomer/groomer.sh b/fs_filecheck/opt/groomer/groomer.sh index d085aad..958305c 100755 --- a/fs_filecheck/opt/groomer/groomer.sh +++ b/fs_filecheck/opt/groomer/groomer.sh @@ -5,18 +5,20 @@ set -x source ./constraint.sh if ! [ "${ID}" -ge "1000" ]; then - echo "This script cannot run as root." + echo "GROOMER: This script cannot run as root." exit fi clean(){ - echo Cleaning. + echo "GROOMER: Cleaning up after groomer.sh." ${SYNC} # Cleanup source + cp ${GROOM_LOG} ${SRC}/groomer_log.txt pumount ${SRC} # Cleanup destination + cp ${GROOM_LOG} ${LOGS}/groomer_log.txt rm -rf ${TEMP} rm -rf ${ZIPTEMP} pumount ${DST} @@ -28,19 +30,19 @@ trap clean EXIT TERM INT # De we have a source device if [ ! -b ${DEV_SRC} ]; then - echo "Source device (${DEV_SRC}) does not exists." + echo "GROOMER: Source device (${DEV_SRC}) does not exist." exit fi # 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." + echo "GROOMER: ${DEV_SRC} does not have any partitions." exit fi # Do we have a destination device if [ ! -b "/dev/${DEV_DST}" ]; then - echo "Destination device (/dev/${DEV_DST}) does not exists." + echo "GROOMER: Destination device (/dev/${DEV_DST}) does not exist." exit fi @@ -51,10 +53,10 @@ fi # uid= only works on a vfat FS. What should wedo if we get an ext* FS ? ${PMOUNT} -w ${DEV_DST} ${DST} if [ ${?} -ne 0 ]; then - echo "Unable to mount /dev/${DEV_DST} on /media/${DST}" + echo "GROOMER: Unable to mount /dev/${DEV_DST} on /media/${DST}" exit else - echo "Target USB device (/dev/${DEV_DST}) mounted at /media/${DST}" + echo "GROOMER: Target USB device (/dev/${DEV_DST}) mounted at /media/${DST}" rm -rf "/media/${DST}/FROM_PARTITION_"* # prepare temp dirs and make sure it's empty @@ -67,6 +69,8 @@ else rm -rf "${LOGS}/"* fi +sleep 30 + # Groom da kitteh! # Find the FS types @@ -76,7 +80,7 @@ PARTCOUNT=1 for partition in ${DEV_PARTITIONS} do # Processing a partition - echo "Processing partition: ${partition}" + echo "GROOMER: Processing partition ${partition}" if [ `${MOUNT} | grep -c ${SRC}` -ne 0 ]; then ${PUMOUNT} ${SRC} fi @@ -86,22 +90,22 @@ do ${PUMOUNT} ${SRC} ${PMOUNT} -r ${partition} ${SRC} if [ ${?} -ne 0 ]; then - echo "Unable to mount ${partition} on /media/${SRC}" + echo "GROOMER: Unable to mount ${partition} on /media/${SRC}" else - echo "${partition} mounted at /media/${SRC}" + 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 "copying to: ${target_dir}" + echo "GROOMER: Copying to ${target_dir}" mkdir -p "${target_dir}" LOGFILE="${LOGS}/processing.txt" - echo "==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE} + echo "GROOMER: ==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE} filecheck.py --source /media/${SRC} --destination ${target_dir} || true - echo "==== Done with /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE} + echo "GROOMER: ==== Done with /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE} ls -lR "${target_dir}" fi diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index 0deb56d..30351b1 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -6,12 +6,12 @@ set -x source ./constraint.sh if [ ${ID} -ne 0 ]; then - echo "This script has to be run as root." + echo "GROOMER: This script has to be run as root." exit fi clean(){ - echo Done, cleaning. + echo "GROOMER: cleaning up after init.sh." ${SYNC} kill -9 $(cat /tmp/music.pid) rm -f /tmp/music.pid @@ -21,6 +21,6 @@ trap clean EXIT TERM INT ./music.sh & echo $! > /tmp/music.pid +echo "GROOMER: music started." -su ${USERNAME} -c ./groomer.sh - +su ${USERNAME} -c ./groomer.sh | tee ${GROOM_LOG} diff --git a/shell_utils/copy_groomer_to_image.sh b/shell_utils/copy_groomer_to_image.sh new file mode 100755 index 0000000..bb06370 --- /dev/null +++ b/shell_utils/copy_groomer_to_image.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e +set -x + +mount /dev/sdb2 /mnt/rpi + +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt/rpi/opt/groomer/init.sh +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/constraint.sh /mnt/rpi/opt/groomer/constraint.sh +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local + +umount /mnt/rpi From 733b5fd63748496f7c0fd33da4bccc51ccce074b Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Wed, 11 Jan 2017 11:34:09 -0500 Subject: [PATCH 03/14] Simplify scripts for testing --- fs_filecheck/etc/rc.local | 26 +++----- fs_filecheck/opt/groomer/constraint.sh | 4 +- fs_filecheck/opt/groomer/groomer.sh | 92 +++++++++++++------------- fs_filecheck/opt/groomer/init.sh | 8 +-- shell_utils/copy_groomer_to_image.sh | 2 +- 5 files changed, 61 insertions(+), 71 deletions(-) diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index 1ff88b8..fcfb6ca 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -19,25 +19,19 @@ clean(){ /sbin/shutdown -P -h now } +trap clean EXIT TERM INT + echo "GROOMER: end of boot, running rc.local." -# Print the IP address -_IP=$(hostname -I) || true -if [ "$_IP" ]; then - printf "My IP address is %s\n" "$_IP" -fi - -if [ -e /dev/sda ]; then - if [ -e /dev/sdb ]; then +# if [ -e /dev/sda ]; then +# if [ -e /dev/sdb ]; then # avoid possible misuse - /sbin/ifconfig eth0 down - trap clean EXIT TERM INT - cd /opt/groomer - /usr/sbin/led & - ./init.sh - fi -fi +#fdisk -l +echo "Testing, did anything happen." >> /var/tmp/thing.txt -sleep 60 +cd /opt/groomer +./init.sh | tee "/var/tmp/groomer_log.txt" + +sleep 20 exit 0 diff --git a/fs_filecheck/opt/groomer/constraint.sh b/fs_filecheck/opt/groomer/constraint.sh index da7a4fe..d3275d9 100644 --- a/fs_filecheck/opt/groomer/constraint.sh +++ b/fs_filecheck/opt/groomer/constraint.sh @@ -1,5 +1,6 @@ DEV_SRC='/dev/sda' -DEV_DST='sdb1' +DEV_SRCONE='dev/sda1' +DEV_DST='/dev/sdb1' # User allowed to do the following commands without password USERNAME='kitten' @@ -17,7 +18,6 @@ GROOM_LOG="/var/tmp/groomer_log.txt" # commands SYNC='/bin/sync' -TIMIDITY='/usr/bin/timidity' MOUNT='/bin/mount' PMOUNT='/usr/bin/pmount -A -s' PUMOUNT='/usr/bin/pumount' diff --git a/fs_filecheck/opt/groomer/groomer.sh b/fs_filecheck/opt/groomer/groomer.sh index 958305c..72dcd38 100755 --- a/fs_filecheck/opt/groomer/groomer.sh +++ b/fs_filecheck/opt/groomer/groomer.sh @@ -13,12 +13,14 @@ clean(){ echo "GROOMER: Cleaning up after groomer.sh." ${SYNC} + cp "${GROOM_LOG} ${SRC}/groomer_log.txt" + cp "${GROOM_LOG} ${DST}/groomer_log.txt" + # Cleanup source - cp ${GROOM_LOG} ${SRC}/groomer_log.txt pumount ${SRC} # Cleanup destination - cp ${GROOM_LOG} ${LOGS}/groomer_log.txt + rm -rf ${TEMP} rm -rf ${ZIPTEMP} pumount ${DST} @@ -31,19 +33,17 @@ trap clean EXIT TERM INT # De we have a source device if [ ! -b ${DEV_SRC} ]; then echo "GROOMER: Source device (${DEV_SRC}) does not exist." - exit fi + # 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 # Do we have a destination device -if [ ! -b "/dev/${DEV_DST}" ]; then +if [ ! -b "${DEV_DST}" ]; then echo "GROOMER: Destination device (/dev/${DEV_DST}) does not exist." - exit fi # mount and prepare destination device @@ -53,21 +53,23 @@ fi # uid= only works on a vfat FS. What should wedo if we get an ext* FS ? ${PMOUNT} -w ${DEV_DST} ${DST} if [ ${?} -ne 0 ]; then - echo "GROOMER: Unable to mount /dev/${DEV_DST} on /media/${DST}" + echo "GROOMER: Unable to mount /dev/${DEV_DST} on ${DST}" exit else - echo "GROOMER: Target USB device (/dev/${DEV_DST}) mounted at /media/${DST}" - rm -rf "/media/${DST}/FROM_PARTITION_"* + echo "GROOMER: Target USB device (/dev/${DEV_DST}) mounted at ${DST}" + + # rm -rf "/media/${DST}/FROM_PARTITION_"* # prepare temp dirs and make sure it's empty - mkdir -p "${TEMP}" - mkdir -p "${ZIPTEMP}" - mkdir -p "${LOGS}" + # mkdir -p "${TEMP}" + # mkdir -p "${ZIPTEMP}" + # mkdir -p "${LOGS}" - rm -rf "${TEMP}/"* - rm -rf "${ZIPTEMP}/"* - rm -rf "${LOGS}/"* + # rm -rf "${TEMP}/"* + # rm -rf "${ZIPTEMP}/"* + # rm -rf "${LOGS}/"* fi +${PMOUNT} -w ${DEV_SRCONE} ${SRC} sleep 30 @@ -76,41 +78,41 @@ sleep 30 # Find the FS types # lsblk -n -o name,fstype,mountpoint,label,uuid -r -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 +# 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}" +# ${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" +# # 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" +# # 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} +# 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 +# ls -lR "${target_dir}" +# fi +# let PARTCOUNT=`expr $PARTCOUNT + 1` +# done # The cleanup is automatically done in the function clean called when # the program quits diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index 30351b1..10bfbaa 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -13,14 +13,8 @@ fi clean(){ echo "GROOMER: cleaning up after init.sh." ${SYNC} - kill -9 $(cat /tmp/music.pid) - rm -f /tmp/music.pid } trap clean EXIT TERM INT -./music.sh & -echo $! > /tmp/music.pid -echo "GROOMER: music started." - -su ${USERNAME} -c ./groomer.sh | tee ${GROOM_LOG} +su ${USERNAME} -c ./groomer.sh diff --git a/shell_utils/copy_groomer_to_image.sh b/shell_utils/copy_groomer_to_image.sh index bb06370..213df32 100755 --- a/shell_utils/copy_groomer_to_image.sh +++ b/shell_utils/copy_groomer_to_image.sh @@ -3,7 +3,7 @@ set -e set -x -mount /dev/sdb2 /mnt/rpi +# mount /dev/sdb2 /mnt/rpi cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt/rpi/opt/groomer/init.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh From 05cc4c1155615715d664ed5ad00108939a3ac153 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Thu, 12 Jan 2017 14:00:51 -0500 Subject: [PATCH 04/14] Make working copy of logging --- fs_filecheck/etc/rc.local | 8 ++------ fs_filecheck/opt/groomer/constraint.sh | 12 +++++++----- fs_filecheck/opt/groomer/groomer.sh | 19 +++++++++---------- fs_filecheck/opt/groomer/init.sh | 4 +++- shell_utils/copy_groomer_to_image.sh | 4 +--- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index fcfb6ca..8efd17c 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -16,6 +16,7 @@ clean(){ echo "GROOMER: rc.local done, shutting down." + sleep 60 /sbin/shutdown -P -h now } @@ -25,13 +26,8 @@ echo "GROOMER: end of boot, running rc.local." # if [ -e /dev/sda ]; then # if [ -e /dev/sdb ]; then - # avoid possible misuse -#fdisk -l -echo "Testing, did anything happen." >> /var/tmp/thing.txt cd /opt/groomer -./init.sh | tee "/var/tmp/groomer_log.txt" - -sleep 20 +./init.sh exit 0 diff --git a/fs_filecheck/opt/groomer/constraint.sh b/fs_filecheck/opt/groomer/constraint.sh index d3275d9..d46a055 100644 --- a/fs_filecheck/opt/groomer/constraint.sh +++ b/fs_filecheck/opt/groomer/constraint.sh @@ -1,5 +1,5 @@ DEV_SRC='/dev/sda' -DEV_SRCONE='dev/sda1' +DEV_SRCONE='/dev/sda1' DEV_DST='/dev/sdb1' # User allowed to do the following commands without password @@ -11,10 +11,12 @@ ID=`/usr/bin/id -u` # Paths used in multiple scripts SRC="src" DST="dst" -TEMP="/media/${DST}/temp" -ZIPTEMP="/media/${DST}/ziptemp" -LOGS="/media/${DST}/logs" -GROOM_LOG="/var/tmp/groomer_log.txt" +SRC_MNT="/media/src" +DST_MNT="/media/dst" +TEMP="${DST}/temp" +ZIPTEMP="${DST}/ziptemp" +LOGS="${DST}/logs" +GROOM_LOG="/tmp/groom_log.txt" # commands SYNC='/bin/sync' diff --git a/fs_filecheck/opt/groomer/groomer.sh b/fs_filecheck/opt/groomer/groomer.sh index 72dcd38..71a78f2 100755 --- a/fs_filecheck/opt/groomer/groomer.sh +++ b/fs_filecheck/opt/groomer/groomer.sh @@ -11,16 +11,16 @@ fi clean(){ echo "GROOMER: Cleaning up after groomer.sh." + + cp ${GROOM_LOG} "${DST_MNT}/groomer_log.txt" + + # Write anything in memory to disk ${SYNC} - cp "${GROOM_LOG} ${SRC}/groomer_log.txt" - cp "${GROOM_LOG} ${DST}/groomer_log.txt" - - # Cleanup source + # Unmount source pumount ${SRC} - # Cleanup destination - + # Clean up and unmount destination rm -rf ${TEMP} rm -rf ${ZIPTEMP} pumount ${DST} @@ -53,10 +53,10 @@ fi # uid= only works on a vfat FS. What should wedo if we get an ext* FS ? ${PMOUNT} -w ${DEV_DST} ${DST} if [ ${?} -ne 0 ]; then - echo "GROOMER: Unable to mount /dev/${DEV_DST} on ${DST}" + echo "GROOMER: Unable to mount ${DEV_DST} on ${DST_MNT}" exit else - echo "GROOMER: Target USB device (/dev/${DEV_DST}) mounted at ${DST}" + echo "GROOMER: Target USB device (${DEV_DST}) mounted at ${DST_MNT}" # rm -rf "/media/${DST}/FROM_PARTITION_"* @@ -69,9 +69,8 @@ else # rm -rf "${ZIPTEMP}/"* # rm -rf "${LOGS}/"* fi -${PMOUNT} -w ${DEV_SRCONE} ${SRC} -sleep 30 +${PMOUNT} -w ${DEV_SRCONE} ${SRC} # Groom da kitteh! diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index 10bfbaa..8558dc7 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -17,4 +17,6 @@ clean(){ trap clean EXIT TERM INT -su ${USERNAME} -c ./groomer.sh +fdisk -l |& tee ${GROOM_LOG} + +su ${USERNAME} -c ./groomer.sh |& tee ${GROOM_LOG} diff --git a/shell_utils/copy_groomer_to_image.sh b/shell_utils/copy_groomer_to_image.sh index 213df32..1955d69 100755 --- a/shell_utils/copy_groomer_to_image.sh +++ b/shell_utils/copy_groomer_to_image.sh @@ -8,6 +8,4 @@ set -x cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt/rpi/opt/groomer/init.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/constraint.sh /mnt/rpi/opt/groomer/constraint.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local - -umount /mnt/rpi +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local \ No newline at end of file From effd4a86a4c0eb73bcbe3329cf961a42a7582e03 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Thu, 12 Jan 2017 15:42:41 -0500 Subject: [PATCH 05/14] Fix bug with mounting DST --- fs_filecheck/etc/rc.local | 23 +++-- .../opt/groomer/{constraint.sh => config.sh} | 12 ++- fs_filecheck/opt/groomer/groomer.sh | 94 +++++++++++-------- fs_filecheck/opt/groomer/init.sh | 9 +- shell_utils/copy_groomer_to_image.sh | 2 +- 5 files changed, 85 insertions(+), 55 deletions(-) rename fs_filecheck/opt/groomer/{constraint.sh => config.sh} (68%) diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index 8efd17c..fba908f 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -16,18 +16,27 @@ clean(){ echo "GROOMER: rc.local done, shutting down." - sleep 60 + sleep 30 /sbin/shutdown -P -h now } -trap clean EXIT TERM INT - echo "GROOMER: end of boot, running rc.local." -# if [ -e /dev/sda ]; then -# if [ -e /dev/sdb ]; then +# Print the IP address (this doesn't work currently?) +# _IP=$(hostname -I) || true +# if [ "$_IP" ]; then +# printf "My IP address is %s\n" "$_IP" +# fi -cd /opt/groomer -./init.sh +if [ -e /dev/sda ]; then + if [ -e /dev/sdb ]; then + # avoid possible misuse - turn off eth0 (ethernet port) + /sbin/ifconfig eth0 down + trap clean EXIT TERM INT + cd /opt/groomer + /usr/sbin/led & + ./init.sh + fi +fi exit 0 diff --git a/fs_filecheck/opt/groomer/constraint.sh b/fs_filecheck/opt/groomer/config.sh similarity index 68% rename from fs_filecheck/opt/groomer/constraint.sh rename to fs_filecheck/opt/groomer/config.sh index d46a055..bde4fa8 100644 --- a/fs_filecheck/opt/groomer/constraint.sh +++ b/fs_filecheck/opt/groomer/config.sh @@ -1,6 +1,7 @@ DEV_SRC='/dev/sda' -DEV_SRCONE='/dev/sda1' -DEV_DST='/dev/sdb1' +DEV_SRC_ONE='/dev/sda1' +DEV_DST='/dev/sdb' +DEV_DST_ONE='/dev/sdb1' # User allowed to do the following commands without password USERNAME='kitten' @@ -13,13 +14,14 @@ SRC="src" DST="dst" SRC_MNT="/media/src" DST_MNT="/media/dst" -TEMP="${DST}/temp" -ZIPTEMP="${DST}/ziptemp" -LOGS="${DST}/logs" +TEMP="${DST_MNT}/temp" +ZIPTEMP="${DST_MNT}/ziptemp" +LOGS="${DST_MNT}/logs" GROOM_LOG="/tmp/groom_log.txt" # commands SYNC='/bin/sync' +TIMIDITY='/usr/bin/timidity' MOUNT='/bin/mount' PMOUNT='/usr/bin/pmount -A -s' PUMOUNT='/usr/bin/pumount' diff --git a/fs_filecheck/opt/groomer/groomer.sh b/fs_filecheck/opt/groomer/groomer.sh index 71a78f2..10d57a8 100755 --- a/fs_filecheck/opt/groomer/groomer.sh +++ b/fs_filecheck/opt/groomer/groomer.sh @@ -1,9 +1,11 @@ #!/bin/bash +# set -e (exit when a line returns non-0 status) and -x (xtrace) flags set -e set -x -source ./constraint.sh +source ./config.sh + if ! [ "${ID}" -ge "1000" ]; then echo "GROOMER: This script cannot run as root." exit @@ -12,8 +14,9 @@ fi clean(){ echo "GROOMER: Cleaning up after groomer.sh." - cp ${GROOM_LOG} "${DST_MNT}/groomer_log.txt" - + cp ${GROOM_LOG} "${DST_MNT}/groomer_log_dst.txt" + cp ${GROOM_LOG} "${SRC_MNT}/groomer_log_src.txt" + # Write anything in memory to disk ${SYNC} @@ -30,53 +33,66 @@ clean(){ trap clean EXIT TERM INT -# De we have a source device +# De we have a source device? if [ ! -b ${DEV_SRC} ]; then echo "GROOMER: Source device (${DEV_SRC}) does not exist." + exit fi +# Do we have a destination device +if [ ! -b ${DEV_DST} ]; then + echo "GROOMER: Destination device (${DEV_DST}) does not exist." + exit +fi + +# Make sure destination device isn't already mounted +if ${MOUNT}|grep ${DST}; then + ${PUMOUNT} ${DST} || true +fi + +# uid= only works on a vfat FS. What should wedo if we get an ext* FS ? +# 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} +if [ ${?} -ne 0 ]; then + echo "GROOMER: Unable to mount ${DEV_DST_ONE} on ${DST_MNT}" + exit +else + 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}/"* +fi + +sleep 30 + +${PMOUNT} -w ${DEV_SRC_ONE} ${SRC} + +sleep 10 + +# Groom da kitteh! + +# List all block devices (uncomment for diagnostics) +# lsblk -n -o name,fstype,mountpoint,label,uuid -r + # 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." -fi - -# Do we have a destination device -if [ ! -b "${DEV_DST}" ]; then - echo "GROOMER: Destination device (/dev/${DEV_DST}) does not exist." -fi - -# mount and prepare destination device -if ${MOUNT}|grep ${DST}; then - ${PUMOUNT} ${DST} || true -fi -# uid= only works on a vfat FS. What should wedo if we get an ext* FS ? -${PMOUNT} -w ${DEV_DST} ${DST} -if [ ${?} -ne 0 ]; then - echo "GROOMER: Unable to mount ${DEV_DST} on ${DST_MNT}" exit -else - echo "GROOMER: Target USB device (${DEV_DST}) mounted at ${DST_MNT}" - - # rm -rf "/media/${DST}/FROM_PARTITION_"* - - # prepare temp dirs and make sure it's empty - # mkdir -p "${TEMP}" - # mkdir -p "${ZIPTEMP}" - # mkdir -p "${LOGS}" - - # rm -rf "${TEMP}/"* - # rm -rf "${ZIPTEMP}/"* - # rm -rf "${LOGS}/"* fi -${PMOUNT} -w ${DEV_SRCONE} ${SRC} - -# Groom da kitteh! - -# Find the FS types -# lsblk -n -o name,fstype,mountpoint,label,uuid -r - +sleep 10 # PARTCOUNT=1 # for partition in ${DEV_PARTITIONS} # do diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index 8558dc7..357d446 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -1,9 +1,10 @@ #!/bin/bash +# set -e (exit when a line returns non-0 status) and -x (xtrace) flags set -e set -x -source ./constraint.sh +source ./config.sh if [ ${ID} -ne 0 ]; then echo "GROOMER: This script has to be run as root." @@ -17,6 +18,8 @@ clean(){ trap clean EXIT TERM INT -fdisk -l |& tee ${GROOM_LOG} +lsblk -n -o name,fstype,mountpoint,label,uuid -r |& tee ${GROOM_LOG} -su ${USERNAME} -c ./groomer.sh |& tee ${GROOM_LOG} +sleep 30 + +su ${USERNAME} -c ./groomer.sh |& tee -a ${GROOM_LOG} diff --git a/shell_utils/copy_groomer_to_image.sh b/shell_utils/copy_groomer_to_image.sh index 1955d69..0651aa2 100755 --- a/shell_utils/copy_groomer_to_image.sh +++ b/shell_utils/copy_groomer_to_image.sh @@ -7,5 +7,5 @@ set -x cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt/rpi/opt/groomer/init.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/constraint.sh /mnt/rpi/opt/groomer/constraint.sh +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/config.sh /mnt/rpi/opt/groomer/config.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local \ No newline at end of file From a8a670c08ea0c7f304b940781401d5d5fd5bd991 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Fri, 13 Jan 2017 17:05:37 -0500 Subject: [PATCH 06/14] Split part of groomer.sh into mount_dest.sh --- fs_filecheck/etc/rc.local | 1 - fs_filecheck/opt/groomer/config.sh | 33 +++--- fs_filecheck/opt/groomer/groomer.sh | 138 +++++++------------------ fs_filecheck/opt/groomer/init.sh | 8 +- fs_filecheck/opt/groomer/mount_dest.sh | 77 ++++++++++++++ shell_utils/copy_groomer_to_image.sh | 6 +- 6 files changed, 140 insertions(+), 123 deletions(-) mode change 100644 => 100755 fs_filecheck/opt/groomer/config.sh create mode 100755 fs_filecheck/opt/groomer/mount_dest.sh diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index fba908f..d12d10f 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -16,7 +16,6 @@ clean(){ echo "GROOMER: rc.local done, shutting down." - sleep 30 /sbin/shutdown -P -h now } diff --git a/fs_filecheck/opt/groomer/config.sh b/fs_filecheck/opt/groomer/config.sh old mode 100644 new mode 100755 index bde4fa8..e31a4b5 --- a/fs_filecheck/opt/groomer/config.sh +++ b/fs_filecheck/opt/groomer/config.sh @@ -1,27 +1,28 @@ -DEV_SRC='/dev/sda' -DEV_SRC_ONE='/dev/sda1' -DEV_DST='/dev/sdb' -DEV_DST_ONE='/dev/sdb1' - -# User allowed to do the following commands without password -USERNAME='kitten' -MUSIC="/opt/midi/" - +USERNAME="kitten" ID=`/usr/bin/id -u` + # Paths used in multiple scripts SRC="src" -DST="dst" +DEV_SRC="/dev/sda" +DEV_SRC_ONE="/dev/sda1" SRC_MNT="/media/src" + +DST="dst" +DEV_DST="/dev/sdb" +DEV_DST_ONE="/dev/sdb1" DST_MNT="/media/dst" + TEMP="${DST_MNT}/temp" ZIPTEMP="${DST_MNT}/ziptemp" LOGS="${DST_MNT}/logs" GROOM_LOG="/tmp/groom_log.txt" +MUSIC="/opt/midi/" -# commands -SYNC='/bin/sync' -TIMIDITY='/usr/bin/timidity' -MOUNT='/bin/mount' -PMOUNT='/usr/bin/pmount -A -s' -PUMOUNT='/usr/bin/pumount' + +# Commands +SYNC="/bin/sync" +TIMIDITY="/usr/bin/timidity" +MOUNT="/bin/mount" +PMOUNT="/usr/bin/pmount -A -s" +PUMOUNT="/usr/bin/pumount" diff --git a/fs_filecheck/opt/groomer/groomer.sh b/fs_filecheck/opt/groomer/groomer.sh index 10d57a8..7b8dc02 100755 --- a/fs_filecheck/opt/groomer/groomer.sh +++ b/fs_filecheck/opt/groomer/groomer.sh @@ -4,87 +4,25 @@ set -e set -x +# Import constants from config file source ./config.sh if ! [ "${ID}" -ge "1000" ]; then - echo "GROOMER: This script cannot run as root." + echo "GROOMER: groomer.sh cannot run as root." exit fi -clean(){ - echo "GROOMER: Cleaning up after groomer.sh." - - cp ${GROOM_LOG} "${DST_MNT}/groomer_log_dst.txt" - cp ${GROOM_LOG} "${SRC_MNT}/groomer_log_src.txt" - +clean(){ # Write anything in memory to disk ${SYNC} - # Unmount source - pumount ${SRC} - - # Clean up and unmount destination + # Remove temporary files from destination key rm -rf ${TEMP} rm -rf ${ZIPTEMP} - pumount ${DST} - - exit } trap clean EXIT TERM INT -# De we have a source device? -if [ ! -b ${DEV_SRC} ]; then - echo "GROOMER: Source device (${DEV_SRC}) does not exist." - exit -fi - -# Do we have a destination device -if [ ! -b ${DEV_DST} ]; then - echo "GROOMER: Destination device (${DEV_DST}) does not exist." - exit -fi - -# Make sure destination device isn't already mounted -if ${MOUNT}|grep ${DST}; then - ${PUMOUNT} ${DST} || true -fi - -# uid= only works on a vfat FS. What should wedo if we get an ext* FS ? -# 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} -if [ ${?} -ne 0 ]; then - echo "GROOMER: Unable to mount ${DEV_DST_ONE} on ${DST_MNT}" - exit -else - 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}/"* -fi - -sleep 30 - -${PMOUNT} -w ${DEV_SRC_ONE} ${SRC} - -sleep 10 - -# Groom da kitteh! - -# List all block devices (uncomment for diagnostics) -# lsblk -n -o name,fstype,mountpoint,label,uuid -r - # 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 @@ -92,42 +30,46 @@ if [ -z "${DEV_PARTITIONS}" ]; then exit fi -sleep 10 -# 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 +PARTCOUNT=1 +for partition in ${DEV_PARTITIONS} +do + echo "GROOMER: Processing partition ${partition}" + # Unmount anything that is mounted on /media/src + 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}" + # Mount the current partition in write mode + ${PMOUNT} -w ${partition} ${SRC} + # Mark any autorun.inf files as dangerous on the source device + ls ${SRC_MNT} | grep -i autorun.inf | xargs -I {} mv "${SRC_MNT}"/{} "{SRC_MNT}"/DANGEROUS_{}_DANGEROUS || true + # Unmount and remount the current partition in read-only mode + ${PUMOUNT} ${SRC} + ${PMOUNT} -r ${partition} ${SRC} + if [ ${?} -ne 0 ]; then + # Previous command (mounting this partition) failed + 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" + # Put the filenames from the current partition in a logfile + find "/media/${SRC}" -fls "${LOGS}/contents_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" + # Create a directory on ${DST} named PARTION_$PARTCOUNT + target_dir="/media/${DST}/FROM_PARTITION_${PARTCOUNT}" + 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} + # Run the current partition through filecheck.py + 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 + # List destination files (recursively) for debugging + ls -lR "${target_dir}" + fi + let PARTCOUNT=`expr $PARTCOUNT + 1` +done # The cleanup is automatically done in the function clean called when -# the program quits +# the program exits diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index 357d446..120c085 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -4,6 +4,7 @@ set -e set -x +# Import constants from config file source ./config.sh if [ ${ID} -ne 0 ]; then @@ -18,8 +19,7 @@ clean(){ trap clean EXIT TERM INT -lsblk -n -o name,fstype,mountpoint,label,uuid -r |& tee ${GROOM_LOG} +# List block storage devices (for debugging) +lsblk |& tee ${GROOM_LOG} -sleep 30 - -su ${USERNAME} -c ./groomer.sh |& tee -a ${GROOM_LOG} +su ${USERNAME} -c ./mount_dest.sh |& tee -a ${GROOM_LOG} diff --git a/fs_filecheck/opt/groomer/mount_dest.sh b/fs_filecheck/opt/groomer/mount_dest.sh new file mode 100755 index 0000000..0e3d955 --- /dev/null +++ b/fs_filecheck/opt/groomer/mount_dest.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +# set -e (exit when a line returns non-0 status) and -x (xtrace) flags +set -e +set -x + +# Import constants from config file +source ./config.sh + +if ! [ "${ID}" -ge "1000" ]; then + echo "GROOMER: mount_keys.sh cannot run as root." + exit +fi + +clean(){ + echo "GROOMER: Cleaning up in mount_keys.sh." + + # Copy the temporary logfile to the destination key + cp ${GROOM_LOG} "${DST_MNT}/groomer_log_dst.txt" + + # Write anything in memory to disk + ${SYNC} + + # Unmount source and destination + pumount ${SRC} + + # Clean up and unmount destination + pumount ${DST} + + exit +} + +trap clean EXIT TERM INT + +# Check that a device is available on /dev/sda +if [ ! -b ${DEV_SRC} ]; then + echo "GROOMER: Source device (${DEV_SRC}) does not exist." + exit +fi + +# Check that a device is available on /dev/sdb +if [ ! -b ${DEV_DST} ]; then + echo "GROOMER: Destination device (${DEV_DST}) does not exist." + exit +fi + +# If there is already a device mounted on /media/dst, unmount it +if ${MOUNT}|grep ${DST}; then + ${PUMOUNT} ${DST} || true +fi + +# uid= only works on a vfat FS. What should wedo if we get an ext* FS ? +# What does this ^ comment mean? + +# Mount the first partition of DST (/dev/sdb1) +# pmount automatically mounts on /media/ (at /media/dst in this case). +${PMOUNT} -w ${DEV_DST_ONE} ${DST} +if [ ${?} -ne 0 ]; then + echo "GROOMER: Unable to mount ${DEV_DST_ONE} on ${DST_MNT}" + exit +else + 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}/"* +fi + +# Now that destination is mounted and prepared, run the groomer +./groomer.sh diff --git a/shell_utils/copy_groomer_to_image.sh b/shell_utils/copy_groomer_to_image.sh index 0651aa2..8337982 100755 --- a/shell_utils/copy_groomer_to_image.sh +++ b/shell_utils/copy_groomer_to_image.sh @@ -1,11 +1,9 @@ #!/bin/bash -set -e set -x -# mount /dev/sdb2 /mnt/rpi - cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt/rpi/opt/groomer/init.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/config.sh /mnt/rpi/opt/groomer/config.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local \ No newline at end of file +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/mount_dest.sh /mnt/rpi/opt/groomer/mount_dest.sh +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local From b1353fa5bf2bffaabc80711abe677c55e084b62e Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Fri, 13 Jan 2017 17:56:16 -0500 Subject: [PATCH 07/14] Re add music to scripts --- fs_filecheck/opt/groomer/groomer.sh | 6 +++--- fs_filecheck/opt/groomer/init.sh | 7 +++++++ shell_utils/copy_groomer_to_image.sh | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fs_filecheck/opt/groomer/groomer.sh b/fs_filecheck/opt/groomer/groomer.sh index 7b8dc02..63d11e8 100755 --- a/fs_filecheck/opt/groomer/groomer.sh +++ b/fs_filecheck/opt/groomer/groomer.sh @@ -47,7 +47,7 @@ do ${PUMOUNT} ${SRC} ${PMOUNT} -r ${partition} ${SRC} if [ ${?} -ne 0 ]; then - # Previous command (mounting this partition) failed + # Previous command (mounting current partition) failed echo "GROOMER: Unable to mount ${partition} on /media/${SRC}" else echo "GROOMER: ${partition} mounted at /media/${SRC}" @@ -61,9 +61,9 @@ do LOGFILE="${LOGS}/processing.txt" # Run the current partition through filecheck.py - echo "GROOMER: ==== Starting processing of /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE} + echo "==== 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} + echo "==== Done with /media/${SRC} to ${target_dir}. ====" >> ${LOGFILE} # List destination files (recursively) for debugging ls -lR "${target_dir}" diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index 120c085..f990a4c 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -15,10 +15,17 @@ fi clean(){ echo "GROOMER: cleaning up after init.sh." ${SYNC} + # Stop the music from playing + kill -9 $(cat /tmp/music.pid) + rm -f /tmp/music.pid } trap clean EXIT TERM INT +# Start music +./music.sh & +echo $! > /tmp/music.pid + # List block storage devices (for debugging) lsblk |& tee ${GROOM_LOG} diff --git a/shell_utils/copy_groomer_to_image.sh b/shell_utils/copy_groomer_to_image.sh index 8337982..b870687 100755 --- a/shell_utils/copy_groomer_to_image.sh +++ b/shell_utils/copy_groomer_to_image.sh @@ -6,4 +6,5 @@ cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/config.sh /mnt/rpi/opt/groomer/config.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/mount_dest.sh /mnt/rpi/opt/groomer/mount_dest.sh +cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/music.sh /mnt/rpi/opt/groomer/music.sh cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local From 5632c9096ac9394da4c03d25bbf76c0198787e8e Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Tue, 17 Jan 2017 10:15:36 -0500 Subject: [PATCH 08/14] Add udev rules for controlling where keys are found in /dev --- fs_filecheck/etc/udev/rules.d/10-usb.rules | 6 ++++++ fs_filecheck/opt/groomer/config.sh | 6 ++---- fs_filecheck/opt/groomer/init.sh | 7 ++++--- fs_filecheck/opt/groomer/mount_dest.sh | 6 +++--- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 fs_filecheck/etc/udev/rules.d/10-usb.rules diff --git a/fs_filecheck/etc/udev/rules.d/10-usb.rules b/fs_filecheck/etc/udev/rules.d/10-usb.rules new file mode 100644 index 0000000..700bf79 --- /dev/null +++ b/fs_filecheck/etc/udev/rules.d/10-usb.rules @@ -0,0 +1,6 @@ +# The purpose of this rules file is to ensure that the top left usb port and its partitions have a symlink to /dev/source_key[num], and the other ports to /dev/dest_key[num] +KERNELS=="1-1.2", SUBSYSTEMS=="usb", SYMLINK+="source_key%n" +KERNELS=="1-1.[3-5]*", SUBSYSTEMS=="usb", SYMLINK+="dest_key%n" + +# KERNELS=="1-1.2", SUBSYSTEMS=="usb", ENV{USB} SYMLINK+="source_key%n" +# KERNELS=="1-1.[3-5]*", SUBSYSTEMS=="usb", SYMLINK+="dest_key%n" \ No newline at end of file diff --git a/fs_filecheck/opt/groomer/config.sh b/fs_filecheck/opt/groomer/config.sh index e31a4b5..f4612fc 100755 --- a/fs_filecheck/opt/groomer/config.sh +++ b/fs_filecheck/opt/groomer/config.sh @@ -4,13 +4,11 @@ ID=`/usr/bin/id -u` # Paths used in multiple scripts SRC="src" -DEV_SRC="/dev/sda" -DEV_SRC_ONE="/dev/sda1" +DEV_SRC="/dev/source_key" SRC_MNT="/media/src" DST="dst" -DEV_DST="/dev/sdb" -DEV_DST_ONE="/dev/sdb1" +DEV_DST="/dev/dest_key" DST_MNT="/media/dst" TEMP="${DST_MNT}/temp" diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index f990a4c..680f0ed 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -26,7 +26,8 @@ trap clean EXIT TERM INT ./music.sh & echo $! > /tmp/music.pid -# List block storage devices (for debugging) -lsblk |& tee ${GROOM_LOG} +# List block storage devices for debugging +# Make sure to set tee in append (-a) mode below if you uncomment +# lsblk |& tee ${GROOM_LOG} -su ${USERNAME} -c ./mount_dest.sh |& tee -a ${GROOM_LOG} +su ${USERNAME} -c ./mount_dest.sh |& tee ${GROOM_LOG} diff --git a/fs_filecheck/opt/groomer/mount_dest.sh b/fs_filecheck/opt/groomer/mount_dest.sh index 0e3d955..9753680 100755 --- a/fs_filecheck/opt/groomer/mount_dest.sh +++ b/fs_filecheck/opt/groomer/mount_dest.sh @@ -54,12 +54,12 @@ fi # Mount the first partition of DST (/dev/sdb1) # pmount automatically mounts on /media/ (at /media/dst in this case). -${PMOUNT} -w ${DEV_DST_ONE} ${DST} +${PMOUNT} -w /dev/dest_key1 ${DST} if [ ${?} -ne 0 ]; then - echo "GROOMER: Unable to mount ${DEV_DST_ONE} on ${DST_MNT}" + echo "GROOMER: Unable to mount ${DEV_DST}1 on ${DST_MNT}" exit else - echo "GROOMER: Destination USB device (${DEV_DST_ONE}) mounted at ${DST_MNT}" + echo "GROOMER: Destination USB device (${DEV_DST}1) mounted at ${DST_MNT}" # Remove any existing "FROM_PARTITION_" directories rm -rf "/media/${DST}/FROM_PARTITION_"* From 7ffa4552b46a01975894cd7ccf720db06a2558e9 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Fri, 13 Jan 2017 17:08:07 -0500 Subject: [PATCH 09/14] Turn off autosleep in rc.local --- fs_filecheck/etc/rc.local | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index d12d10f..ad6e7f7 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -29,8 +29,10 @@ echo "GROOMER: end of boot, running rc.local." if [ -e /dev/sda ]; then if [ -e /dev/sdb ]; then - # avoid possible misuse - turn off eth0 (ethernet port) + # Avoid possible misuse - turn off eth0 (ethernet port) /sbin/ifconfig eth0 down + # Stop hdmi display from sleeping after a period of time + setterm -powersave off -blank 0 trap clean EXIT TERM INT cd /opt/groomer /usr/sbin/led & From 0d3e3d4ce570131b5dea13fa8ec8faf9826f6c1e Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Mon, 23 Jan 2017 22:32:20 -0500 Subject: [PATCH 10/14] Debug udev rules --- fs_filecheck/etc/pmount.allow | 2 +- fs_filecheck/etc/rc.local | 1 - fs_filecheck/etc/udev/rules.d/10-usb.rules | 7 ++----- fs_filecheck/etc/udev/rules.d/90-qemu.rules | 3 +++ fs_filecheck/opt/groomer/groomer.sh | 2 +- fs_filecheck/opt/groomer/mount_dest.sh | 10 +++++----- fs_filecheck/opt/groomer/music.sh | 2 +- shell_utils/copy_groomer_to_image.sh | 14 ++++++++------ 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/fs_filecheck/etc/pmount.allow b/fs_filecheck/etc/pmount.allow index e9bb419..0964946 100644 --- a/fs_filecheck/etc/pmount.allow +++ b/fs_filecheck/etc/pmount.allow @@ -1,5 +1,5 @@ # /etc/pmount.allow # pmount will allow users to additionally mount all devices that are # listed here. -/dev/sdb1 +/dev/sdb* /dev/sda* diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index ad6e7f7..fb86b0b 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -35,7 +35,6 @@ if [ -e /dev/sda ]; then setterm -powersave off -blank 0 trap clean EXIT TERM INT cd /opt/groomer - /usr/sbin/led & ./init.sh fi fi diff --git a/fs_filecheck/etc/udev/rules.d/10-usb.rules b/fs_filecheck/etc/udev/rules.d/10-usb.rules index 700bf79..bbe5128 100644 --- a/fs_filecheck/etc/udev/rules.d/10-usb.rules +++ b/fs_filecheck/etc/udev/rules.d/10-usb.rules @@ -1,6 +1,3 @@ # The purpose of this rules file is to ensure that the top left usb port and its partitions have a symlink to /dev/source_key[num], and the other ports to /dev/dest_key[num] -KERNELS=="1-1.2", SUBSYSTEMS=="usb", SYMLINK+="source_key%n" -KERNELS=="1-1.[3-5]*", SUBSYSTEMS=="usb", SYMLINK+="dest_key%n" - -# KERNELS=="1-1.2", SUBSYSTEMS=="usb", ENV{USB} SYMLINK+="source_key%n" -# KERNELS=="1-1.[3-5]*", SUBSYSTEMS=="usb", SYMLINK+="dest_key%n" \ No newline at end of file +KERNEL=="sd*", KERNELS=="1-1.2", SUBSYSTEMS=="usb", SYMLINK+="source_key%n" +KERNEL=="sd*", KERNELS=="1-1.[3-5]", SUBSYSTEMS=="usb", SYMLINK+="dest_key%n" diff --git a/fs_filecheck/etc/udev/rules.d/90-qemu.rules b/fs_filecheck/etc/udev/rules.d/90-qemu.rules index 07dfc21..98b9071 100644 --- a/fs_filecheck/etc/udev/rules.d/90-qemu.rules +++ b/fs_filecheck/etc/udev/rules.d/90-qemu.rules @@ -1,2 +1,5 @@ +# This udev rule is designed to make the hardware appear more like the actual raspi hardware when emulating in Qemu. You might have to change sdc to sda or sdb depending on where the filesystem you are emulating is available from in /dev/. +# See http://pub.phyks.me/respawn/mypersonaldata/public/2014-05-20-11-08-01/ for more info. KERNEL=="sdc", SYMLINK+="mmcblk0" KERNEL=="sdc?", SYMLINK+="mmcblk0p%n", +#KERNEL=="sdc2", SYMLINK+="root" diff --git a/fs_filecheck/opt/groomer/groomer.sh b/fs_filecheck/opt/groomer/groomer.sh index 63d11e8..7a3e989 100755 --- a/fs_filecheck/opt/groomer/groomer.sh +++ b/fs_filecheck/opt/groomer/groomer.sh @@ -23,7 +23,7 @@ clean(){ trap clean EXIT TERM INT -# Find the partition names on the source device +# Find the partition names on the device available at /dev/source_key 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." diff --git a/fs_filecheck/opt/groomer/mount_dest.sh b/fs_filecheck/opt/groomer/mount_dest.sh index 9753680..720ac47 100755 --- a/fs_filecheck/opt/groomer/mount_dest.sh +++ b/fs_filecheck/opt/groomer/mount_dest.sh @@ -17,7 +17,7 @@ clean(){ # Copy the temporary logfile to the destination key cp ${GROOM_LOG} "${DST_MNT}/groomer_log_dst.txt" - + # Write anything in memory to disk ${SYNC} @@ -32,13 +32,13 @@ clean(){ trap clean EXIT TERM INT -# Check that a device is available on /dev/sda +# Check that a device is available on /dev/source_key (symlinked to /dev/sda or sdb) if [ ! -b ${DEV_SRC} ]; then echo "GROOMER: Source device (${DEV_SRC}) does not exist." exit fi -# Check that a device is available on /dev/sdb +# Check that a device is available on /dev/dest_key (symlinked to /dev/sda or sdb) if [ ! -b ${DEV_DST} ]; then echo "GROOMER: Destination device (${DEV_DST}) does not exist." exit @@ -52,9 +52,9 @@ fi # uid= only works on a vfat FS. What should wedo if we get an ext* FS ? # What does this ^ comment mean? -# Mount the first partition of DST (/dev/sdb1) +# Mount the first partition of DST (/dev/dest_key1) # pmount automatically mounts on /media/ (at /media/dst in this case). -${PMOUNT} -w /dev/dest_key1 ${DST} +${PMOUNT} -w "${DEV_DST}1" ${DST} if [ ${?} -ne 0 ]; then echo "GROOMER: Unable to mount ${DEV_DST}1 on ${DST_MNT}" exit diff --git a/fs_filecheck/opt/groomer/music.sh b/fs_filecheck/opt/groomer/music.sh index 8c769f0..c57639d 100755 --- a/fs_filecheck/opt/groomer/music.sh +++ b/fs_filecheck/opt/groomer/music.sh @@ -3,7 +3,7 @@ set -e #set -x -source ./constraint.sh +source ./config.sh killed(){ echo 'Music stopped.' diff --git a/shell_utils/copy_groomer_to_image.sh b/shell_utils/copy_groomer_to_image.sh index b870687..fd1a7c1 100755 --- a/shell_utils/copy_groomer_to_image.sh +++ b/shell_utils/copy_groomer_to_image.sh @@ -2,9 +2,11 @@ set -x -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt/rpi/opt/groomer/init.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/config.sh /mnt/rpi/opt/groomer/config.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/mount_dest.sh /mnt/rpi/opt/groomer/mount_dest.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/music.sh /mnt/rpi/opt/groomer/music.sh -cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local +# cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/init.sh /mnt/rpi/opt/groomer/init.sh +# cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/groomer.sh /mnt/rpi/opt/groomer/groomer.sh +# cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/config.sh /mnt/rpi/opt/groomer/config.sh +# cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/mount_dest.sh /mnt/rpi/opt/groomer/mount_dest.sh +# cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/opt/groomer/music.sh /mnt/rpi/opt/groomer/music.sh +# cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/rc.local /mnt/rpi/etc/rc.local +# cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/pmount.allow /mnt/rpi/etc/pmount.allow +# cp /media/sf_ubuntu-shared/Circlean-Ubuntu/fs_filecheck/etc/udev/rules.d/10-usb.rules /mnt/rpi/etc/udev/rules.d/10-usb.rules From deca2595299760871b55b83e6a93d6f274953fbf Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Tue, 24 Jan 2017 15:24:05 -0500 Subject: [PATCH 11/14] Remove led related stuff --- diode_controller/Makefile | 2 - diode_controller/led.c | 81 --------- ledButton_controller/Makefile | 2 - ledButton_controller/ledBtn.c | 282 ------------------------------- ledButton_controller/test_ledBtn | 27 --- 5 files changed, 394 deletions(-) delete mode 100644 diode_controller/Makefile delete mode 100644 diode_controller/led.c delete mode 100644 ledButton_controller/Makefile delete mode 100644 ledButton_controller/ledBtn.c delete mode 100755 ledButton_controller/test_ledBtn diff --git a/diode_controller/Makefile b/diode_controller/Makefile deleted file mode 100644 index da190d5..0000000 --- a/diode_controller/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -led: led.c - gcc -ggdb -o led led.c diff --git a/diode_controller/led.c b/diode_controller/led.c deleted file mode 100644 index 67f7342..0000000 --- a/diode_controller/led.c +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* GPIO registers address */ -#define BCM2708_PERI_BASE 0x20000000 -#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */ -#define BLOCK_SIZE (256) - -/* GPIO setup macros. Always use GPIO_IN(x) before using GPIO_OUT(x) or GPIO_ALT(x,y) */ -#define GPIO_IN(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3)) -#define GPIO_OUT(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3)) -#define GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3)) - -#define GPIO_SET(g) *(gpio+7) = 1<<(g) /* sets bit which are 1, ignores bit which are 0 */ -#define GPIO_CLR(g) *(gpio+10) = 1<<(g) /* clears bit which are 1, ignores bit which are 0 */ -#define GPIO_LEV(g) (*(gpio+13) >> (g)) & 0x00000001 - - - -#define GPIO_4 4 - -int mem_fd; -void *gpio_map; -volatile uint32_t *gpio; - -int main(int argc, char* argv[]) -{ - int ret; - int i; - /* open /dev/mem */ - mem_fd = open("/dev/mem", O_RDWR|O_SYNC); - if (mem_fd == -1) { - perror("Cannot open /dev/mem"); - exit(1); - } - - /* mmap GPIO */ - gpio_map = mmap(NULL, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, GPIO_BASE); - if (gpio_map == MAP_FAILED) { - perror("mmap() failed"); - exit(1); - } - /* Always use volatile pointer! */ - gpio = (volatile uint32_t *)gpio_map; - - - GPIO_IN(GPIO_4); /* must use GPIO_IN before we can use GPIO_OUT */ - GPIO_OUT(GPIO_4); - - //Turn on led - while (1) { - //printf("Enable LED\n"); - GPIO_SET(GPIO_4); - usleep(1000000); - //printf("Disable GPIO\n"); // Does not seem to work? - //GPIO_CLR(GPIO_4); - //usleep(1000000); - } - /* Free up ressources */ - /* munmap GPIO */ - ret = munmap(gpio_map, BLOCK_SIZE); - if (ret == -1) { - perror("munmap() failed"); - exit(1); - } - /* close /dev/mem */ - ret = close(mem_fd); - if (ret == -1) { - perror("Cannot close /dev/mem"); - exit(1); - } - - return EXIT_SUCCESS; -} diff --git a/ledButton_controller/Makefile b/ledButton_controller/Makefile deleted file mode 100644 index b6bd8a0..0000000 --- a/ledButton_controller/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -ledBtn: ledBtn.c - gcc -o ledBtn ledBtn.c diff --git a/ledButton_controller/ledBtn.c b/ledButton_controller/ledBtn.c deleted file mode 100644 index e52aa16..0000000 --- a/ledButton_controller/ledBtn.c +++ /dev/null @@ -1,282 +0,0 @@ -/***************************************************************************************/ -/* */ -/* file : ledBtn.c */ -/* */ -/* synopsis : */ -/* the compiled code should be ran with root privileges to allow for access to */ -/* the GPIO pins through direct GPIO register manipulation in C-code. */ -/* After initialization, the code update the LEDs status according to the commands */ -/* passed on std input (using a pipe). */ -/* It also monitors the push-button and triggers a reboot sequence */ -/* when it is depressed. */ -/* */ -/* */ -/* This code is based on examples from */ -/* http://elinux.org/RPi_Low-level_peripherals#C */ -/* How to access GPIO registers from C-code on the Raspberry-Pi, Example program */ -/* Dom and Gert, 15-January-2012, Revised: 15-Feb-2013 */ -/* */ -/* and from Raphael Vinot (CIRCL.lu) */ -/* */ -/* v 1.00 - 22/02/2015 - initial release (Marc Durvaux) */ -/* v 1.10 - 27/02/2015 - added 'z' command for debugging, improved handling of */ -/* concateneted command sequences */ -/* */ -/* */ -/* */ -/***************************************************************************************/ - -// Includes -#include -#include -#include -#include -#include -#include -#include - -// Constant for low-level access to GPIO -#define BCM2708_PERI_BASE 0x20000000 -#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */ -#define BLOCK_SIZE (4*1024) - -// global variables related to GPIO -int mem_fd ; -void *gpio_map ; -volatile unsigned *gpio ; // I/O access - -// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y) -#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3)) -#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3)) -#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3)) - -#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0 -#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0 - -#define GET_GPIO(g) (*(gpio+13)&(1<= 4) { // final state, immediate reboot - close(fd) ; - do_reboot() ; - } - } - if (Btn_press_count == LONG_PUSH) { // trigger forced reboot - state = 10 ; // LED animation before reboot - repeat_count = 0 ; - } - } - Btn_prev_state = Btn_state ; - - nbytes = read(fd, &code, 1) ; - if (nbytes < 0) { - perror("read") ; - exit (2) ; - } - - if (nbytes > 0) { - switch (code) { // codes evaluated at every tic - case 'z' : // clear without restart (for debugging) - GPIO_CLR = 1<= MAX_COUNT) { - count = 0 ; - - switch (state) { // states evaluated after MAX_COUNT tics - case 3 : // green LED flash OFF - GPIO_CLR = 1< 5) { - state = 12 ; - } else { - state = 10 ; - } - break ; - case 12 : // proceed with reboot - close(fd) ; - do_reboot() ; - break ; - } // end switch - } // end if - - // loop delay - nanosleep((struct timespec[]){{0, TIME_TIC}}, NULL) ; - } - - return 0 ; // we should never come here! -} // main - -/***************************************************************************************/ -// -// Set up a memory region to access GPIO -// -void setup_io() { - /* open /dev/mem */ - if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) { - printf("can't open /dev/mem \n"); - exit(-1); - } - - /* mmap GPIO */ - gpio_map = mmap( - NULL, //Any adddress in our space will do - BLOCK_SIZE, //Map length - PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory - MAP_SHARED, //Shared with other processes - mem_fd, //File to map - GPIO_BASE //Offset to GPIO peripheral - ); - - close(mem_fd); //No need to keep mem_fd open after mmap - - if (gpio_map == MAP_FAILED) { - printf("mmap error %d\n", (int)gpio_map);//errno also set! - exit(-1); - } - - // Always use volatile pointer! - gpio = (volatile unsigned *)gpio_map ; - - // initializes the LED and push-button pins - INP_GPIO( GREEN_LED) ; // must use INP_GPIO before we can use OUT_GPIO - OUT_GPIO( GREEN_LED) ; - INP_GPIO( YELLOW_LED) ; - OUT_GPIO( YELLOW_LED) ; - INP_GPIO( RED_LED) ; - OUT_GPIO( RED_LED) ; - INP_GPIO( PUSHBUTTON) ; - - // initializes LEDs to OFF state - GPIO_CLR = 1< $FIFO -#sleep 1 -# send command "PROCESSING" -echo "p" > $FIFO -sleep 1 -# send command "FILE processed" -echo "f" > $FIFO -sleep 3 -# send command "FILE processed" -echo "f" > $FIFO -sleep 3 -# send command "processing successfully COMPLETED" -echo "c" > $FIFO -sleep 2 -# send command "ZERO (clear display and return state to 0)" -echo "z" > $FIFO -sleep 2 -# send command "ERROR" -echo "e" > $FIFO - From 74a22a5ee2245914265fdc721a04f12cc59481f8 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Tue, 24 Jan 2017 15:26:09 -0500 Subject: [PATCH 12/14] Improve rc.local comments --- fs_filecheck/etc/rc.local | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index fb86b0b..c80ebf3 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -11,8 +11,8 @@ # # By default this script does nothing. # -# The above are the default comments for rc.local. For Circlean, rc.local has -# been modified to start the grooming process on boot. +## The above are the default comments for rc.local. For Circlean, rc.local has +## been modified to start the grooming process after booting. clean(){ echo "GROOMER: rc.local done, shutting down." From c51531f77c57f662f9948a399ff4001c72717e38 Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Wed, 25 Jan 2017 01:48:21 -0500 Subject: [PATCH 13/14] Readme update with filesystem info --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4f9e1a0..3ffacce 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,21 @@ And the linux way is in the command line, via dd (see in copy_to_final.sh) If you'd like to contribute to the project or build the image yourself, see [contributing](CONTRIBUTING.md) and the [setup readme](README_setup.md). +This is a work in progress - contributions are welcome. Why/What ======== This project aims to be useful when you get/find a USB key that you can't trust, -and you want to have a look at its contents without taking the risk of plugging it into your -main computer directly. +and you want to look at its contents without taking the risk of plugging it into +your computer directly. -This is a work in progress - contributions are welcome: +CIRCLean is currently tested to work with USB keys that have FAT32, NTFS, or +ext2/3/4 filesystems. Currently, exFAT is not supported due to lack of support for +this format in pmount. The vast majority of USB keys will be FAT32 or NTFS. -The content of the first key will be copied or/and converted to the second key -following these rules (based on the mime type, as determined by libmagic): +The content of the untrusted key will be copied or/and converted to the second +(blank) key following these rules (based on the mime type as determined bylibmagic): - Direct copy of: - Plain text files (mime type: text/*) - Audio files (mime type: audio/*) From 1ecf260f678610a26fb50f1bce8dccb71343143c Mon Sep 17 00:00:00 2001 From: Dan Puttick Date: Wed, 25 Jan 2017 01:59:35 -0500 Subject: [PATCH 14/14] Moving autosleep from rc.local to init.sh --- fs_filecheck/etc/rc.local | 2 -- fs_filecheck/opt/groomer/init.sh | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs_filecheck/etc/rc.local b/fs_filecheck/etc/rc.local index c80ebf3..d0b2b9b 100755 --- a/fs_filecheck/etc/rc.local +++ b/fs_filecheck/etc/rc.local @@ -31,8 +31,6 @@ if [ -e /dev/sda ]; then if [ -e /dev/sdb ]; then # Avoid possible misuse - turn off eth0 (ethernet port) /sbin/ifconfig eth0 down - # Stop hdmi display from sleeping after a period of time - setterm -powersave off -blank 0 trap clean EXIT TERM INT cd /opt/groomer ./init.sh diff --git a/fs_filecheck/opt/groomer/init.sh b/fs_filecheck/opt/groomer/init.sh index 680f0ed..adc4b6d 100755 --- a/fs_filecheck/opt/groomer/init.sh +++ b/fs_filecheck/opt/groomer/init.sh @@ -22,6 +22,9 @@ clean(){ trap clean EXIT TERM INT +# Stop hdmi display from sleeping after a period of time +setterm -powersave off -blank 0 + # Start music ./music.sh & echo $! > /tmp/music.pid