1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00
nux-env/bin/nuxfs
Tony Tkacik 8aff47bd72 nuxfs: Added support for git directive.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2016-11-24 12:33:25 +01:00

69 lines
1.5 KiB
Text
Executable file

#!/usr/bin/env nux-runner
### Filesystem Layout manager
###
STARTDIR=$(pwd)
nux.include nuxfs
nux.include nuxfs.dsl
GIT_BIN=$(which git)
## verify - Verifies that directory matches nuxfs specification
function task.verify {
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
nuxfs.error "$1" "links to $REAL_LINK instead of $TARGET"
return
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.dsl.execute .nuxfs
}
## create - Creates missing files as described in nuxfs definition.
function task.create {
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.dsl.execute .nuxfs
}