project-layout/scripts/mfgames-project-script-builder.sh
D. Moonfire edb2f36b57
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
chore: added script builder and updated scripts
2023-01-25 18:33:34 -06:00

55 lines
1.3 KiB
Bash
Executable file

# !/usr/bin/env bash
# Variables
version=0.0.0
# Make sure we have the proper parameters.
usage() {
echo "USAGE $0 script.sh [script2.sh]"
exit 1
}
if [ "x$1" = "x" ]
then
usage
fi
# Go through the script and look for each one.
for script in "$@"
do
# Write out the file.
echo '# !/usr/bin/env bash' > .mfgames-project.tmp
if [ -f $script ]
then
cat $script \
| sed -n '/usr.bin.env bash/!p' \
| sed '/^#mfgames-project:setup@/q' \
| sed -n '/mfgames-project:setup/!p' \
>> .mfgames-project.tmp
else
echo >> .mfgames-project.tmp
fi
echo "#mfgames-project:setup@v$version" >> .mfgames-project.tmp
if [ -f $script ] && grep 'log() { echo' $script > /dev/null
then
grep 'log() { echo' $script >> .mfgames-project.tmp
else
unicode=$(unipicker)
echo "log() { echo \"$unicode \$(basename \$0): \$@\"; }" >> .mfgames-project.tmp
fi
echo "cd \$(dirname \$(dirname \$0))" >> .mfgames-project.tmp
echo "#mfgames-project:setup" >> .mfgames-project.tmp
if [ -f $script ]
then
sed '1,/^#mfgames-project:setup$/d' < $script >> .mfgames-project.tmp
fi
# Finish up and make the script executable.
mv .mfgames-project.tmp $script
chmod a+x $script
done