1
0
mirror of https://github.com/deajan/obackup.git synced 2024-11-15 04:03:41 +01:00
obackup/dev/bootstrap.sh

76 lines
1.8 KiB
Bash
Raw Normal View History

2016-12-20 21:19:31 +01:00
#!/usr/bin/env bash
2018-10-02 21:21:58 +02:00
## dev pre-processor bootstrap rev 2018100201
2016-12-20 21:19:31 +01: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-10-02 21:21:58 +02:00
echo "$0 --program=osync|obackup|pmocr [options to pass to program]"
echo "Can also be run with BASHVERBOSE=yes environment variable in order to prefix program with bash -x"
}
2016-12-20 21:19:31 +01:00
if [ ! -f "./merge.sh" ]; then
echo "Plrase run bootstrap.sh from osync/dev directory."
exit 1
fi
bootstrapProgram=""
opts=""
2016-12-20 21:19:31 +01:00
outputFileName="$0"
for i in "$@"; do
case $i in
--program=*)
bootstrapProgram="${i##*=}"
;;
*)
opts=$opts" $i"
;;
esac
done
if [ "$bootstrapProgram" == "" ]; then
Usage
exit 128
else
source "merge.sh"
__PREPROCESSOR_PROGRAM=$bootstrapProgram
__PREPROCESSOR_PROGRAM_EXEC="n_$bootstrapProgram.sh"
__PREPROCESSOR_Constants
if [ ! -f "$__PREPROCESSOR_PROGRAM_EXEC" ]; then
2018-10-02 21:21:58 +02:00
echo "Cannot find file $__PREPROCESSOR_PROGRAM executable [n_$bootstrapProgram.sh]."
exit 1
fi
fi
2016-12-20 21:19:31 +01:00
cp "$__PREPROCESSOR_PROGRAM_EXEC" "$outputFileName.tmp.sh"
2016-12-20 21:19:31 +01:00
if [ $? != 0 ]; then
echo "Cannot copy original file [$__PREPROCESSOR_PROGRAM_EXEC] to [$outputFileName.tmp.sh]."
2016-12-20 21:19:31 +01:00
exit 1
fi
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "$outputFileName.tmp.sh"
done
chmod +x "$outputFileName.tmp.sh"
2016-12-20 21:19:31 +01:00
if [ $? != 0 ]; then
echo "Cannot make [$outputFileName] executable."
2016-12-20 21:19:31 +01:00
exit 1
fi
# Termux fix
if type termux-fix-shebang > /dev/null 2>&1; then
termux-fix-shebang "$outputFileName.tmp.sh"
fi
2018-10-02 21:21:58 +02:00
if [ "$BASHVERBOSE" == "yes" ]; then
2018-03-25 14:16:31 +02:00
bash -x "$outputFileName.tmp.sh" $opts
else
"$outputFileName.tmp.sh" $opts
fi