mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
Removed legacy implementation of nuxfs.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
089cb5ccce
commit
4ffbe06990
2 changed files with 0 additions and 354 deletions
233
bin/nuxfs-old
233
bin/nuxfs-old
|
|
@ -1,233 +0,0 @@
|
||||||
#!/usr/bin/env nux-runner
|
|
||||||
|
|
||||||
### Filesystem Layout manager
|
|
||||||
###
|
|
||||||
local STARTDIR=$(pwd)
|
|
||||||
local TEMPLATE_DIR=$NUX_ENV_DIR/templates
|
|
||||||
local SUFFIX=".nuxfs"
|
|
||||||
local TEMPLATE_FILTER="*$SUFFIX"
|
|
||||||
|
|
||||||
nux.include nuxfs
|
|
||||||
nux.include nuxfs.dsl
|
|
||||||
|
|
||||||
GIT_BIN=$(which git)
|
|
||||||
|
|
||||||
## check - Verifies that directory matches nuxfs specification
|
|
||||||
function task.check {
|
|
||||||
link.exists() {
|
|
||||||
nux.log debug "Testing '$1' as link"
|
|
||||||
if test ! -h "$1"; then
|
|
||||||
nuxfs.error "$1" "is not symlink."
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
local REAL_LINK=$(readlink "$1")
|
|
||||||
local TARGET="$2";
|
|
||||||
if test ! "$REAL_LINK" = "$TARGET"; then
|
|
||||||
MAT_REAL=$(realpath "$REAL_LINK")
|
|
||||||
local cdir=$(dirname "$1")
|
|
||||||
MAT_TARGET=$(realpath "$cdir/$TARGET")
|
|
||||||
if test "$MAT_REAL" = "$MAT_TARGET"; then
|
|
||||||
nuxfs.warning "$1" "is using different definition for target '$2'"
|
|
||||||
else
|
|
||||||
nuxfs.error "$1" "links to $REAL_LINK instead of $TARGET"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
if test ! -e "$1"; then
|
|
||||||
nuxfs.warning "$1" "target '$NC_White$2$NC_No' does not exists."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
git.exists() {
|
|
||||||
nux.log debug "Testing '$1' as git repository"
|
|
||||||
if test ! -e "$1/.git"; then
|
|
||||||
nuxfs.error "$1" "is not git repository"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
local remotes=$(grep "$2" "$1/.git/config" | wc -l)
|
|
||||||
if [ $remotes -eq 0 ]; then
|
|
||||||
nuxfs.error "$1" "Does not refer git remote '$2'"
|
|
||||||
return;
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
def.notexists() {
|
|
||||||
nuxfs.error "$1" "does not exists".
|
|
||||||
}
|
|
||||||
nuxfs.initcfg "$@"
|
|
||||||
nuxfs.dsl.execute "$NUXFS_DEF" "$NUXFS_DEF_DIR" "$WORKDIR_ABSOLUTE"
|
|
||||||
}
|
|
||||||
|
|
||||||
## apply - Creates missing files as described in nuxfs definition.
|
|
||||||
function task.apply {
|
|
||||||
directory.notexists() {
|
|
||||||
nuxfs.info "$1" "Created directory";
|
|
||||||
mkdir -p "$1"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
link.notexists() {
|
|
||||||
nuxfs.info "$1" "Creating link to '$2'";
|
|
||||||
ln -s "$2" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
git.notexists() {
|
|
||||||
local cur_dir=$(nuxfs.dir.get);
|
|
||||||
local rel_path=$(realpath -Lms $1 --relative-to $cur_dir)
|
|
||||||
pushd $(nuxfs.dir.get) > /dev/null;
|
|
||||||
$GIT_BIN clone "$2" $rel_path
|
|
||||||
popd > /dev/null;
|
|
||||||
}
|
|
||||||
|
|
||||||
nuxfs.initcfg "$@"
|
|
||||||
nuxfs.dsl.execute "$NUXFS_DEF" "$NUXFS_DEF_DIR" "$WORKDIR_ABSOLUTE"
|
|
||||||
}
|
|
||||||
|
|
||||||
## 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 task.info {
|
|
||||||
nuxfs.initcfg;
|
|
||||||
if [ -n "$NUXFS_DEF" ]; then
|
|
||||||
MANAGED_RELATIVE=$(realpath $NUXFS_DEF_DIR --relative-to $(pwd));
|
|
||||||
|
|
||||||
if [ "$MANAGED_RELATIVE" = . ]; then
|
|
||||||
echo $(pwd) is nuxfs managed directory.
|
|
||||||
else
|
|
||||||
echo $(pwd) is child of nuxfs managed directory.
|
|
||||||
echo Managed directory is $NUXFS_DEF_DIR.
|
|
||||||
fi;
|
|
||||||
else
|
|
||||||
echo "$(pwd) is not managed by nuxfs";
|
|
||||||
|
|
||||||
fi;
|
|
||||||
}
|
|
||||||
|
|
||||||
function nuxfs.dsl.capture.dir {
|
|
||||||
local CDIR=$1;
|
|
||||||
local LEVEL=$2;
|
|
||||||
nux.log debug "Inspecting directory $CDIR";
|
|
||||||
|
|
||||||
if [ -e "$RELATIVE/$SUFFIX" ]; then
|
|
||||||
return;
|
|
||||||
fi;
|
|
||||||
|
|
||||||
pushd "$CDIR" > /dev/null;
|
|
||||||
for file in ./* ; do
|
|
||||||
nuxfs.dsl.capture.file "$file" ".";
|
|
||||||
done;
|
|
||||||
popd > /dev/null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function nuxfs.dsl.capture.file {
|
|
||||||
local file=$1;
|
|
||||||
local pdir=$2;
|
|
||||||
local RELATIVE=$(realpath -ms "$file" --relative-to "$pdir");
|
|
||||||
local ADDARGS="";
|
|
||||||
local TYPE="";
|
|
||||||
nux.log debug "Inspecting $file , Relative path is $RELATIVE";
|
|
||||||
if [ -h "$RELATIVE" ]; then
|
|
||||||
TYPE="link";
|
|
||||||
ADDARGS="\"$(readlink "$RELATIVE")\""
|
|
||||||
elif [ -d "$RELATIVE" -a -d "$RELATIVE/.git" ]; then
|
|
||||||
TYPE=git;
|
|
||||||
pushd "$RELATIVE" > /dev/null;
|
|
||||||
ADDARGS="\"$($GIT_BIN remote get-url origin)\""
|
|
||||||
popd > /dev/null;
|
|
||||||
elif [ -d "$RELATIVE" ]; then
|
|
||||||
TYPE="dir";
|
|
||||||
fi;
|
|
||||||
|
|
||||||
if [ "$TYPE" ]; then
|
|
||||||
echo -e "${LEVEL}$TYPE \"$RELATIVE\" $ADDARGS";
|
|
||||||
fi;
|
|
||||||
|
|
||||||
if [ "$TYPE" = "dir" -a "$LEVEL" != " " ]; then
|
|
||||||
nuxfs.dsl.capture.dir "$RELATIVE" "${LEVEL} "
|
|
||||||
echo "${LEVEL}enddir";
|
|
||||||
fi;
|
|
||||||
}
|
|
||||||
|
|
||||||
## capture - Captures current directory to nuxfs syntax
|
|
||||||
function task.capture {
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
nuxfs.dsl.capture.dir .
|
|
||||||
|
|
||||||
else
|
|
||||||
for file in "$@" ; do
|
|
||||||
nuxfs.dsl.capture.file "$file" .;
|
|
||||||
done;
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function nuxfs.initcfg {
|
|
||||||
|
|
||||||
WORKDIR=$1;
|
|
||||||
if [ -n "$WORKDIR" ]; then
|
|
||||||
WORKDIR=$WORKDIR
|
|
||||||
else
|
|
||||||
WORKDIR=$(pwd);
|
|
||||||
fi;
|
|
||||||
|
|
||||||
nux.log debug Target: $WORKDIR
|
|
||||||
|
|
||||||
NUXFS_DEF=$(nuxfs.closest $SUFFIX "$WORKDIR");
|
|
||||||
|
|
||||||
if [ "$NUXFS_DEF" = "" ]; then
|
|
||||||
nuxfs.error $(pwd) "No nuxfs configuration found."
|
|
||||||
return;
|
|
||||||
fi;
|
|
||||||
NUXFS_DEF_DIR=$(dirname $NUXFS_DEF);
|
|
||||||
WORKDIR_RELATIVE=$(realpath -ms "$WORKDIR" --relative-to "$NUXFS_DEF_DIR")
|
|
||||||
WORKDIR_ABSOLUTE=$(realpath -ms "$WORKDIR")
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,121 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
function exec.if.function {
|
|
||||||
FUNC_NAME=$1;
|
|
||||||
DEFAULT_NAME=$2;
|
|
||||||
shift; shift;
|
|
||||||
|
|
||||||
if nux.check.function $FUNC_NAME; then
|
|
||||||
nux.log trace Executing: $FUNC_NAME "$@";
|
|
||||||
$FUNC_NAME "$@";
|
|
||||||
return;
|
|
||||||
fi
|
|
||||||
if nux.check.function $DEFAULT_NAME; then
|
|
||||||
nux.log trace Executing: $FUNC_NAME "$@";
|
|
||||||
$DEFAULT_NAME "$@";
|
|
||||||
return;
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function nuxfs.dsl.command {
|
|
||||||
CMD=$1;
|
|
||||||
localFile=$(nuxfs.relative "$2");
|
|
||||||
|
|
||||||
|
|
||||||
shift; shift;
|
|
||||||
nux.log trace Processing $CMD "$localFile" $@;
|
|
||||||
|
|
||||||
exec.if.function $CMD.pre def.pre "$localFile" "$@";
|
|
||||||
|
|
||||||
if [[ "$NESTED_DIR" = "$localFile"* || "$localFile" = "$NESTED_DIR"* ]]; then
|
|
||||||
nux.log debug $localFile is affected by $NESTED_DIR;
|
|
||||||
|
|
||||||
if [[ "$NESTED_DIR" = "$localFile/" || "$localFile" = "$NESTED_DIR"* ]]; then
|
|
||||||
NUXFS_TARGET_FOUND=1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
if nuxfs.file.exists "$localFile"; then
|
|
||||||
nux.log debug "File $NC_White$localFile$NC_No exits";
|
|
||||||
exec.if.function $CMD.exists def.exists "$localFile" "$@";
|
|
||||||
else
|
|
||||||
nux.log debug "File $NC_White$localFile$NC_No does not exists";
|
|
||||||
exec.if.function $CMD.notexists def.notexists "$localFile" "$@";
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
exec.if.function $CMD.post def.post "$localFile" "$@";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function nuxfs.dsl.keywords {
|
|
||||||
origin() {
|
|
||||||
:
|
|
||||||
}
|
|
||||||
name() {
|
|
||||||
:
|
|
||||||
}
|
|
||||||
dir() {
|
|
||||||
nuxfs.dsl.command directory "$@";
|
|
||||||
}
|
|
||||||
sdir() {
|
|
||||||
dir "$@"
|
|
||||||
enddir
|
|
||||||
}
|
|
||||||
|
|
||||||
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.pre() {
|
|
||||||
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'"
|
|
||||||
nux.log trace "Trying to nest into directory"
|
|
||||||
if test -e "$1/.nuxfs"; then
|
|
||||||
nux.log debug "Invoking nested nuxfs definition."
|
|
||||||
source "$1/.nuxfs";
|
|
||||||
fi;
|
|
||||||
else
|
|
||||||
nuxfs.error "$1" "is not directory."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
enddirectory() {
|
|
||||||
nuxfs.dir.pop
|
|
||||||
}
|
|
||||||
enddir() {
|
|
||||||
nuxfs.dir.pop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function nuxfs.dsl.execute {
|
|
||||||
nuxfs.dsl.keywords
|
|
||||||
local DEF="$1";
|
|
||||||
local DIR="$2";
|
|
||||||
NESTED_DIR="$(realpath -s "$3")/";
|
|
||||||
nux.log debug "Working Directory: $DIR , Nested Directory: $NESTED_DIR"
|
|
||||||
declare -a DIR_ARRAY
|
|
||||||
DIR_ARRAY[0]=$DIR
|
|
||||||
if test -e "$DEF"; then
|
|
||||||
NUXFS_TARGET_FOUND=0;
|
|
||||||
source "$DEF";
|
|
||||||
if [ $NUXFS_TARGET_FOUND = 0 ]; then
|
|
||||||
nuxfs.warning "$3" "Does not have definition in $DEF";
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
nuxfs.error "$DEF" Definition file does not exists.
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue