From 531f55f249e1c387c9be9fb15880eac9ab029156 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Fri, 11 Nov 2016 19:55:34 +0100 Subject: [PATCH] Splitted nuxfs into components. Signed-off-by: Tony Tkacik --- bin/nuxfs | 165 ++++--------------------------------------- inc/nuxfs.dsl.inc.sh | 93 ++++++++++++++++++++++++ inc/nuxfs.inc.sh | 37 ++++++++++ 3 files changed, 143 insertions(+), 152 deletions(-) create mode 100644 inc/nuxfs.dsl.inc.sh create mode 100644 inc/nuxfs.inc.sh diff --git a/bin/nuxfs b/bin/nuxfs index 254d3fd..13b9f0f 100755 --- a/bin/nuxfs +++ b/bin/nuxfs @@ -3,190 +3,51 @@ ### Filesystem Layout manager ### STARTDIR=$(pwd) -function error { - echo -e "${NC_Error}$* ${NC_No}"; -} -function warning { - echo -e "${NC_Warning}$* ${NC_No}"; -} - -function fs.relative { - echo "$(dir.get)/$1" - #realpath -Lms "$(pwd)/$1" --relative-to "$STARTDIR" -} - -function fs.error { - local filename=$1; shift; - error "$filename"$NC_No: $*; -} - -function fs.warning { - local filename=$1; shift; - warning "$filename"$NC_No: $*; -} +nux.include nuxfs +nux.include nuxfs.dsl -function fs.info { - local filename=$1; shift; - echo -e $NC_White"$filename"$NC_No: $*; -} - - -function dir.get { - echo ${DIR_ARRAY[${#DIR_ARRAY[@]}-1]} -} - -function dir.pop { - unset DIR_ARRAY[${#DIR_ARRAY[@]}-1] -} - -function dir.push { - value="$1" - DIR_ARRAY[${#DIR_ARRAY[@]}]="$value" -} - -ROOT_DIR=$(pwd); -declare -a DIR_ARRAY -DIR_ARRAY[0]=. -function exec.if.function { - FUNC_NAME=$1; - DEFAULT_NAME=$2; - shift; shift; - - if is_function $FUNC_NAME; then - log.debug Executing: $FUNC_NAME "$@"; - $FUNC_NAME "$@"; - return; - fi - if is_function $DEFAULT_NAME; then - log.debug Executing: $FUNC_NAME "$@"; - $DEFAULT_NAME "$@"; - return; - fi - - -} - -function dsl.fs.command { - CMD=$1; - localFile=$(fs.relative "$2"); - shift; shift; - - log.debug Processing $CMD "$localFile" $@; - - exec.if.function $CMD-pre "$localFile" "$@"; - - log.debug Working file: $NC_White$localFile; - if dsl.file.exists "$localFile"; then - log.debug "File $localFile exits"; - exec.if.function $CMD-exists def-exists "$localFile" "$@"; - else - log.debug "File $localFile does not exists"; - exec.if.function $CMD-notexists def-notexists "$localFile" "$@"; - fi - exec.if.function $CMD-post def-post "$localFile" "$@"; -} - -dsl.file.exists() { - test -e "$1" -o -h "$1"; -} - -directory-verify() { - test -d "$1"; -} - -function origin { - : -} - - -dsl.execute() { - dir() { - dsl.fs.command directory "$@"; - } - - directory() { - dsl.fs.command directory "$@"; - } - - link() { - dsl.fs.command link "$@"; - #log.debug ln -s "$ORIGIN/$1" "$VFS/$2" ; - } - - git() { - dsl.fs.command git "$@"; - #echo git clone $1 $2; - } - - directory-post() { - dir.push "$1" - log.debug "Adding to dir stack: $1" - } - - directory-exists() { - if test -d "$1"; then - log.debug "Directory exists '$1'" - else - fs.error "$1" "is not directory." - fi - } - enddirectory() { - dir.pop - } - enddir() { - dir.pop - } - if test -f "$1"; then - source $1; - else - error "$1": Definition file does not exists. - fi -} ## verify - Verifies that directory matches nuxfs specification function task.verify { link-exists() { - log.debug "Testing '$1' as link" + nux.log debug "Testing '$1' as link" if test ! -h "$1"; then - fs.error "$1" "is not symlink." + nuxfs.error "$1" "is not symlink." return fi local REAL_LINK=$(readlink "$1") local TARGET="$2"; if test ! "$REAL_LINK" = "$TARGET"; then - fs.error "$1" "links to $REAL_LINK instead of $TARGET" + nuxfs.error "$1" "links to $REAL_LINK instead of $TARGET" return fi if test ! -e "$1"; then - fs.warning "$1" target does not exists. + nuxfs.warning "$1" "target '$NC_White$2$NC_No' does not exists." fi } def-notexists() { - fs.error "$1" "does not exists". + nuxfs.error "$1" "does not exists". } - dsl.execute .nuxfs + nuxfs.dsl.execute .nuxfs } - +## create - Creates missing files as described in nuxfs definition. function task.create { directory-notexists() { - fs.info "$1" "Created directory"; + nuxfs.info "$1" "Created directory"; mkdir -p "$1" } link-notexists() { - fs.info "$1" "Creating link to '$2'"; + nuxfs.info "$1" "Creating link to '$2'"; ln -s "$2" "$1" } git-notexists() { log.warning "Not implemented"; } - - dsl.execute .nuxfs + + nuxfs.dsl.execute .nuxfs } - - - diff --git a/inc/nuxfs.dsl.inc.sh b/inc/nuxfs.dsl.inc.sh new file mode 100644 index 0000000..90433ab --- /dev/null +++ b/inc/nuxfs.dsl.inc.sh @@ -0,0 +1,93 @@ + + +function exec.if.function { + FUNC_NAME=$1; + DEFAULT_NAME=$2; + shift; shift; + + if is_function $FUNC_NAME; then + nux.log debug Executing: $FUNC_NAME "$@"; + $FUNC_NAME "$@"; + return; + fi + if is_function $DEFAULT_NAME; then + nux.log debug Executing: $FUNC_NAME "$@"; + $DEFAULT_NAME "$@"; + return; + fi + +} + +function nuxfs.dsl.command { + CMD=$1; + localFile=$(nuxfs.relative "$2"); + shift; shift; + + nux.log debug Processing $CMD "$localFile" $@; + + exec.if.function $CMD-pre "$localFile" "$@"; + + nux.log debug Working file: $NC_White$localFile; + if nuxfs.file.exists "$localFile"; then + nux.log debug "File $localFile exits"; + exec.if.function $CMD-exists def-exists "$localFile" "$@"; + else + nux.log debug "File $localFile does not exists"; + exec.if.function $CMD-notexists def-notexists "$localFile" "$@"; + fi + exec.if.function $CMD-post def-post "$localFile" "$@"; +} + + +function nuxfs.dsl.keywords { + origin() { + : + } + dir() { + nuxfs.dsl.command directory "$@"; + } + + directory() { + nuxfs.dsl.command directory "$@"; + } + + link() { + nuxfs.dsl.command link "$@"; + #nux.log debug ln -s "$ORIGIN/$1" "$VFS/$2" ; + } + + git() { + nuxfs.dsl.command git "$@"; + #echo git clone $1 $2; + } + + directory-post() { + nuxfs.dir.push "$1" + nux.log debug "Adding to dir stack: $1" + } + + directory-exists() { + if test -d "$1"; then + nux.log debug "Directory exists '$1'" + else + nuxfs.error "$1" "is not directory." + fi + } + enddirectory() { + nuxfs.dir.pop + } + enddir() { + nuxfs.dir.pop + } +} + +function nuxfs.dsl.execute { + nuxfs.dsl.keywords + declare -a DIR_ARRAY + DIR_ARRAY[0]=. + if test -f "$1"; then + source $1; + else + error "$1": Definition file does not exists. + fi +} diff --git a/inc/nuxfs.inc.sh b/inc/nuxfs.inc.sh new file mode 100644 index 0000000..02f5abf --- /dev/null +++ b/inc/nuxfs.inc.sh @@ -0,0 +1,37 @@ + + +function nuxfs.relative { + echo "$(nuxfs.dir.get)/$1" +} + +function nuxfs.error { + local filename=$1; shift; + nux.echo.error "$filename"$NC_No: $*; +} + +function nuxfs.warning { + local filename=$1; shift; + nux.echo.warning "$filename"$NC_No: $*; +} + +function nuxfs.info { + local filename=$1; shift; + echo -e $NC_White"$filename"$NC_No: $*; +} + +function nuxfs.dir.get { + echo ${DIR_ARRAY[${#DIR_ARRAY[@]}-1]} +} + +function nuxfs.dir.pop { + unset DIR_ARRAY[${#DIR_ARRAY[@]}-1] +} + +function nuxfs.dir.push { + local value="$1" + DIR_ARRAY[${#DIR_ARRAY[@]}]="$value" +} + +function nuxfs.file.exists { + test -e "$1" -o -h "$1"; +}