#!/bin/bash # evapporate.sh v0.0.1 # # This is the frontend for setting up new evapporate projects, # generating db code, and loading templates. ## BASE="%%PREFIX%%/share/evapporate" progname="$0" command="$1" shift args=("$@") function create() { # Copies skel into place target="$1" if [[ -z "$target" ]]; then echo "Specify the directory to place the skeleton application in." exit 1 fi cp -a $BASE/skel/ $target } function generate() { rm -rf evapporate.build if [[ ! -r schema/schema.rpc ]]; then echo "schema/schema.rpc was not found!" exit 1 fi rpcgen="$BASE/scripts/event_rpcgen.py" dbgen="$BASE/scripts/event_dbgen.sh" if [[ ! -x "$rpcgen" || ! -x "$dbgen" ]]; then echo "Could not find evapporate scripts" exit 1 fi mkdir evapporate.build pushd evapporate.build &> /dev/null cp ../schema/schema.rpc . "$rpcgen" schema.rpc >> generate.log "$dbgen" schema.gen.h schema.rpc >> generate.log popd &> /dev/null # TODO: add targets to make automatically? } function load() { # Loads all templates from ./templates into the database DIR="$PWD/templates" if [[ ! -d "$DIR" ]]; then echo "template directory not found: $DIR" exit 1 fi db="$1" if [[ ! -d "$db" ]]; then echo "Database home ($db) is not a directory" exit 1 fi boiler="$BASE/bin/boiler" if [[ ! -x "$boiler" ]]; then echo "Could not find boiler binary!" exit 1 fi # All templates should end in .cs files=$(find $DIR -type f -name '*.cs') # XXX: Add delete support for f in $files; do uri=$(echo $f | sed "s:$DIR::g" |sed 's/\.cs$//g') "$boiler" $db $uri $f echo "--> [$db] $uri --> $f" done } case $command in "create") create "${args[@]}" ;; "generate") # Generates database code from schema/schema.rpc generate "${args[@]}" ;; "load") load "${args[@]}" ;; *) echo -ne "Usage:\n${progname} command [args]\n" echo -ne "\nCommands:\n" echo -ne " create - creates a skeleton application\n" echo -ne " generate - generates the database code\n" echo -ne " for schema/schema.rpc\n" echo -ne " load [database] - loads the templates in the database\n" echo echo exit 1 ;; esac