2015-11-12 00:37:43 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2016-11-20 16:41:52 +00:00
|
|
|
## MERGE 2016112001
|
2016-08-28 19:39:09 +00:00
|
|
|
|
|
|
|
## Merges ofunctions.sh and n_program.sh into program.sh
|
|
|
|
## Adds installer
|
2015-11-12 00:37:43 +00:00
|
|
|
|
|
|
|
PROGRAM=osync
|
2016-03-25 22:08:48 +00:00
|
|
|
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
|
|
|
|
VERSION=${VERSION#*=}
|
2015-11-12 00:37:43 +00:00
|
|
|
|
2016-08-28 19:39:09 +00:00
|
|
|
PARANOIA_DEBUG_LINE="__WITH_PARANOIA_DEBUG"
|
2015-11-12 00:37:43 +00:00
|
|
|
PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
|
|
|
|
PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
|
2016-08-28 19:39:09 +00:00
|
|
|
MINIMUM_FUNCTION_BEGIN="#### MINIMAL-FUNCTION-SET BEGIN ####"
|
|
|
|
MINIMUM_FUNCTION_END="#### MINIMAL-FUNCTION-SET END ####"
|
2015-11-12 00:37:43 +00:00
|
|
|
|
2016-08-30 16:20:41 +00:00
|
|
|
source "ofunctions.sh"
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Please run $0 in dev directory with ofunctions.sh"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-11-12 00:37:43 +00:00
|
|
|
function Unexpand {
|
2016-08-28 19:39:09 +00:00
|
|
|
unexpand n_$PROGRAM.sh > tmp_$PROGRAM.sh
|
2015-11-12 00:37:43 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 19:39:09 +00:00
|
|
|
function MergeAll {
|
|
|
|
|
|
|
|
sed "/source \"\.\/ofunctions.sh\"/r ofunctions.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' > debug_$PROGRAM.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot sed ofunctions" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-28 19:39:09 +00:00
|
|
|
chmod +x debug_$PROGRAM.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-28 19:39:09 +00:00
|
|
|
}
|
2015-11-12 00:37:43 +00:00
|
|
|
|
2016-08-28 19:39:09 +00:00
|
|
|
function MergeMinimum {
|
|
|
|
sed -n "/$MINIMUM_FUNCTION_BEGIN/,/$MINIMUM_FUNCTION_END/p" ofunctions.sh > tmp_minimal.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot sed minimum functions." "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-28 19:39:09 +00:00
|
|
|
sed "/source \"\.\/ofunctions.sh\"/r tmp_minimal.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' | grep -v "$PARANOIA_DEBUG_LINE" > debug_$PROGRAM.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot remove PARANOIA_DEBUG code from tmp_minimum.." "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-28 19:39:09 +00:00
|
|
|
rm -f tmp_minimal.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot remove tmp_minimal.sh" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-11-12 00:37:43 +00:00
|
|
|
chmod +x debug_$PROGRAM.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot chmod debug_$PROGRAM.sh" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-11-12 00:37:43 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 19:39:09 +00:00
|
|
|
|
2015-11-12 00:37:43 +00:00
|
|
|
function CleanDebug {
|
|
|
|
|
|
|
|
# sed explanation
|
|
|
|
#/pattern1/{ # if pattern1 is found
|
|
|
|
# p # print it
|
|
|
|
# :a # loop
|
|
|
|
# N # and accumulate lines
|
|
|
|
# /pattern2/!ba # until pattern2 is found
|
|
|
|
# s/.*\n// # delete the part before pattern2
|
|
|
|
#}
|
|
|
|
#p
|
2016-11-20 16:41:52 +00:00
|
|
|
# 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
|
2015-11-12 00:37:43 +00:00
|
|
|
|
2016-11-20 16:41:52 +00:00
|
|
|
# Way simpler version of the above, compatible with BSD
|
|
|
|
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
|
|
|
|
QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build." "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-11-12 00:37:43 +00:00
|
|
|
chmod +x ../$PROGRAM.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-11-12 00:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CopyCommons {
|
2016-08-28 19:39:09 +00:00
|
|
|
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot assemble install." "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-28 19:39:09 +00:00
|
|
|
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot change install version." "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-28 19:39:09 +00:00
|
|
|
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
|
|
|
|
QuickLogger "Cannot assemble batch runner." "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-09-08 20:49:51 +00:00
|
|
|
chmod +x ../$PROGRAM-batch.sh
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot chmod $PROGRAM-batch.sh" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-28 19:39:09 +00:00
|
|
|
fi
|
|
|
|
chmod +x ../install.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot chmod install.sh" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-28 19:39:09 +00:00
|
|
|
rm -f ../tmp_install.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot chmod $PROGRAM.sh" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-11-12 00:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Unexpand
|
2016-08-28 19:39:09 +00:00
|
|
|
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then
|
|
|
|
MergeAll
|
|
|
|
else
|
|
|
|
MergeMinimum
|
|
|
|
fi
|
2015-11-12 00:37:43 +00:00
|
|
|
CleanDebug
|
|
|
|
CopyCommons
|
2016-08-28 19:39:09 +00:00
|
|
|
rm -f tmp_$PROGRAM.sh
|
2016-08-30 16:20:41 +00:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
QuickLogger "Cannot remove tmp_$PROGRAM.sh" "stdout"
|
|
|
|
exit 1
|
|
|
|
fi
|