#!/bin/bash if [ -z "$1" ]; then echo "Pass abolute path to where slx-tools will be located" exit 1 fi declare -rg BASE="$1" shopt -s globstar set -e DEFS= for file in modules/**/*.inc; do name="${file#modules/}" name="${name//\//_}" name="${name%.inc}" [[ "$name" =~ ^[a-z0-9_]+$ ]] || continue echo " * Handling $file" if ! bash -n "$file"; then echo "FILE CONTAINS ERRORS; ABORTING" rm -f -- slx-tools exit 1 fi for var in $( grep -oP '^[a-z0-9_]+\s*\(\)' "$file" | grep -oE '^[a-z0-9_]+' ); do echo "Found $var" DEFS+="$var() { . \$BASE/$file; $var "'"$@"; }\n' done done sed "s#%DEFS%#${DEFS}#;s#^BASE=.*\$#BASE='$BASE'#" slx-tools.template > slx-tools chmod +x slx-tools