2
0
mirror of https://github.com/deajan/osync synced 2024-11-11 07:10:40 +00:00
osync/dev/bootstrap.sh

76 lines
1.8 KiB
Bash
Raw Normal View History

2016-12-07 20:30:10 +00:00
#!/usr/bin/env bash
2018-10-02 16:19:32 +00:00
## dev pre-processor bootstrap rev 2018100201
2016-12-07 20:30:10 +00:00
## Yeah !!! A really tech sounding name... In fact it's just include emulation in bash
function Usage {
echo "$0 - Quick and dirty preprocessor for including ofunctions into programs"
echo "Creates and executes $0.tmp.sh"
echo "Usage:"
echo ""
2018-09-30 19:21:30 +00:00
echo "$0 --program=osync|obackup|pmocr [options to pass to program]"
2018-06-25 12:49:15 +00:00
echo "Can also be run with BASHVERBOSE=yes environment variable in order to prefix program with bash -x"
}
2016-12-13 18:28:47 +00:00
if [ ! -f "./merge.sh" ]; then
2016-12-13 11:33:30 +00:00
echo "Plrase run bootstrap.sh from osync/dev directory."
exit 1
fi
bootstrapProgram=""
opts=""
2016-12-07 20:30:10 +00:00
outputFileName="$0"
for i in "$@"; do
case $i in
--program=*)
bootstrapProgram="${i##*=}"
;;
*)
opts=$opts" $i"
;;
esac
done
if [ "$bootstrapProgram" == "" ]; then
Usage
exit 128
2017-06-20 13:20:42 +00:00
else
source "merge.sh"
2016-12-07 20:30:10 +00:00
2017-06-20 13:20:42 +00:00
__PREPROCESSOR_PROGRAM=$bootstrapProgram
__PREPROCESSOR_PROGRAM_EXEC="n_$bootstrapProgram.sh"
__PREPROCESSOR_Constants
2017-06-18 20:48:38 +00:00
2017-06-20 13:20:42 +00:00
if [ ! -f "$__PREPROCESSOR_PROGRAM_EXEC" ]; then
2018-10-02 16:19:32 +00:00
echo "Cannot find file $__PREPROCESSOR_PROGRAM executable [n_$bootstrapProgram.sh]."
2017-06-20 13:20:42 +00:00
exit 1
fi
fi
2016-12-07 20:30:10 +00:00
2017-06-20 13:20:42 +00:00
cp "$__PREPROCESSOR_PROGRAM_EXEC" "$outputFileName.tmp.sh"
2016-12-07 20:30:10 +00:00
if [ $? != 0 ]; then
2017-06-20 13:20:42 +00:00
echo "Cannot copy original file [$__PREPROCESSOR_PROGRAM_EXEC] to [$outputFileName.tmp.sh]."
2016-12-07 20:30:10 +00:00
exit 1
fi
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "$outputFileName.tmp.sh"
done
2017-06-18 20:48:38 +00:00
chmod +x "$outputFileName.tmp.sh"
2016-12-07 20:30:10 +00:00
if [ $? != 0 ]; then
2017-06-18 20:48:38 +00:00
echo "Cannot make [$outputFileName] executable."
2016-12-07 20:30:10 +00:00
exit 1
fi
2016-12-10 16:56:03 +00:00
# Termux fix
if type termux-fix-shebang > /dev/null 2>&1; then
termux-fix-shebang "$outputFileName.tmp.sh"
fi
2018-06-25 12:49:15 +00:00
if [ "$BASHVERBOSE" == "yes" ]; then
2018-03-22 16:24:04 +00:00
bash -x "$outputFileName.tmp.sh" $opts
else
"$outputFileName.tmp.sh" $opts
fi