2
0
mirror of https://github.com/deajan/osync synced 2024-11-19 03:25:37 +00:00
osync/dev/merge.sh

157 lines
4.0 KiB
Bash
Raw Normal View History

2015-11-12 00:37:43 +00:00
#!/usr/bin/env bash
## MERGE 2016120802
## Merges ofunctions.sh and n_program.sh into program.sh
## Adds installer
2015-11-12 00:37:43 +00:00
2016-12-07 20:30:10 +00:00
function __PREPROCESSOR_Merge {
PROGRAM=osync
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
VERSION=${VERSION#*=}
2015-11-12 00:37:43 +00:00
2016-12-07 20:30:10 +00:00
__PREPROCESSOR_Constants
2015-11-12 00:37:43 +00:00
2016-12-07 20:30:10 +00:00
source "ofunctions.sh"
if [ $? != 0 ]; then
echo "Please run $0 in dev directory with ofunctions.sh"
exit 1
fi
__PREPROCESSOR_Unexpand "n_$PROGRAM.sh" "debug_$PROGRAM.sh"
2016-08-30 16:20:41 +00:00
2016-12-07 20:30:10 +00:00
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
QuickLogger "Cannot remove tmp_$PROGRAM.sh" "stderr"
exit 1
fi
2015-11-12 00:37:43 +00:00
}
2016-12-07 20:30:10 +00: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 MINIMAL SUBSET ####'
'#### DEBUG SUBSET ####'
'#### TrapError SUBSET ####'
'#### RemoteLogger SUBSET ####'
'#### IsInteger SUBSET ####'
'#### HumanToNumeric SUBSET ####'
'#### ArrayContains SUBSET ####'
)
}
2016-12-07 20:30:10 +00:00
function __PREPROCESSOR_Unexpand {
local source="${1}"
local destination="${2}"
unexpand "$source" > "$destination"
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot unexpand [$source] to [$destination]." "stderr"
2016-08-30 16:20:41 +00:00
exit 1
fi
2016-12-07 20:30:10 +00:00
}
function __PREPROCESSOR_MergeSubset {
local subsetBegin="${1}"
local subsetEnd="${2}"
local subsetFile="${3}"
local mergedFile="${4}"
2016-12-07 20:30:10 +00:00
sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin"
if [ $? != 0 ]; then
QuickLogger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]." "stderr"
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]." "stderr"
exit 1
fi
rm -f "$subsetFile.$subsetBegin"
2016-12-07 20:30:10 +00:00
if [ $? != 0 ]; then
QuickLogger "Cannot remove temporary subset [$subsetFile.$subsetBeign]." "stderr"
exit 1
fi
rm -f "$mergedFile"
if [ $? != 0 ]; then
QuickLogger "Cannot remove merged original file [$mergedFile]." "stderr"
exit 1
fi
2015-11-12 00:37:43 +00:00
2016-12-07 20:30:10 +00:00
mv "$mergedFile.tmp" "$mergedFile"
if [ $? != 0 ]; then
QuickLogger "Cannot move merged tmp file to original [$mergedFile]." "stderr"
exit 1
fi
}
2015-11-12 00:37:43 +00:00
2016-12-07 20:30:10 +00:00
function __PREPROCESSOR_CleanDebug {
2016-11-20 16:41:52 +00:00
sed '/'$PARANOIA_DEBUG_BEGIN'/,/'$PARANOIA_DEBUG_END'/d' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build." "stderr"
2016-08-30 16:20:41 +00:00
exit 1
fi
2016-12-07 20:30:10 +00:00
chmod +x "debug_$PROGRAM.sh"
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot chmod debug_$PROGRAM.sh" "stderr"
exit 1
fi
chmod +x "../$PROGRAM.sh"
if [ $? != 0 ]; then
QuickLogger "Cannot chmod $PROGRAM.sh" "stderr"
2016-08-30 16:20:41 +00:00
exit 1
fi
2015-11-12 00:37:43 +00:00
}
2016-12-07 20:30:10 +00:00
function __PREPROCESSOR_CopyCommons {
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot assemble install." "stderr"
2016-08-30 16:20:41 +00:00
exit 1
fi
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot change install version." "stderr"
2016-08-30 16:20:41 +00:00
exit 1
fi
if [ -f "common_batch.sh" ]; then
sed "s/\[prgname\]/$PROGRAM/g" common_batch.sh > ../$PROGRAM-batch.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot assemble batch runner." "stderr"
2016-08-30 16:20:41 +00:00
exit 1
fi
2016-09-08 20:49:51 +00:00
chmod +x ../$PROGRAM-batch.sh
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot chmod $PROGRAM-batch.sh" "stderr"
2016-09-08 20:49:51 +00:00
exit 1
fi
fi
chmod +x ../install.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot chmod install.sh" "stderr"
2016-08-30 16:20:41 +00:00
exit 1
fi
rm -f ../tmp_install.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2016-12-07 20:30:10 +00:00
QuickLogger "Cannot chmod $PROGRAM.sh" "stderr"
2016-08-30 16:20:41 +00:00
exit 1
fi
2015-11-12 00:37:43 +00:00
}
2016-12-07 20:30:10 +00:00
# If sourced don't do anything
if [ "$(basename $0)" == "merge.sh" ]; then
__PREPROCESSOR_Merge
2016-08-30 16:20:41 +00:00
fi