mirror of https://github.com/CIRCL/Circlean
run the script as user (via sudo)
parent
3f9c6e7b8f
commit
eb2f394ec1
|
@ -0,0 +1,21 @@
|
||||||
|
DEV_SRC='/dev/sdf'
|
||||||
|
DEV_DST='/dev/sdg1'
|
||||||
|
HOME='/home/kitten'
|
||||||
|
# User allowed to do the following commands without password
|
||||||
|
USERNAME='kitten'
|
||||||
|
|
||||||
|
# commands
|
||||||
|
SUDO='/usr/bin/sudo'
|
||||||
|
ID='/usr/bin/id -u'
|
||||||
|
|
||||||
|
# root commands
|
||||||
|
MOUNT='/bin/mount'
|
||||||
|
UMOUNT='/bin/umount'
|
||||||
|
SYNC='/bin/sync'
|
||||||
|
SHUTDOWN='/sbin/shutdown'
|
||||||
|
|
||||||
|
|
||||||
|
# To put in /etc/sudoers
|
||||||
|
# Cmnd alias specification
|
||||||
|
#Cmnd_Alias GROOMER_CMDS = /bin/mount, /bin/umount, /bin/sync
|
||||||
|
#kitten ALL=(ALL) NOPASSWD: GROOMER_CMDS
|
|
@ -3,12 +3,7 @@
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
#Constraints
|
source ./constraint.sh
|
||||||
DEV_SRC='/dev/sdf'
|
|
||||||
DEV_DST='/dev/sdg1'
|
|
||||||
HOME=testing
|
|
||||||
############
|
|
||||||
|
|
||||||
|
|
||||||
SRC=${HOME}/src
|
SRC=${HOME}/src
|
||||||
DST=${HOME}/dst
|
DST=${HOME}/dst
|
||||||
|
@ -20,20 +15,19 @@ LOGS=${DST}/logs
|
||||||
|
|
||||||
clean(){
|
clean(){
|
||||||
echo Cleaning.
|
echo Cleaning.
|
||||||
sync
|
${SUDO} ${SYNC}
|
||||||
|
|
||||||
# Cleanup source
|
# Cleanup source
|
||||||
umount $SRC
|
${SUDO} ${UMOUNT} $SRC || true
|
||||||
rm -rf $SRC
|
rm -rf $SRC
|
||||||
|
|
||||||
# Cleanup destination
|
# Cleanup destination
|
||||||
rm -rf ${TEMP}
|
rm -rf ${TEMP}
|
||||||
rm -rf ${ZIPTEMP}
|
rm -rf ${ZIPTEMP}
|
||||||
umount $DST
|
${SUDO} ${UMOUNT} $DST || true
|
||||||
rm -rf $DST
|
rm -rf $DST
|
||||||
|
|
||||||
# Only if running on a rPi
|
exit
|
||||||
#/sbin/shutdown -h now
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trap clean EXIT TERM INT
|
trap clean EXIT TERM INT
|
||||||
|
@ -64,13 +58,14 @@ if [ ! -d $DST ]; then
|
||||||
mkdir $DST
|
mkdir $DST
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mount and prepare destination device
|
# mount and prepare destination device
|
||||||
if mount|grep $DST; then
|
if ${MOUNT}|grep $DST; then
|
||||||
umount $DST || true
|
${SUDO} ${UMOUNT} $DST || true
|
||||||
fi
|
fi
|
||||||
mount -o noexec,nosuid,nodev ${DEV_DST} ${DST}
|
# uid= only works on a vfat FS. What should wedo if we get an ext* FS ?
|
||||||
|
${SUDO} ${MOUNT} -t vfat -o user,noexec,nosuid,nodev,rw,uid=`${ID}` ${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
|
exit
|
||||||
else
|
else
|
||||||
echo 'Target USB device ('${DEV_DST}') mounted at '${DST}
|
echo 'Target USB device ('${DEV_DST}') mounted at '${DST}
|
||||||
|
@ -94,13 +89,13 @@ for partition in ${DEV_PARTITIONS}
|
||||||
do
|
do
|
||||||
# Processing a partition
|
# Processing a partition
|
||||||
echo Processing partition: ${partition}
|
echo Processing partition: ${partition}
|
||||||
if mount|grep $SRC; then
|
if ${MOUNT}|grep $SRC; then
|
||||||
umount $SRC
|
${SUDO} ${UMOUNT} $SRC
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount -o noexec,nosuid,nodev -r $partition $SRC
|
${SUDO} ${MOUNT} -o noexec,nosuid,nodev -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
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
|
||||||
|
USERNAME='kitten'
|
||||||
|
|
||||||
|
su ${USERNAME} -c ./groomer.sh
|
||||||
|
|
||||||
|
echo 'Done.'
|
||||||
|
# Only if running on a rPi
|
||||||
|
# shutdown -h now
|
||||||
|
|
Loading…
Reference in New Issue