1
0
mirror of https://github.com/deajan/obackup.git synced 2024-09-28 16:13:40 +02:00

Added merge and bootstrap from osync

This commit is contained in:
deajan 2016-12-20 21:19:31 +01:00
parent 25fb362762
commit 7967251206
2 changed files with 148 additions and 81 deletions

36
dev/bootstrap.sh Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
## dev pre-processor bootstrap rev 2016121302
## Yeah !!! A really tech sounding name... In fact it's just include emulation in bash
if [ ! -f "./merge.sh" ]; then
echo "Plrase run bootstrap.sh from osync/dev directory."
exit 1
fi
outputFileName="$0"
source "merge.sh"
__PREPROCESSOR_PROGRAM=obackup
__PREPROCESSOR_Constants
cp "n_$__PREPROCESSOR_PROGRAM.sh" "$outputFileName.tmp.sh"
if [ $? != 0 ]; then
echo "Cannot copy original file [n_$__PREPROCESSOR_PROGRAM.sh] to [$outputFileName.tmp.sh]."
exit 1
fi
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "$outputFileName.tmp.sh"
done
chmod +x "$0.tmp.sh"
if [ $? != 0 ]; then
echo "Cannot make [$outputFileName] executable.."
exit 1
fi
# Termux fix
if type termux-fix-shebang > /dev/null 2>&1; then
termux-fix-shebang "$outputFileName.tmp.sh"
fi
"$outputFileName.tmp.sh" "$@"

View File

@ -1,142 +1,173 @@
#!/usr/bin/env bash #!/usr/bin/env bash
## MERGE 2016112001 ## MERGE 2016121901
## Merges ofunctions.sh and n_program.sh into program.sh ## Merges ofunctions.sh and n_program.sh into program.sh
## Adds installer ## Adds installer
PROGRAM=obackup function __PREPROCESSOR_Merge {
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh) PROGRAM=obackup
VERSION=${VERSION#*=} VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
VERSION=${VERSION#*=}
PARANOIA_DEBUG_LINE="__WITH_PARANOIA_DEBUG" __PREPROCESSOR_Constants
PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
MINIMUM_FUNCTION_BEGIN="#### MINIMAL-FUNCTION-SET BEGIN ####"
MINIMUM_FUNCTION_END="#### MINIMAL-FUNCTION-SET END ####"
source "ofunctions.sh" source "ofunctions.sh"
if [ $? != 0 ]; then
echo "Please run $0 in dev directory with ofunctions.sh"
exit 1
fi
function Unexpand {
unexpand n_$PROGRAM.sh > tmp_$PROGRAM.sh
}
function MergeAll {
sed "/source \"\.\/ofunctions.sh\"/r ofunctions.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' > debug_$PROGRAM.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot sed ofunctions" "stdout" echo "Please run $0 in dev directory with ofunctions.sh"
exit 1 exit 1
fi fi
chmod +x debug_$PROGRAM.sh
__PREPROCESSOR_Unexpand "n_$PROGRAM.sh" "debug_$PROGRAM.sh"
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "debug_$PROGRAM.sh"
done
__PREPROCESSOR_CleanDebug
__PREPROCESSOR_CopyCommons
rm -f tmp_$PROGRAM.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout" QuickLogger "Cannot remove tmp_$PROGRAM.sh"
exit 1 exit 1
fi fi
} }
function MergeMinimum { function __PREPROCESSOR_Constants {
sed -n "/$MINIMUM_FUNCTION_BEGIN/,/$MINIMUM_FUNCTION_END/p" ofunctions.sh > tmp_minimal.sh PARANOIA_DEBUG_LINE="#__WITH_PARANOIA_DEBUG"
if [ $? != 0 ]; then PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
QuickLogger "Cannot sed minimum functions." "stdout" PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
exit 1
fi
sed "/source \"\.\/ofunctions.sh\"/r tmp_minimal.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' | grep -v "$PARANOIA_DEBUG_LINE" > debug_$PROGRAM.sh
if [ $? != 0 ]; then
QuickLogger "Cannot remove PARANOIA_DEBUG code from tmp_minimum.." "stdout"
exit 1
fi
rm -f tmp_minimal.sh
if [ $? != 0 ]; then
QuickLogger "Cannot remove tmp_minimal.sh" "stdout"
exit 1
fi
chmod +x debug_$PROGRAM.sh
if [ $? != 0 ]; then
QuickLogger "Cannot chmod debug_$PROGRAM.sh" "stdout"
exit 1
fi
__PREPROCESSOR_SUBSETS=(
'#### OFUNCTIONS FULL SUBSET ####'
'#### OFUNCTIONS MINI SUBSET ####'
'#### _OFUNCTIONS_BOOTSTRAP SUBSET ####'
'#### DEBUG SUBSET ####'
'#### TrapError SUBSET ####'
'#### RemoteLogger SUBSET ####'
'#### QuickLogger SUBSET ####'
'#### GetLocalOS SUBSET ####'
'#### IsInteger SUBSET ####'
'#### UrlEncode SUBSET ####'
'#### HumanToNumeric SUBSET ####'
'#### ArrayContains SUBSET ####'
)
} }
function __PREPROCESSOR_Unexpand {
local source="${1}"
local destination="${2}"
function CleanDebug { unexpand "$source" > "$destination"
if [ $? != 0 ]; then
QuickLogger "Cannot unexpand [$source] to [$destination]."
exit 1
fi
}
# sed explanation function __PREPROCESSOR_MergeSubset {
#/pattern1/{ # if pattern1 is found local subsetBegin="${1}"
# p # print it local subsetEnd="${2}"
# :a # loop local subsetFile="${3}"
# N # and accumulate lines local mergedFile="${4}"
# /pattern2/!ba # until pattern2 is found
# s/.*\n// # delete the part before pattern2
#}
#p
# sed -n '/'$PARANOIA_DEBUG_BEGIN'/{p; :a; N; /'$PARANOIA_DEBUG_END'/!ba; s/.*\n//}; p' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh
# Way simpler version of the above, compatible with BSD sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin"
if [ $? != 0 ]; then
QuickLogger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]."
exit 1
fi
sed "/include $subsetBegin/r $subsetFile.$subsetBegin" "$mergedFile" | grep -v -E "$subsetBegin\$|$subsetEnd\$" > "$mergedFile.tmp"
if [ $? != 0 ]; then
QuickLogger "Cannot add subset [$subsetBegin] to [$mergedFile]."
exit 1
fi
rm -f "$subsetFile.$subsetBegin"
if [ $? != 0 ]; then
QuickLogger "Cannot remove temporary subset [$subsetFile.$subsetBegin]."
exit 1
fi
rm -f "$mergedFile"
if [ $? != 0 ]; then
QuickLogger "Cannot remove merged original file [$mergedFile]."
exit 1
fi
mv "$mergedFile.tmp" "$mergedFile"
if [ $? != 0 ]; then
QuickLogger "Cannot move merged tmp file to original [$mergedFile]."
exit 1
fi
}
function __PREPROCESSOR_CleanDebug {
sed '/'$PARANOIA_DEBUG_BEGIN'/,/'$PARANOIA_DEBUG_END'/d' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh sed '/'$PARANOIA_DEBUG_BEGIN'/,/'$PARANOIA_DEBUG_END'/d' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build." "stdout" QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build."
exit 1 exit 1
fi fi
chmod +x ../$PROGRAM.sh chmod +x "debug_$PROGRAM.sh"
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout" QuickLogger "Cannot chmod debug_$PROGRAM.sh"
exit 1 exit 1
else
QuickLogger "Prepared ./debug_$PROGRAM.sh"
fi
chmod +x "../$PROGRAM.sh"
if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh"
exit 1
else
QuickLogger "Prepared ../$PROGRAM.sh"
fi fi
} }
function CopyCommons { function __PREPROCESSOR_CopyCommons {
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot assemble install." "stdout" QuickLogger "Cannot assemble install."
exit 1 exit 1
fi fi
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "../tmp_install.sh"
done
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot change install version." "stdout" QuickLogger "Cannot change install version."
exit 1 exit 1
fi fi
if [ -f "common_batch.sh" ]; then if [ -f "common_batch.sh" ]; then
sed "s/\[prgname\]/$PROGRAM/g" common_batch.sh > ../$PROGRAM-batch.sh sed "s/\[prgname\]/$PROGRAM/g" common_batch.sh > ../$PROGRAM-batch.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot assemble batch runner." "stdout" QuickLogger "Cannot assemble batch runner."
exit 1 exit 1
fi fi
chmod +x ../$PROGRAM-batch.sh chmod +x ../$PROGRAM-batch.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM-batch.sh" "stdout" QuickLogger "Cannot chmod $PROGRAM-batch.sh"
exit 1 exit 1
else
QuickLogger "Prepared ../$PROGRAM-batch.sh"
fi fi
fi fi
chmod +x ../install.sh chmod +x ../install.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot chmod install.sh" "stdout" QuickLogger "Cannot chmod install.sh"
exit 1 exit 1
else
QuickLogger "Prepared ../install.sh"
fi fi
rm -f ../tmp_install.sh rm -f ../tmp_install.sh
if [ $? != 0 ]; then if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout" QuickLogger "Cannot chmod $PROGRAM.sh"
exit 1 exit 1
fi fi
} }
Unexpand # If sourced don't do anything
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then if [ "$(basename $0)" == "merge.sh" ]; then
MergeAll __PREPROCESSOR_Merge
else
MergeMinimum
fi
CleanDebug
CopyCommons
rm -f tmp_$PROGRAM.sh
if [ $? != 0 ]; then
QuickLogger "Cannot remove tmp_$PROGRAM.sh" "stdout"
exit 1
fi fi