mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
Splitted nuxfs into components.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
6e5c5986c3
commit
531f55f249
3 changed files with 143 additions and 152 deletions
165
bin/nuxfs
165
bin/nuxfs
|
|
@ -3,190 +3,51 @@
|
||||||
### Filesystem Layout manager
|
### Filesystem Layout manager
|
||||||
###
|
###
|
||||||
STARTDIR=$(pwd)
|
STARTDIR=$(pwd)
|
||||||
function error {
|
|
||||||
echo -e "${NC_Error}$* ${NC_No}";
|
|
||||||
}
|
|
||||||
|
|
||||||
function warning {
|
nux.include nuxfs
|
||||||
echo -e "${NC_Warning}$* ${NC_No}";
|
nux.include nuxfs.dsl
|
||||||
}
|
|
||||||
|
|
||||||
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: $*;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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
|
## verify - Verifies that directory matches nuxfs specification
|
||||||
function task.verify {
|
function task.verify {
|
||||||
link-exists() {
|
link-exists() {
|
||||||
log.debug "Testing '$1' as link"
|
nux.log debug "Testing '$1' as link"
|
||||||
if test ! -h "$1"; then
|
if test ! -h "$1"; then
|
||||||
fs.error "$1" "is not symlink."
|
nuxfs.error "$1" "is not symlink."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local REAL_LINK=$(readlink "$1")
|
local REAL_LINK=$(readlink "$1")
|
||||||
local TARGET="$2";
|
local TARGET="$2";
|
||||||
if test ! "$REAL_LINK" = "$TARGET"; then
|
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
|
return
|
||||||
fi
|
fi
|
||||||
if test ! -e "$1"; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
def-notexists() {
|
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 {
|
function task.create {
|
||||||
directory-notexists() {
|
directory-notexists() {
|
||||||
fs.info "$1" "Created directory";
|
nuxfs.info "$1" "Created directory";
|
||||||
mkdir -p "$1"
|
mkdir -p "$1"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
link-notexists() {
|
link-notexists() {
|
||||||
fs.info "$1" "Creating link to '$2'";
|
nuxfs.info "$1" "Creating link to '$2'";
|
||||||
ln -s "$2" "$1"
|
ln -s "$2" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
git-notexists() {
|
git-notexists() {
|
||||||
log.warning "Not implemented";
|
log.warning "Not implemented";
|
||||||
}
|
}
|
||||||
|
|
||||||
dsl.execute .nuxfs
|
nuxfs.dsl.execute .nuxfs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
93
inc/nuxfs.dsl.inc.sh
Normal file
93
inc/nuxfs.dsl.inc.sh
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
37
inc/nuxfs.inc.sh
Normal file
37
inc/nuxfs.inc.sh
Normal file
|
|
@ -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";
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue