Moved disco-ball to universe, added functions necessary for fetching, templating, and executing a given disco ball. Made all existing scripts aware of NOOP and how to change their DISCOROOT accordingly. Added skeleton restricted.d/* files for a semi-safe base system. Added disco-param that allows management of parameters on the client (currently isn't smart enough to manage them on the server, or per-module). Added client/bin/disco that actually allows the entire thing to come together and get executed. Still lots of bugs to work out.

This commit is contained in:
2012-08-08 05:30:03 -04:00
parent f51124252e
commit 7d6d94ae3d
10 changed files with 433 additions and 41 deletions

91
universe/bin/disco-ball Executable file
View File

@@ -0,0 +1,91 @@
#!/bin/bash
DISCOROOT=/var/disco
RSYNC=$(disco-param get disco/client/cmds/rsync || exit 1)
SERVERURI=$(disco-param get disco/server/uri || exit 1)
STORAGE=$(disco-param get disco/client/storage 2>/dev/null || echo "/var/disco/localstore")
mkdir -p ${STORAGE}
function init() {
if [ "$1" == "" ]; then
echo "Must enter a path to initialize" >&2
exit 1
fi
mkdir -p $1/templates
mkdir -p $1/scripts
mkdir -p $1/files
touch $1/requires
mkdir -p $1/parameters/$(basename $1)
}
function fetch_params() {
# Sometimes there's some shell escaping voodoo and rsync doesn't like the command args some people will pass it straight on
# the command line; so we wrap it in a little bash script, and everyone's happy.
echo ${RSYNC} --delete ${SERVERURI}::parameters/$(hostname)/* ${DISCOROOT}/parameters/$(hostname)/ > /tmp/$$.sh
echo 'exit $?' >> /tmp/$$.sh
/bin/bash /tmp/$$.sh
RETVAL=$?
rm -f /tmp/$$.sh
exit $RETVAL
}
function fetch() {
if [ "$1" == "" ]; then
echo "Must pass a module name to fetch"
exit 1
fi
rm -rf ${STORAGE}/${1}
# Sometimes there's some shell escaping voodoo and rsync doesn't like the command args some people will pass it straight on
# the command line; so we wrap it in a little bash script, and everyone's happy.
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 'exit $?' >> /tmp/$$.sh
/bin/bash /tmp/$$.sh
RETVAL=$?
rm -f /tmp/$$.sh
exit $RETVAL
}
function requires()
{
if [ "$1" == "" ]; then
echo "Must pass a module name for requirements"
exit 1
fi
cat ${STORAGE}/${1}/requires | sed s/"^"/"${1} "/g
}
function exec() {
RETVAL=0
for file in $(find ${STORAGE}/${1}/scripts/ -type f | sort -u)
do
NOOP="$NOOP" disco-sh-exec $file /tmp/${1}-$(basename $file)
RETVAL=$(expr $RETVAL + $?)
done
}
function template() {
if [ "$1" == "" ]; then
echo "Must pass a module name to template"
exit 1
fi
DESTROOT=""
if [ "$NOOP" != "" ]; then
DESTROOT=/var/disco/testfs/noop
fi
cd ${STORAGE}/${1}/templates
for file in $(find . -type f | sed s/"^\.\/"//g)
do
NOOP=true disco-sh-exec $(pwd)/$file /$file >/tmp/$$.tmpl
if [ $? -eq 0 ]; then
mkdir -p $(dirname ${DESTROOT}/$file)
mv /tmp/$$.tmpl ${DESTROOT}/$file
else
echo "error: template ${1}/templates/$file failed, not replacing /$file"
exit 1
fi
done
exit 0
}
$1 $2

View File

@@ -40,8 +40,27 @@ function disco_delete() {
function disco_set() {
if [ "$1" == "--help" ]; then
echo "info: disco-param set [PATH_NAME] [optarg] ... reads from stdin and sets PATH_NAME, unless [optarg] is {}, in which case a new hierarchy is made" >&2
echo "info: disco-param set - .... Reads lines from stdin, with each line being PATH_NAME=VALUE, and performs 'set' for each pair." >&2
exit 1
fi
if [ "$1" == "-" ]; then
RETVAL=0
while read LINE
do
PATHNAME=$(echo $LINE | cut -d = -f 1)
VALUE=$(echo $LINE | cut -d = -f 2-| sed s/"^\s*"//g)
echo $PATHNAME = $VALUE
if [ "$VALUE" == "{}" ]; then
disco_set $PATHNAME "{}"
else
echo $VALUE | disco_set $PATHNAME
fi
RETVAL=$(expr $RETVAL + $?)
done
exit $RETVAL
fi
check_names_regex "$1" || exit 1
mkdir -p $(dirname ${PARAMROOT}/${1})
if [ "$2" == "" ]; then
@@ -58,41 +77,63 @@ function disco_set() {
fi
}
function disco_get() {
function disco_keys() {
if [ "$1" == "--help" ]; then
echo "info: disco-param get [PATH_NAME]" >&2
echo "info: disco-param keys [PATH_NAME] ... returns a list of all keys present in the toplevel of the given directory" >&2
exit 1
fi
VARPATH=$(echo $1 | sed s/"^\/*"//g)
check_names_regex "$VARPATH" || exit 1
if [ -d ${PARAMROOT}/${VARPATH} ]; then
if [ "$RECURSING" == "" ]; then
echo "${VARPATH} = {}"
else
echo '{}'
fi
# Iterate over the path like a key/value dictionary
cd ${PARAMROOT}/${VARPATH}
for file in $(ls 2>/dev/null);
do
echo "${VARPATH}/${file} = $(RECURSING='true' disco_get ${VARPATH}/${file})" | sed s/"^\/*"//g
echo $file
done
exit 0
elif [ -e ${PARAMROOT}/${VARPATH} ]; then
cat ${PARAMROOT}/${VARPATH}
exit 0
else
echo "error: ${VARPATH} is undefined."
echo "error: $VARPATH does not exist or is not a directory" >&2
exit 1
fi
}
function disco_dump() {
if [ "$1" == "--help" ]; then
echo "info: disco-param dump [PATH_NAME] ... Print each key/value pair in the tree in PATH_NAME = VALUE format, one per line." >&2
exit 1
fi
VARPATH=$(echo $1 | sed s/"^\/*"//g)
check_names_regex "$VARPATH" || exit 1
cd $PARAMROOT
find $VARPATH | sed s/"^\.\/*"//g | grep -v "^$" | while read line; do if [ -d $line ]; then echo $line = '{}' ; else echo $line = $(cat $line); fi; done | sort -u
exit 0
}
function disco_get() {
if [ "$1" == "--help" ]; then
echo "info: disco-param get [PATH_NAME] ... Get the value of the given path name." >&2
exit 1
fi
VARPATH=$(echo $1 | sed s/"^\/*"//g)
check_names_regex "$VARPATH" || exit 1
cd $PARAMROOT
if [ -d ${PARAMROOT}/${VARPATH} ]; then
echo '{}'
else
cat ${PARAMROOT}/${VARPATH}
fi
exit $?
}
if [ "$1" == "--help" ]; then
echo "info: disco-param [CMD] [OPTIONS] ... execute the given command with the given options, and return zero on success."
echo
$0 set --help
$0 get --help
$0 dump --help
$0 delete --help
$0 keys --help
exit 0
fi