Skip to content

Commit

Permalink
Improved configuration overriding and checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mapio committed Nov 27, 2020
1 parent 810260b commit 82baa7b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
12 changes: 10 additions & 2 deletions scythe/bin/scythe
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,22 @@ case "$command" in
upgrade|versions)
;;
edit|prepare)
if [ ! -r "$EXERCISES" ]; then
echo "scythe: exercises list '$EXERCISES' not readable!" >&2
if [ ! -d "$BASE_BUNDLE" ]; then
echo "scythe: base bundle dir '$BASE_BUNDLE' missing!" >&2
exit 1
fi
if [ ! -r "$CONFS_DIR/confs.py" ]; then
echo "scythe: base bundle configuration '$CONFS_DIR/confs.py' not readable!" >&2
exit 1
fi
if [ ! -r "$EXERCISES" ]; then
echo "scythe: exercises list '$EXERCISES' not readable!" >&2
exit 1
fi
if [ ! -r "$REGISTERED_UIDS" ]; then
echo "scythe: registered uids file '$REGISTERED_UIDS' not readable!" >&2
exit 1
fi
;;
auth|backup|logtail|push|start|status|stop|unsign)
if [ ! -r "$TM_SETTINGS" ]; then
Expand Down
45 changes: 35 additions & 10 deletions scythe/confs.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,59 @@
# current version

export SCYTHE_VERSION=1.3.2
export SCYTHE_VERSION=1.3.3

# tool dirs
# user confs

export CONFS_DIR="$(realpath -eL $SCYTHE_HOME/../confs)"
export EXERCISES_DIR="$(realpath -eL $SCYTHE_HOME/../exercises)"
export BACKUPS_DIR="$(realpath -eL $SCYTHE_HOME/../backups)"
if [ ! -r "$CONFS_DIR/confs.sh" ]; then
echo "scythe: missing user confs '$CONFS_DIR/confs.sh'" >&2
exit 1
fi

# defaults

# local dirs
export EXERCISES_DIR="$SCYTHE_HOME/../exercises"
export BACKUPS_DIR="$SCYTHE_HOME/../backups"

export BASE_BUNDLE="$CONFS_DIR/basebundle"
export EXERCISES="$CONFS_DIR/${SCYTHE_SESSION_ID}.txt"
export REGISTERED_UIDS="$CONFS_DIR/${SCYTHE_SESSION_ID}.tsv"

export TM_SETTINGS="$CONFS_DIR/${SCYTHE_SESSION_ID}-tm.py"
export ST_SETTINGS="$CONFS_DIR/${SCYTHE_SESSION_ID}-st.py"

export SCYTHE_BACKUPS="$BACKUPS_DIR/$SCYTHE_SESSION_ID"

# user confs (here so that can override any of the above)
# possibly ovverriden by user values

if [ ! -r "$CONFS_DIR/confs.sh" ]; then
echo "scythe: missing user confs '$CONFS_DIR/confs.sh'" >&2
exit 1
fi
source "$CONFS_DIR/confs.sh"

# fix missing SCYTHE_EDITOR

if [ -z "$SCYTHE_EDITOR" ]; then
export SCYTHE_EDITOR="$EDITOR"
fi

# make all path absolute

export EXERCISES_DIR="$(realpath -mL $EXERCISES_DIR)"
if [ ! -d "$EXERCISES_DIR" ]; then
echo "scythe: missing exercises dir '$EXERCISES_DIR'" >&2
exit 1
fi
export BACKUPS_DIR="$(realpath -mL $BACKUPS_DIR)"
if [ ! -d "$BACKUPS_DIR" ]; then
echo "scythe: missing backups dir '$BACKUPS_DIR'" >&2
exit 1
fi

export BASE_BUNDLE="$(realpath -mL $BASE_BUNDLE)"
export EXERCISES="$(realpath -mL $EXERCISES)"
export REGISTERED_UIDS="$(realpath -mL $REGISTERED_UIDS)"

export TM_SETTINGS="$(realpath -mL $TM_SETTINGS)"
export ST_SETTINGS="$(realpath -mL $ST_SETTINGS)"
export SCYTHE_BACKUPS="$(realpath -mL $SCYTHE_BACKUPS)"

# functions

Expand Down

0 comments on commit 82baa7b

Please sign in to comment.