2
0
mirror of https://github.com/deajan/osync synced 2024-11-15 12:12:56 +00:00
osync/dev/merge.sh

202 lines
5.0 KiB
Bash
Raw Normal View History

2015-11-12 00:37:43 +00:00
#!/usr/bin/env bash
2018-06-25 12:11:46 +00:00
## MERGE 2018062501
## Merges ofunctions.sh and n_program.sh into program.sh
## Adds installer
2015-11-12 00:37:43 +00:00
function Usage {
echo "Merges ofunctions.sh and n_program.sh into debug_program.sh and ../program.sh"
echo "Usage"
echo "$0 osync|obackup|pmocr"
}
2016-12-07 20:30:10 +00:00
function __PREPROCESSOR_Merge {
2017-06-18 20:53:57 +00:00
local PROGRAM="$1"
2017-03-14 20:12:38 +00:00
2016-12-07 20:30:10 +00:00
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
VERSION=${VERSION#*=}
__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
2017-06-18 20:53:57 +00:00
__PREPROCESSOR_CleanDebug "$PROGRAM"
2016-12-07 20:30:10 +00:00
rm -f tmp_$PROGRAM.sh
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot remove tmp_$PROGRAM.sh" "SIMPLE"
2016-12-07 20:30:10 +00:00
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 ####'
2016-12-19 21:38:13 +00:00
'#### OFUNCTIONS MINI SUBSET ####'
2016-12-11 13:58:52 +00:00
'#### _OFUNCTIONS_BOOTSTRAP SUBSET ####'
2016-12-07 20:30:10 +00:00
'#### DEBUG SUBSET ####'
'#### TrapError SUBSET ####'
'#### RemoteLogger SUBSET ####'
2018-06-25 12:11:46 +00:00
'#### Logger SUBSET ####'
2016-12-11 21:40:27 +00:00
'#### GetLocalOS SUBSET ####'
2016-12-07 20:30:10 +00:00
'#### IsInteger SUBSET ####'
2016-12-11 21:40:27 +00:00
'#### UrlEncode SUBSET ####'
2016-12-07 20:30:10 +00:00
'#### HumanToNumeric SUBSET ####'
'#### ArrayContains SUBSET ####'
2017-04-11 11:26:23 +00:00
'#### VerComp SUBSET ####'
2017-02-07 21:04:19 +00:00
'#### GetConfFileValue SUBSET ####'
'#### SetConfFileValue SUBSET ####'
2018-02-20 21:15:20 +00:00
'#### CheckRFC822 SUBSET ####'
2016-12-07 20:30:10 +00:00
)
}
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
2018-06-25 12:11:46 +00:00
Logger "Cannot unexpand [$source] to [$destination]." "SIMPLE"
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-11 19:54:40 +00:00
sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin"
2016-12-07 20:30:10 +00:00
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]." "SIMPLE"
2016-12-07 20:30:10 +00:00
exit 1
fi
2016-12-11 19:54:40 +00:00
sed "/include $subsetBegin/r $subsetFile.$subsetBegin" "$mergedFile" | grep -v -E "$subsetBegin\$|$subsetEnd\$" > "$mergedFile.tmp"
2016-12-07 20:30:10 +00:00
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot add subset [$subsetBegin] to [$mergedFile]." "SIMPLE"
2016-12-07 20:30:10 +00:00
exit 1
fi
rm -f "$subsetFile.$subsetBegin"
2016-12-07 20:30:10 +00:00
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot remove temporary subset [$subsetFile.$subsetBegin]." "SIMPLE"
2016-12-07 20:30:10 +00:00
exit 1
fi
2016-12-11 19:54:40 +00:00
rm -f "$mergedFile"
2016-12-07 20:30:10 +00:00
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot remove merged original file [$mergedFile]." "SIMPLE"
2016-12-07 20:30:10 +00:00
exit 1
fi
2015-11-12 00:37:43 +00:00
2016-12-11 19:54:40 +00:00
mv "$mergedFile.tmp" "$mergedFile"
2016-12-07 20:30:10 +00:00
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot move merged tmp file to original [$mergedFile]." "SIMPLE"
2016-12-07 20:30:10 +00:00
exit 1
fi
}
2015-11-12 00:37:43 +00:00
2016-12-07 20:30:10 +00:00
function __PREPROCESSOR_CleanDebug {
2017-06-18 20:53:57 +00:00
local PROGRAM="$1"
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
2018-06-25 12:11:46 +00:00
Logger "Cannot remove PARANOIA_DEBUG code from standard build." "SIMPLE"
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
2018-06-25 12:11:46 +00:00
Logger "Cannot chmod debug_$PROGRAM.sh" "SIMPLE"
2016-12-07 20:30:10 +00:00
exit 1
2016-12-11 21:40:27 +00:00
else
2018-06-25 12:11:46 +00:00
Logger "Prepared ./debug_$PROGRAM.sh" "SIMPLE"
2016-12-07 20:30:10 +00:00
fi
chmod +x "../$PROGRAM.sh"
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot chmod $PROGRAM.sh" "SIMPLE"
2016-08-30 16:20:41 +00:00
exit 1
2016-12-11 21:40:27 +00:00
else
2018-06-25 12:11:46 +00:00
Logger "Prepared ../$PROGRAM.sh" "SIMPLE"
2016-08-30 16:20:41 +00:00
fi
2015-11-12 00:37:43 +00:00
}
2016-12-07 20:30:10 +00:00
function __PREPROCESSOR_CopyCommons {
2017-06-18 20:53:57 +00:00
local PROGRAM="$1"
2017-03-14 20:12:38 +00:00
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../install.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot assemble install." "SIMPLE"
2016-08-30 16:20:41 +00:00
exit 1
fi
2016-12-11 21:40:27 +00:00
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
2017-03-14 20:12:38 +00:00
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "../install.sh"
2016-12-11 21:40:27 +00:00
done
2017-03-14 20:12:38 +00:00
#sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
#if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
# Logger "Cannot change install version." "SIMPLE"
2017-03-14 20:12:38 +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
2018-06-25 12:11:46 +00:00
Logger "Cannot assemble batch runner." "SIMPLE"
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
2018-06-25 12:11:46 +00:00
Logger "Cannot chmod $PROGRAM-batch.sh" "SIMPLE"
2016-09-08 20:49:51 +00:00
exit 1
2016-12-11 21:40:27 +00:00
else
2018-06-25 12:11:46 +00:00
Logger "Prepared ../$PROGRAM-batch.sh" "SIMPLE"
2016-09-08 20:49:51 +00:00
fi
fi
chmod +x ../install.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot chmod install.sh" "SIMPLE"
2016-08-30 16:20:41 +00:00
exit 1
2016-12-11 21:40:27 +00:00
else
2018-06-25 12:11:46 +00:00
Logger "Prepared ../install.sh" "SIMPLE"
2016-08-30 16:20:41 +00:00
fi
rm -f ../tmp_install.sh
2016-08-30 16:20:41 +00:00
if [ $? != 0 ]; then
2018-06-25 12:11:46 +00:00
Logger "Cannot chmod $PROGRAM.sh" "SIMPLE"
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
if [ "$1" == "osync" ]; then
__PREPROCESSOR_Merge osync
__PREPROCESSOR_Merge osync_target_helper
__PREPROCESSOR_CopyCommons osync
elif [ "$1" == "obackup" ]; then
__PREPROCESSOR_Merge obackup
__PREPROCESSOR_CopyCommons obackup
elif [ "$1" == "pmocr" ]; then
__PREPROCESSOR_Merge pmocr
__PREPROCESSOR_CopyCommons pmocr
else
echo "No valid program given."
2018-05-28 06:28:01 +00:00
Usage
exit 1
fi
2016-08-30 16:20:41 +00:00
fi