Moved disco colorization into a function, can be used standalone with "client/bin/disco colorize" on stdin.

Fixed disco-fs-diff to only use rsync, sed, grep, etc to produce the filesystem changelog, python script is gone

Minor fixups to other scripts
This commit is contained in:
2012-08-17 19:24:25 -04:00
parent 7d6d94ae3d
commit 3cfffd192e
5 changed files with 57 additions and 36 deletions

View File

@@ -7,7 +7,15 @@ else
DISCOROOT=/var/disco/testfs/real DISCOROOT=/var/disco/testfs/real
fi fi
function main() { . ${DISCOCFG}/client.cfg
function colorize() {
sed s/"^info:\(.*\)"/"${COLOR_CYAN}info:\1${COLOR_NORMAL}"/g |\
sed s/"^warning: \(.*\)"/"${COLOR_YELLOW}warning: \1${COLOR_NORMAL}"/g |\
sed s/"^error: \(.*\)"/"${COLOR_RED}error: \1${COLOR_NORMAL}"/g
}
function dance() {
mount | grep $DISCOROOT >/dev/null 2>&1 mount | grep $DISCOROOT >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@@ -45,4 +53,4 @@ function main() {
done done
} }
main $@ $1 "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"

View File

@@ -11,32 +11,44 @@ fi
cd $DISCOROOT cd $DISCOROOT
diff -r ./rootfs ./scratchfs |\ rsync --checksum --times --perms --owner --group -ani ./scratchfs/ ./rootfs/ |\
grep -v "^Only in ./rootfs" |\ grep -v ".unionfs.*/$" |\
sed s/"^Only in \.\/scratchfs\(.*\): \(.*\)"/"info: File: created \1\/\2 : (CONTENT)"/g |\ sed s/"\.\/scratchfs"/""/ |\
sed s/"\/\/"/"\/"/g |\ sed s/"\.unionfs\/"/""/ |\
grep -v "File: created /.unionfs" |\ grep -v "./$" |\
sed s/"^Binary files .\/rootfs\(.*\) and .\/scratchfs.*"/"info: File: modified \1 : (OLDMD5SUM) => (NEWMD5SUM)"/g |\ sed s/"^[<>ch\.*]d"/"File: directory: "/ |\
sed s/"^diff -r .\/rootfs\(.*\) .\/scratchfs\(.*\)"/"info: File: modified \1 :"/g > /tmp/$$.discofsdiff sed s/"^[<>ch\.*]f"/"File: file: "/ |\
sed s/"^[<>ch\.*]L"/"File: symlink: "/ |\
sed s/"^[<>ch\.*]D"/"File: device: "/ |\
sed s/"^[<>ch\.*]S"/"File: special: "/ |\
sed s/": \([\.cstpoguax+]*\) \(.*\)$"/": \2 : \1"/ |\
sed s/"+++++++++$"/"Created"/ |\
sed s/" [\.cstpoguax]*$"/" Modified"/ |\
sed s/"_HIDDEN~ : Created"/" : Deleted"/ |\
sed s/"^\(.*\)\$"/"info: \1"/g |\
while read LINE
do
FNAME=$(echo $LINE | cut -d : -f 4 | sed s/"^ *"/""/ | sed s/" *$"/""/)
MD5_NEW=$(md5sum ${DISCOROOT}/scratchfs/${FNAME} 2>/dev/null| cut -d " " -f 1)
MD5_OLD=$(md5sum /${FNAME} 2>/dev/null| cut -d " " -f 1)
PERMS_NEW=$(stat --format "%G:%U %a" ${DISCOROOT}/scratchfs/${FNAME} 2>/dev/null)
PERMS_OLD=$(stat --format "%G:%U %a" /${FNAME} 2>/dev/null)
if [ ! -d /${FNAME} ] && [ ! -d ${DISCOROOT}/scratchfs/${FNAME} ]; then
DIFF=$(echo; diff /${FNAME} ${DISCOROOT}/scratchfs/${FNAME} 2>/dev/null > /tmp/$$.diff )
fi
file ${DISCOROOT}/scratchfs/${FNAME} 2>&1 | grep ASCII >/dev/null 2>&1
if [ $? -eq 0 ]; then
CONTENT=$(echo "Text"; cat ${DISCOROOT}/scratchfs/${FNAME} | sed s/"^"/"> "/g > /tmp/$$.content)
fi
echo $LINE |\
sed -e s/"Created$"/"Created : md5=[${MD5_NEW}] perms=[${PERMS_NEW}]"/ |\
sed -e s/"Modified$"/"Modified : md5=[${MD5_OLD} => ${MD5_NEW}] perms=[${PERMS_OLD} => ${PERMS_NEW}]"/
if [ -f /tmp/$$.diff ]; then
cat /tmp/$$.diff
elif [ -f /tmp/$$.content ]; then
cat /tmp/$$.content
fi
rm -f /tmp/$$.content /tmp/$$.diff 2>/dev/null
done
find ./scratchfs/.unionfs -iname "*_HIDDEN~" |\ rm -f /tmp/$$*
sed s/"^.\/scratchfs\/.unionfs\(.*\)_HIDDEN~"/"info: File: deleted \1"/g >> /tmp/$$.discofsdiff
# Find the permissions/timestamp diffs from rsync
# FIXME: This should be the root of all diffs, not tacked on at the end.
rsync -ani ./scratchfs/* ./rootfs/ |\
grep -v "_HIDDEN~\$" |\
grep -v .unionfs |\
sed s/"\.\/scratchfs"/""/g |\
sed s/"^\(.*\)\$"/"info: \1"/g
# Swap out the (CONTENT) and (MD5SUM) hashes for actual content and md5s
# FIXME: Stop calling a python script for this.
cat /tmp/$$.discofsdiff | NOOP=$NOOP python ${SCRIPTROOT}/disco-fs-fixup.py > /tmp/$$.newfile
mv /tmp/$$.newfile /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 |\
sed s/"^error: \(.*\)"/"${COLOR_RED}error: \1${COLOR_RED}"/g

View File

@@ -46,7 +46,7 @@ if [ "$NOOP" != "" ]; then
echo "export PATH=${DISCOROOT}/restricted/bin:${DISCOROOT}/munge/mungebin" >> ${DISCOROOT}/munge/etc/bashrc echo "export PATH=${DISCOROOT}/restricted/bin:${DISCOROOT}/munge/mungebin" >> ${DISCOROOT}/munge/etc/bashrc
# Make default wrapper # Make default wrapper
echo -e "#!/bin/bash\necho \"info: Would execute : \$(basename \$0) \$@\"" > ${DISCOROOT}/restricted/bin/_disco_restricted_cmd echo -e "#!/bin/bash\necho \"warning: Would execute : \$(basename \$0) \$@\"" > ${DISCOROOT}/restricted/bin/_disco_restricted_cmd
chmod +x ${DISCOROOT}/restricted/bin/_disco_restricted_cmd chmod +x ${DISCOROOT}/restricted/bin/_disco_restricted_cmd
# Now link everything to the default wrapper # Now link everything to the default wrapper

View File

@@ -40,7 +40,8 @@ function fetch() {
echo ${RSYNC} ${SERVERURI}::${1}/files/* / > /tmp/$$.sh echo ${RSYNC} ${SERVERURI}::${1}/files/* / > /tmp/$$.sh
echo ${RSYNC} --delete ${SERVERURI}::${1}/requires ${SERVERURI}::${1}/scripts ${SERVERURI}::${1}/parameters ${SERVERURI}::${1}/templates ${STORAGE}/${1} >> /tmp/$$.sh echo ${RSYNC} --delete ${SERVERURI}::${1}/requires ${SERVERURI}::${1}/scripts ${SERVERURI}::${1}/parameters ${SERVERURI}::${1}/templates ${STORAGE}/${1} >> /tmp/$$.sh
echo 'exit $?' >> /tmp/$$.sh echo 'exit $?' >> /tmp/$$.sh
/bin/bash /tmp/$$.sh /bin/bash /tmp/$$.sh 2>/tmp/$$.errors | sed s/"^"/"info: ${1}: "/g
cat /tmp/$$.errors | grep -v "some files/attrs were not transferred" | sed s/"^"/"error: ${1}: "/g
RETVAL=$? RETVAL=$?
rm -f /tmp/$$.sh rm -f /tmp/$$.sh
exit $RETVAL exit $RETVAL
@@ -71,7 +72,7 @@ function template() {
fi fi
DESTROOT="" DESTROOT=""
if [ "$NOOP" != "" ]; then if [ "$NOOP" != "" ]; then
DESTROOT=/var/disco/testfs/noop DESTROOT=/var/disco/testfs/noop/scratchfs
fi fi
cd ${STORAGE}/${1}/templates cd ${STORAGE}/${1}/templates
for file in $(find . -type f | sed s/"^\.\/"//g) for file in $(find . -type f | sed s/"^\.\/"//g)

View File

@@ -3,9 +3,9 @@
PARAMROOT=/var/disco/parameters PARAMROOT=/var/disco/parameters
function check_names_regex() { function check_names_regex() {
echo "$1" | grep -E '^[a-zA-Z0-9_-\./]*$' >/dev/null 2>&1 echo $1 | grep -E '^[a-zA-Z0-9_\-\.\/]*$' >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "error: Invalid characters in pathname '$1'. Valid pathname characters are [a-zA-Z0-9_-\.\/]*." >&2 echo "error: Invalid characters in pathname '$1'. Valid pathname characters are [a-zA-Z0-9_-.\/]*." >&2
exit 1 exit 1
fi fi
echo "$1" | grep "^/" >/dev/null 2>&1 echo "$1" | grep "^/" >/dev/null 2>&1