mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nuxfs: added init and templates support.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
1737416a72
commit
e4ae60fdb0
2 changed files with 65 additions and 6 deletions
59
bin/nuxfs
59
bin/nuxfs
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
### Filesystem Layout manager
|
### Filesystem Layout manager
|
||||||
###
|
###
|
||||||
STARTDIR=$(pwd)
|
local STARTDIR=$(pwd)
|
||||||
|
local TEMPLATE_DIR=$NUX_ENV_DIR/templates
|
||||||
|
local SUFFIX=".nuxfs"
|
||||||
|
local TEMPLATE_FILTER="*$SUFFIX"
|
||||||
|
|
||||||
nux.include nuxfs
|
nux.include nuxfs
|
||||||
nux.include nuxfs.dsl
|
nux.include nuxfs.dsl
|
||||||
|
|
@ -65,5 +68,57 @@ function task.create {
|
||||||
popd > /dev/null;
|
popd > /dev/null;
|
||||||
}
|
}
|
||||||
|
|
||||||
nuxfs.dsl.execute .nuxfs
|
nuxfs.dsl.execute $SUFFIX
|
||||||
|
}
|
||||||
|
|
||||||
|
## init - Initializes a directory using template
|
||||||
|
function task.init {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
nux.log debug "No template specified. Creating empty $SUFFIX definition."
|
||||||
|
touch .nuxfs
|
||||||
|
return;
|
||||||
|
fi
|
||||||
|
local TEMPLATE=$1
|
||||||
|
nux.log debug "User specified template is " $TEMPLATE
|
||||||
|
if [ $(echo $TEMPLATE | grep -c "$SUFFIX\$") -eq 0 ]; then
|
||||||
|
nux.log debug "Template is common template."
|
||||||
|
TEMPLATE=$TEMPLATE_DIR/$TEMPLATE$SUFFIX
|
||||||
|
if [ ! -e $TEMPLATE ]; then
|
||||||
|
echo -n "Template '$1' does not exists. "
|
||||||
|
nuxfs.template.list
|
||||||
|
return;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
fi;
|
||||||
|
nux.log debug "Using '$TEMPLATE' to initialize."
|
||||||
|
if [ ! -e $TEMPLATE ]; then
|
||||||
|
echo "nuxfs template $1 does not exists."
|
||||||
|
return;
|
||||||
|
fi;
|
||||||
|
local template_relative=$(realpath -Lms $TEMPLATE --relative-to $(pwd))
|
||||||
|
nux.log debug "Creating link $SUFFIX: target is '$template_relative'";
|
||||||
|
ln -s "$template_relative" "$SUFFIX"
|
||||||
|
nux.log debug "Invoking create task."
|
||||||
|
task.create
|
||||||
|
}
|
||||||
|
|
||||||
|
##
|
||||||
|
## template - List available templates
|
||||||
|
#
|
||||||
|
function task.template {
|
||||||
|
nux.log debug $NUX_ENV_DIR
|
||||||
|
|
||||||
|
nuxfs.template.list
|
||||||
|
}
|
||||||
|
|
||||||
|
function nuxfs.template.list {
|
||||||
|
echo "Available templates:";
|
||||||
|
pushd $TEMPLATE_DIR > /dev/null;
|
||||||
|
for i in $TEMPLATE_FILTER; do
|
||||||
|
local TEMPLATE_ID=$(basename $i $SUFFIX)
|
||||||
|
echo -n " $TEMPLATE_ID - " ;
|
||||||
|
grep -m1 "^name " $i | sed -e "s/name *//"
|
||||||
|
echo
|
||||||
|
done;
|
||||||
|
popd > /dev/null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ function exec.if.function {
|
||||||
shift; shift;
|
shift; shift;
|
||||||
|
|
||||||
if nux.check.function $FUNC_NAME; then
|
if nux.check.function $FUNC_NAME; then
|
||||||
nux.log debug Executing: $FUNC_NAME "$@";
|
nux.log trace Executing: $FUNC_NAME "$@";
|
||||||
$FUNC_NAME "$@";
|
$FUNC_NAME "$@";
|
||||||
return;
|
return;
|
||||||
fi
|
fi
|
||||||
if nux.check.function $DEFAULT_NAME; then
|
if nux.check.function $DEFAULT_NAME; then
|
||||||
nux.log debug Executing: $FUNC_NAME "$@";
|
nux.log trace Executing: $FUNC_NAME "$@";
|
||||||
$DEFAULT_NAME "$@";
|
$DEFAULT_NAME "$@";
|
||||||
return;
|
return;
|
||||||
fi
|
fi
|
||||||
|
|
@ -43,6 +43,9 @@ function nuxfs.dsl.keywords {
|
||||||
origin() {
|
origin() {
|
||||||
:
|
:
|
||||||
}
|
}
|
||||||
|
name() {
|
||||||
|
:
|
||||||
|
}
|
||||||
dir() {
|
dir() {
|
||||||
nuxfs.dsl.command directory "$@";
|
nuxfs.dsl.command directory "$@";
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +74,7 @@ function nuxfs.dsl.keywords {
|
||||||
nux.log debug "Directory exists '$1'"
|
nux.log debug "Directory exists '$1'"
|
||||||
nux.log trace "Trying to nest into directory"
|
nux.log trace "Trying to nest into directory"
|
||||||
if test -e "$1/.nuxfs"; then
|
if test -e "$1/.nuxfs"; then
|
||||||
|
nux.log debug "Invoking nested nuxfs definition."
|
||||||
source "$1/.nuxfs";
|
source "$1/.nuxfs";
|
||||||
fi;
|
fi;
|
||||||
else
|
else
|
||||||
|
|
@ -89,9 +93,9 @@ function nuxfs.dsl.execute {
|
||||||
nuxfs.dsl.keywords
|
nuxfs.dsl.keywords
|
||||||
declare -a DIR_ARRAY
|
declare -a DIR_ARRAY
|
||||||
DIR_ARRAY[0]=.
|
DIR_ARRAY[0]=.
|
||||||
if test -f "$1"; then
|
if test -e "$1"; then
|
||||||
source $1;
|
source $1;
|
||||||
else
|
else
|
||||||
error "$1": Definition file does not exists.
|
nuxfs.error "$1" Definition file does not exists.
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue