2015-11-12 01:26:38 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
## MERGE 2016121901
|
2016-08-06 16:14:07 +02:00
|
|
|
|
2016-08-06 15:15:11 +02:00
|
|
|
## Merges ofunctions.sh and n_program.sh into program.sh
|
|
|
|
## Adds installer
|
2015-11-12 01:26:38 +01:00
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
function __PREPROCESSOR_Merge {
|
|
|
|
PROGRAM=obackup
|
|
|
|
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
|
|
|
|
VERSION=${VERSION#*=}
|
2015-11-12 01:26:38 +01:00
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
__PREPROCESSOR_Constants
|
2015-11-12 01:26:38 +01:00
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
source "ofunctions.sh"
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Please run $0 in dev directory with ofunctions.sh"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-30 18:28:27 +02:00
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
__PREPROCESSOR_Unexpand "n_$PROGRAM.sh" "debug_$PROGRAM.sh"
|
2015-11-12 01:26:38 +01:00
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
|
|
|
|
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "debug_$PROGRAM.sh"
|
|
|
|
done
|
2015-11-12 01:26:38 +01:00
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
__PREPROCESSOR_CleanDebug
|
|
|
|
__PREPROCESSOR_CopyCommons
|
|
|
|
rm -f tmp_$PROGRAM.sh
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot remove tmp_$PROGRAM.sh"
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-12-20 21:19:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function __PREPROCESSOR_Constants {
|
|
|
|
PARANOIA_DEBUG_LINE="#__WITH_PARANOIA_DEBUG"
|
|
|
|
PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
|
|
|
|
PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
|
|
|
|
|
|
|
|
__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}"
|
|
|
|
|
|
|
|
unexpand "$source" > "$destination"
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot unexpand [$source] to [$destination]."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2015-11-12 01:26:38 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
function __PREPROCESSOR_MergeSubset {
|
|
|
|
local subsetBegin="${1}"
|
|
|
|
local subsetEnd="${2}"
|
|
|
|
local subsetFile="${3}"
|
|
|
|
local mergedFile="${4}"
|
|
|
|
|
|
|
|
sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin"
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-12-20 21:19:31 +01:00
|
|
|
sed "/include $subsetBegin/r $subsetFile.$subsetBegin" "$mergedFile" | grep -v -E "$subsetBegin\$|$subsetEnd\$" > "$mergedFile.tmp"
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot add subset [$subsetBegin] to [$mergedFile]."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-12-20 21:19:31 +01:00
|
|
|
rm -f "$subsetFile.$subsetBegin"
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot remove temporary subset [$subsetFile.$subsetBegin]."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
rm -f "$mergedFile"
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot remove merged original file [$mergedFile]."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
mv "$mergedFile.tmp" "$mergedFile"
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot move merged tmp file to original [$mergedFile]."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-06 15:15:11 +02:00
|
|
|
}
|
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
function __PREPROCESSOR_CleanDebug {
|
2016-11-30 13:28:26 +01:00
|
|
|
sed '/'$PARANOIA_DEBUG_BEGIN'/,/'$PARANOIA_DEBUG_END'/d' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
chmod +x "debug_$PROGRAM.sh"
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot chmod debug_$PROGRAM.sh"
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
2016-12-20 21:19:31 +01:00
|
|
|
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"
|
2016-08-30 18:28:27 +02:00
|
|
|
fi
|
2015-11-12 01:26:38 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
function __PREPROCESSOR_CopyCommons {
|
2016-08-06 15:15:11 +02:00
|
|
|
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot assemble install."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-12-20 21:19:31 +01:00
|
|
|
|
|
|
|
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
|
|
|
|
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "../tmp_install.sh"
|
|
|
|
done
|
|
|
|
|
2016-03-25 22:51:26 +01:00
|
|
|
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot change install version."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-06 16:14:07 +02:00
|
|
|
if [ -f "common_batch.sh" ]; then
|
|
|
|
sed "s/\[prgname\]/$PROGRAM/g" common_batch.sh > ../$PROGRAM-batch.sh
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot assemble batch runner."
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-09-08 22:51:00 +02:00
|
|
|
chmod +x ../$PROGRAM-batch.sh
|
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot chmod $PROGRAM-batch.sh"
|
2016-09-08 22:51:00 +02:00
|
|
|
exit 1
|
2016-12-20 21:19:31 +01:00
|
|
|
else
|
|
|
|
QuickLogger "Prepared ../$PROGRAM-batch.sh"
|
2016-09-08 22:51:00 +02:00
|
|
|
fi
|
2016-08-06 16:14:07 +02:00
|
|
|
fi
|
2015-11-12 01:26:38 +01:00
|
|
|
chmod +x ../install.sh
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot chmod install.sh"
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
2016-12-20 21:19:31 +01:00
|
|
|
else
|
|
|
|
QuickLogger "Prepared ../install.sh"
|
2016-08-30 18:28:27 +02:00
|
|
|
fi
|
2016-08-06 15:15:11 +02:00
|
|
|
rm -f ../tmp_install.sh
|
2016-08-30 18:28:27 +02:00
|
|
|
if [ $? != 0 ]; then
|
2016-12-20 21:19:31 +01:00
|
|
|
QuickLogger "Cannot chmod $PROGRAM.sh"
|
2016-08-30 18:28:27 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2015-11-12 01:26:38 +01:00
|
|
|
}
|
|
|
|
|
2016-12-20 21:19:31 +01:00
|
|
|
# If sourced don't do anything
|
|
|
|
if [ "$(basename $0)" == "merge.sh" ]; then
|
|
|
|
__PREPROCESSOR_Merge
|
2016-08-30 18:28:27 +02:00
|
|
|
fi
|