Edited README, added initial client tools

This commit is contained in:
2012-08-05 19:19:59 -04:00
parent ea6ad91249
commit 1eafe5a220
6 changed files with 213 additions and 1 deletions

41
client/bin/disco-fs-diff Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
OLDPWD=$(pwd)
DISCOROOT=/var/disco/testfs
COLOR_CYAN=$(echo -e '\033[0;36;40m');
COLOR_MAGENTA=$(echo -e '\033[0;35;40m');
COLOR_GREEN=$(echo -e '\033[0;32;40m');
COLOR_YELLOW=$(echo -e '\033[0;33;40m');
COLOR_BLUE=$(echo -e '\033[0;34;40m');
COLOR_RED=$(echo -e '\033[0;31;40m');
COLOR_NORMAL=$(echo -e '\033[0m');
cd $DISCOROOT
diff -r ./rootfs ./scratchfs |\
grep -v "^Only in ./rootfs" |\
sed s/"^Only in \.\/scratchfs\(.*\): \(.*\)"/"info: File: created \1\/\2 : (CONTENT)"/g |\
sed s/"\/\/"/"\/"/g |\
grep -v "File: created /.unionfs" |\
sed s/"^Binary files .\/rootfs\(.*\) and .\/scratchfs.*"/"info: File: modified \1 : (OLDMD5SUM) => (NEWMD5SUM)"/g |\
sed s/"^diff -r .\/rootfs\(.*\) .\/scratchfs\(.*\)"/"info: File: modified \1 :"/g > /tmp/$$.discofsdiff
find ./scratchfs/.unionfs -iname "*_HIDDEN~" |\
sed s/"^.\/scratchfs\/.unionfs\(.*\)_HIDDEN~"/"info: File: deleted \1"/g >> /tmp/$$.discofsdiff
#Find the permissions/timestamp diffs from rsync
rsync -ani ./scratchfs/* ./rootfs/ | grep -v .unionfs
# Swap out the (CONTENT) and (MD5SUM) hashes for actual content and md5s
cat /tmp/$$.discofsdiff | python ${OLDPWD}/disco-fs-fixup.py > /tmp/$$.newfile
mv /tmp/$$.newfile n/tmp/$$.discofsdiff
cat /tmp/$$.discofsdiff |\
sed s/"^info:\(.*\)"/"${COLOR_CYAN}info:\1${COLOR_NORMAL}"/g
#sed s/"^warning: \(.*\)"/"${COLOR_YELLOW}warning: \1${COLOR_NORMAL}"/g
cd $OLDPWD

76
client/bin/disco-fs-mount Executable file
View File

@@ -0,0 +1,76 @@
#!/bin/bash
DISCOCFG=/etc/disco
DISCOROOT=/var/disco/testfs
mount | grep $DISCOROOT >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "disco chroot is already mounted, please exec disco-fs-unmount and try again."
exit 1
fi
# Cleanup old junk
rm -rf ${DISCOROOT}/scratchfs
rm -rf ${DISCOROOT}/restricted/bin/*
# Prepare all the mountpoint directories
mkdir -p ${DISCOROOT}/chroot
mkdir -p ${DISCOROOT}/execs/bin
mkdir -p ${DISCOROOT}/proc/proc
mkdir -p ${DISCOROOT}/sysfs/sys
mkdir -p ${DISCOROOT}/rootfs
mkdir -p ${DISCOROOT}/scratchfs
mkdir -p ${DISCOROOT}/dev/dev
mkdir -p ${DISCOROOT}/restricted/bin
# Setup all the commands for the bash restricted execution environment
mkdir -p ${DISCOCFG}/restricted.d
for file in $(cat ${DISCOCFG}/restricted.d/* 2>/dev/null | grep -v "^#")
do
mkdir -p ${DISCOROOT}/restricted/bin$(echo $file | dirname $file)
ln -s $file ${DISCOROOT}/restricted/bin/$file
done
# Setup some more restricted execution stuff, but only if we actually have $NOOP
if [ "$NOOP" != "" ]; then
# Here we play a pretty lame trick on the user. /bin/bash will always exist
# (unfortunately), but we can force everything else to our rbash wrapper,
# forcing restricted execution. The user can get around this by calling
# /bin/bash directly, but that's on the user. TNMP, RTFM!
ln -s /bin/bash ${DISCOROOT}/restricted/bin/rbash
for dir in /usr/bin /usr/local/bin /usr/sbin;
do
mkdir -p ${DISCOROOT}/restricted/${dir}
echo "#!/bin/bash --restricted\neval \$@" > ${DISCOROOT}/restricted/${dir}/bash
chmod +x ${DISCOROOT}/restricted/${dir}/bash
done
fi
# We need SOME special files in /dev like /dev/null, so make them here
mknod ${DISCOROOT}/dev/dev/null c 1 3
chmod 666 ${DISCOROOT}/dev/dev/null
# Mount all the (real filesystem) layers individually
mount --bind -o ro / ${DISCOROOT}/rootfs 2>&1 | grep -v "seems to be mounted read-write"
mount -o remount,ro ${DISCOROOT}/rootfs
mount -t proc -o ro none ${DISCOROOT}/proc/proc
mount -t sysfs -o ro none ${DISCOROOT}/sysfs/sys
# Setup filesystem layers. The read/write ones go on the top, with scratchfs ALWAYS on top.
FSLAYERS="${DISCOROOT}/scratchfs=rw"
FSLAYERS="${FSLAYERS}:${DISCOROOT}/dev=rw"
FSLAYERS="${FSLAYERS}:${DISCOROOT}/restricted=ro"
FSLAYERS="${FSLAYERS}:${DISCOROOT}/execs=ro"
FSLAYERS="${FSLAYERS}:${DISCOROOT}/proc=ro"
FSLAYERS="${FSLAYERS}:${DISCOROOT}/sysfs=ro"
FSLAYERS="${FSLAYERS}:${DISCOROOT}/rootfs=ro"
# Here we go
unionfs -o cow,dev,dirs=$FSLAYERS ${DISCOROOT}/chroot
exit 0

24
client/bin/disco-fs-unmount Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
DISCOROOT=/var/disco/testfs
mount | grep $DISCOROOT > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "disco chroot is not mounted"
exit 1
fi
umount ${DISCOROOT}/chroot
umount ${DISCOROOT}/proc/proc
umount ${DISCOROOT}/sysfs/sys
umount ${DISCOROOT}/rootfs
mount | grep $DISCOROOT > /dev/null 2>&1
if [ $? -eq 0 ]; then
# Sometimes required
umount ${DISCOROOT}/rootfs
fi
rm -rf ${DISCOROOT}/scratchfs/* ${DISCOROOT}/scratchfs/.unionfs
rm -rf ${DISCOROOT}/dev/*
exit 0

19
client/bin/disco-sh-exec Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
DISCOROOT=/var/disco/testfs
mount | grep $DISCOROOT >/dev/null 2>&1
if [ $? -ne 0 ]; then
./disco-fs-mount
fi
# Strip out any shebang and put the script in the root
mkdir -p ${DISCOROOT}/execs/$(dirname $2)
cat $1 | sed s/'^#!.*'/''/g > ${DISCOROOT}/execs/$2
if [ "$NOOP" != "" ]; then
chroot ${DISCOROOT}/chroot /bin/bash --restricted $2
else
chroot ${DISCOROOT}/chroot /bin/bash $2
fi
./disco-fs-unmount
exit $?

15
client/bin/disco-sh-shell Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
DISCOROOT=/var/disco/testfs
mount | grep $DISCOROOT >/dev/null 2>&1
if [ $? -ne 0 ]; then
./disco-fs-mount
fi
if [ "$NOOP" != "" ]; then
chroot ${DISCOROOT}/chroot /bin/rbash
else
chroot ${DISCOROOT}/chroot /bin/bash
fi
./disco-fs-unmount
exit $?