#!/bin/bash

[ -r ../env ] && . ../env
[ -r env ] && . ./env

[ -z "$INSTALL_FILE" ] && echo "Check env values && exit 1
[ -z "$INSTALL_BIN_PATH" ] && echo "Check env values && exit 1

echo "------------------------------"
echo "Collect binaries from $TARGET_PATH ... "
echo "------------------------------"

[ -r ../nushell/target/release/nu ] &&  cp -v ../nushell/target/release/nu . 

cp -v ../nu_plugin_*/target/release/nu_plugin_* . 
rm -f nu_plugin_*.d

echo "------------------------------"
echo "Generate installer for nushell in $INSTALL_FILE ..."
echo "------------------------------"
echo "#!/usr/bin/env nu" > $INSTALL_FILE
for plgn in $(ls -d nu_plugin_*) 
do
   echo "plugin add $INSTALL_BIN_PATH/$plgn ">>$INSTALL_FILE
   echo "$plgn"
done
chmod +x $INSTALL_FILE

echo "------------------------------"
echo "Install nu plugins in $INSTALL_BIN_PATH ..."
echo "------------------------------"
cp -pv nu_plugin* $INSTALL_BIN_PATH

