mirror of
https://github.com/deajan/obackup.git
synced 2024-11-15 04:03:41 +01:00
merge.sh
This commit is contained in:
parent
19ee83bb52
commit
0b4a2543d4
114
dev/merge.sh
114
dev/merge.sh
@ -1,10 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
## MERGE 2018062501
|
## MERGE 2018100204
|
||||||
|
|
||||||
## 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=merge
|
||||||
|
INSTANCE_ID=dev
|
||||||
|
|
||||||
function Usage {
|
function Usage {
|
||||||
echo "Merges ofunctions.sh and n_program.sh into debug_program.sh and ../program.sh"
|
echo "Merges ofunctions.sh and n_program.sh into debug_program.sh and ../program.sh"
|
||||||
echo "Usage"
|
echo "Usage"
|
||||||
@ -12,30 +15,24 @@ function Usage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function __PREPROCESSOR_Merge {
|
function __PREPROCESSOR_Merge {
|
||||||
local PROGRAM="$1"
|
local nPROGRAM="$1"
|
||||||
|
|
||||||
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
|
if [ -f "$nPROGRAM" ]; then
|
||||||
|
Logger "$nPROGRAM is not found in local path." "CRITICAL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION=$(grep "PROGRAM_VERSION=" n_$nPROGRAM.sh)
|
||||||
VERSION=${VERSION#*=}
|
VERSION=${VERSION#*=}
|
||||||
__PREPROCESSOR_Constants
|
__PREPROCESSOR_Constants
|
||||||
|
|
||||||
source "ofunctions.sh"
|
__PREPROCESSOR_Unexpand "n_$nPROGRAM.sh" "debug_$nPROGRAM.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"
|
|
||||||
|
|
||||||
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
|
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
|
||||||
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "debug_$PROGRAM.sh"
|
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "debug_$nPROGRAM.sh"
|
||||||
done
|
done
|
||||||
|
|
||||||
__PREPROCESSOR_CleanDebug "$PROGRAM"
|
__PREPROCESSOR_CleanDebug "debug_$nPROGRAM.sh" "../$nPROGRAM.sh"
|
||||||
rm -f tmp_$PROGRAM.sh
|
|
||||||
if [ $? != 0 ]; then
|
|
||||||
Logger "Cannot remove tmp_$PROGRAM.sh" "SIMPLE"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __PREPROCESSOR_Constants {
|
function __PREPROCESSOR_Constants {
|
||||||
@ -46,6 +43,8 @@ function __PREPROCESSOR_Constants {
|
|||||||
__PREPROCESSOR_SUBSETS=(
|
__PREPROCESSOR_SUBSETS=(
|
||||||
'#### OFUNCTIONS FULL SUBSET ####'
|
'#### OFUNCTIONS FULL SUBSET ####'
|
||||||
'#### OFUNCTIONS MINI SUBSET ####'
|
'#### OFUNCTIONS MINI SUBSET ####'
|
||||||
|
'#### OFUNCTIONS MICRO SUBSET ####'
|
||||||
|
'#### PoorMansRandomGenerator SUBSET ####'
|
||||||
'#### _OFUNCTIONS_BOOTSTRAP SUBSET ####'
|
'#### _OFUNCTIONS_BOOTSTRAP SUBSET ####'
|
||||||
'#### DEBUG SUBSET ####'
|
'#### DEBUG SUBSET ####'
|
||||||
'#### TrapError SUBSET ####'
|
'#### TrapError SUBSET ####'
|
||||||
@ -60,6 +59,7 @@ function __PREPROCESSOR_Constants {
|
|||||||
'#### GetConfFileValue SUBSET ####'
|
'#### GetConfFileValue SUBSET ####'
|
||||||
'#### SetConfFileValue SUBSET ####'
|
'#### SetConfFileValue SUBSET ####'
|
||||||
'#### CheckRFC822 SUBSET ####'
|
'#### CheckRFC822 SUBSET ####'
|
||||||
|
'#### CleanUp SUBSET ####'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,34 +110,45 @@ function __PREPROCESSOR_MergeSubset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function __PREPROCESSOR_CleanDebug {
|
function __PREPROCESSOR_CleanDebug {
|
||||||
local PROGRAM="$1"
|
local source="${1}"
|
||||||
|
local destination="${2:-$source}"
|
||||||
|
|
||||||
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' "$source" | grep -v "$PARANOIA_DEBUG_LINE" > "$destination.tmp"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot remove PARANOIA_DEBUG code from standard build." "SIMPLE"
|
Logger "Cannot remove PARANOIA_DEBUG code from standard build." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
|
else
|
||||||
|
mv -f "$destination.tmp" "$destination"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
Logger "Cannot move [$destination.tmp] to [$destination]." "SIMPLE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod +x "debug_$PROGRAM.sh"
|
chmod +x "$source"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot chmod debug_$PROGRAM.sh" "SIMPLE"
|
Logger "Cannot chmod [$source]." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
Logger "Prepared ./debug_$PROGRAM.sh" "SIMPLE"
|
Logger "Prepared [$source]." "SIMPLE"
|
||||||
fi
|
fi
|
||||||
chmod +x "../$PROGRAM.sh"
|
|
||||||
if [ $? != 0 ]; then
|
if [ "$source" != "$destination" ]; then
|
||||||
Logger "Cannot chmod $PROGRAM.sh" "SIMPLE"
|
|
||||||
exit 1
|
chmod +x "$destination"
|
||||||
else
|
if [ $? != 0 ]; then
|
||||||
Logger "Prepared ../$PROGRAM.sh" "SIMPLE"
|
Logger "Cannot chmod [$destination]." "SIMPLE"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
Logger "Prepared [$destination]." "SIMPLE"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __PREPROCESSOR_CopyCommons {
|
function __PREPROCESSOR_CopyCommons {
|
||||||
local PROGRAM="$1"
|
local nPROGRAM="$1"
|
||||||
|
|
||||||
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../install.sh
|
sed "s/\[prgname\]/$nPROGRAM/g" common_install.sh > ../install.sh
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot assemble install." "SIMPLE"
|
Logger "Cannot assemble install." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
@ -147,45 +158,34 @@ function __PREPROCESSOR_CopyCommons {
|
|||||||
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "../install.sh"
|
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "../install.sh"
|
||||||
done
|
done
|
||||||
|
|
||||||
#sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
|
__PREPROCESSOR_CleanDebug "../install.sh"
|
||||||
#if [ $? != 0 ]; then
|
|
||||||
# Logger "Cannot change install version." "SIMPLE"
|
|
||||||
# exit 1
|
|
||||||
#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\]/$nPROGRAM/g" common_batch.sh > ../$nPROGRAM-batch.sh
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot assemble batch runner." "SIMPLE"
|
Logger "Cannot assemble batch runner." "SIMPLE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
chmod +x ../$PROGRAM-batch.sh
|
|
||||||
if [ $? != 0 ]; then
|
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
|
||||||
Logger "Cannot chmod $PROGRAM-batch.sh" "SIMPLE"
|
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "../$nPROGRAM-batch.sh"
|
||||||
exit 1
|
done
|
||||||
else
|
|
||||||
Logger "Prepared ../$PROGRAM-batch.sh" "SIMPLE"
|
__PREPROCESSOR_CleanDebug "../$nPROGRAM-batch.sh"
|
||||||
fi
|
|
||||||
fi
|
|
||||||
chmod +x ../install.sh
|
|
||||||
if [ $? != 0 ]; then
|
|
||||||
Logger "Cannot chmod install.sh" "SIMPLE"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
Logger "Prepared ../install.sh" "SIMPLE"
|
|
||||||
fi
|
|
||||||
rm -f ../tmp_install.sh
|
|
||||||
if [ $? != 0 ]; then
|
|
||||||
Logger "Cannot chmod $PROGRAM.sh" "SIMPLE"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# If sourced don't do anything
|
# If sourced don't do anything
|
||||||
if [ "$(basename $0)" == "merge.sh" ]; then
|
if [ "$(basename $0)" == "merge.sh" ]; then
|
||||||
if [ "$1" == "osync" ]; then
|
source "./ofunctions.sh"
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
echo "Please run $0 in dev directory with ofunctions.sh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
trap GenericTrapQuit TERM EXIT HUP QUIT
|
||||||
|
|
||||||
|
if [ "$1" == "osync" ]; then
|
||||||
__PREPROCESSOR_Merge osync
|
__PREPROCESSOR_Merge osync
|
||||||
__PREPROCESSOR_Merge osync_target_helper
|
|
||||||
__PREPROCESSOR_CopyCommons osync
|
__PREPROCESSOR_CopyCommons osync
|
||||||
elif [ "$1" == "obackup" ]; then
|
elif [ "$1" == "obackup" ]; then
|
||||||
__PREPROCESSOR_Merge obackup
|
__PREPROCESSOR_Merge obackup
|
||||||
|
Loading…
Reference in New Issue
Block a user