Minor changes & fixes
This commit is contained in:
parent
28460a714e
commit
bd28ca8837
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## dev pre-processor bootstrap rev 2016120701
|
||||
## dev pre-processor bootstrap rev 2016121101
|
||||
## Yeah !!! A really tech sounding name... In fact it's just include emulation in bash
|
||||
|
||||
outputFileName="$0"
|
||||
|
@ -11,7 +11,7 @@ __PREPROCESSOR_Constants
|
|||
|
||||
cp "n_$__PREPROCESSOR_PROGRAM.sh" "$outputFileName.tmp.sh"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot copy original file [n_$__PREPROCESSOR_PROGRAM.sh] to [$outputFileName.tmp.sh]." "stderr"
|
||||
echo "Cannot copy original file [n_$__PREPROCESSOR_PROGRAM.sh] to [$outputFileName.tmp.sh]."
|
||||
exit 1
|
||||
fi
|
||||
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
|
||||
|
@ -19,7 +19,7 @@ for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
|
|||
done
|
||||
chmod +x "$0.tmp.sh"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot make [$outputFileName] executable.." "stderr"
|
||||
echo "Cannot make [$outputFileName] executable.."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -29,4 +29,3 @@ if type termux-fix-shebang > /dev/null 2>&1; then
|
|||
fi
|
||||
|
||||
"$outputFileName.tmp.sh" "$@"
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
include #### _OFUNCTIONS_BOOTSTRAP SUBSET ####
|
||||
|
||||
PROGRAM=[prgname]
|
||||
PROGRAM_VERSION=[version]
|
||||
PROGRAM_BINARY=$PROGRAM".sh"
|
||||
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
||||
SCRIPT_BUILD=2016120801
|
||||
SCRIPT_BUILD=2016121101
|
||||
|
||||
## osync / obackup / pmocr / zsnap install script
|
||||
## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8 & 10
|
||||
|
@ -42,73 +44,20 @@ else
|
|||
LOG_FILE="./$PROGRAM-install.log"
|
||||
fi
|
||||
|
||||
# Generic quick logging function
|
||||
function _QuickLogger {
|
||||
local value="${1}"
|
||||
local destination="${2}" # Destination: stdout, log, both
|
||||
|
||||
if ([ "$destination" == "log" ] || [ "$destination" == "both" ]); then
|
||||
echo -e "$(date) - $value" >> "$LOG_FILE"
|
||||
elif ([ "$destination" == "stdout" ] || [ "$destination" == "both" ]); then
|
||||
echo -e "$value"
|
||||
fi
|
||||
}
|
||||
|
||||
function QuickLogger {
|
||||
local value="${1}"
|
||||
|
||||
if [ "$_SILENT" -eq 1 ]; then
|
||||
_QuickLogger "$value" "log"
|
||||
else
|
||||
_QuickLogger "$value" "stdout"
|
||||
fi
|
||||
}
|
||||
|
||||
function UrlEncode() {
|
||||
# urlencode <string>
|
||||
|
||||
local LANG=C
|
||||
local length="${#1}"
|
||||
for (( i = 0; i < length; i++ )); do
|
||||
local c="${1:i:1}"
|
||||
case $c in
|
||||
[a-zA-Z0-9.~_-]) printf "$c" ;;
|
||||
*) printf '%%%02X' "'$c" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
function SetOSSettings {
|
||||
local localOsVar
|
||||
|
||||
include #### QuickLogger SUBSET ####
|
||||
include #### UrlEncode SUBSET ####
|
||||
include #### GetLocalOS SUBSET ####
|
||||
function SetLocalOSSettings {
|
||||
USER=root
|
||||
|
||||
# There's no good way to tell if currently running in BusyBox shell. Using sluggish way.
|
||||
if ls --help 2>&1 | grep -i "BusyBox" > /dev/null; then
|
||||
localOsVar="BusyBox"
|
||||
else
|
||||
# Detecting the special ubuntu userland in Windows 10 bash
|
||||
if grep -i Microsoft /proc/sys/kernel/osrelease > /dev/null 2>&1; then
|
||||
localOsVar="Microsoft"
|
||||
else
|
||||
localOsVar="$(uname -spio 2>&1)"
|
||||
if [ $? != 0 ]; then
|
||||
localOsVar="$(uname -v 2>&1)"
|
||||
if [ $? != 0 ]; then
|
||||
localOsVar="$(uname)"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
case $localOsVar in
|
||||
case $LOCAL_OS in
|
||||
*"BSD"*)
|
||||
GROUP=wheel
|
||||
;;
|
||||
*"Darwin"*)
|
||||
*"MacOSX"*)
|
||||
GROUP=admin
|
||||
;;
|
||||
*"MINGW"*|*"CYGWIN"*)
|
||||
*"msys"*|*"Cygwin"*)
|
||||
USER=""
|
||||
GROUP=""
|
||||
;;
|
||||
|
@ -117,6 +66,11 @@ function SetOSSettings {
|
|||
;;
|
||||
esac
|
||||
|
||||
if [ "$LOCAL_OS" == "Android" ] || [ "$LOCAL_OS" == "MacOSX" ] || [ "$LOCAL_OS" == "BusyBox" ]; then
|
||||
QuickLogger "Cannot be installed on [$LOCAL_OS]. Please use $PROGRAM.sh directly."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then
|
||||
QuickLogger "Must be run as $USER."
|
||||
exit 1
|
||||
|
@ -308,7 +262,8 @@ if [ "$FAKEROOT" != "" ]; then
|
|||
mkdir -p "$SERVICE_DIR_SYSTEMD_SYSTEM" "$SERVICE_DIR_SYSTEMD_USER" "$BIN_DIR"
|
||||
fi
|
||||
|
||||
SetOSSettings
|
||||
GetLocalOS
|
||||
SetLocalOSSettings
|
||||
CreateConfDir
|
||||
CopyExampleFiles
|
||||
CopyProgram
|
||||
|
|
48
dev/merge.sh
48
dev/merge.sh
|
@ -28,7 +28,7 @@ function __PREPROCESSOR_Merge {
|
|||
__PREPROCESSOR_CopyCommons
|
||||
rm -f tmp_$PROGRAM.sh
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot remove tmp_$PROGRAM.sh" "stderr"
|
||||
QuickLogger "Cannot remove tmp_$PROGRAM.sh"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -45,7 +45,10 @@ function __PREPROCESSOR_Constants {
|
|||
'#### DEBUG SUBSET ####'
|
||||
'#### TrapError SUBSET ####'
|
||||
'#### RemoteLogger SUBSET ####'
|
||||
'#### QuickLogger SUBSET ####'
|
||||
'#### GetLocalOS SUBSET ####'
|
||||
'#### IsInteger SUBSET ####'
|
||||
'#### UrlEncode SUBSET ####'
|
||||
'#### HumanToNumeric SUBSET ####'
|
||||
'#### ArrayContains SUBSET ####'
|
||||
)
|
||||
|
@ -57,7 +60,7 @@ function __PREPROCESSOR_Unexpand {
|
|||
|
||||
unexpand "$source" > "$destination"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot unexpand [$source] to [$destination]." "stderr"
|
||||
QuickLogger "Cannot unexpand [$source] to [$destination]."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -70,29 +73,29 @@ function __PREPROCESSOR_MergeSubset {
|
|||
|
||||
sed -n "/$subsetBegin/,/$subsetEnd/p" "$subsetFile" > "$subsetFile.$subsetBegin"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]." "stderr"
|
||||
QuickLogger "Cannot sed subset [$subsetBegin -- $subsetEnd] in [$subsetFile]."
|
||||
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"
|
||||
QuickLogger "Cannot add subset [$subsetBegin] to [$mergedFile]."
|
||||
exit 1
|
||||
fi
|
||||
rm -f "$subsetFile.$subsetBegin"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot remove temporary subset [$subsetFile.$subsetBeign]." "stderr"
|
||||
QuickLogger "Cannot remove temporary subset [$subsetFile.$subsetBegin]."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f "$mergedFile"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot remove merged original file [$mergedFile]." "stderr"
|
||||
QuickLogger "Cannot remove merged original file [$mergedFile]."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv "$mergedFile.tmp" "$mergedFile"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot move merged tmp file to original [$mergedFile]." "stderr"
|
||||
QuickLogger "Cannot move merged tmp file to original [$mergedFile]."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
@ -100,53 +103,66 @@ function __PREPROCESSOR_MergeSubset {
|
|||
function __PREPROCESSOR_CleanDebug {
|
||||
sed '/'$PARANOIA_DEBUG_BEGIN'/,/'$PARANOIA_DEBUG_END'/d' debug_$PROGRAM.sh | grep -v "$PARANOIA_DEBUG_LINE" > ../$PROGRAM.sh
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build." "stderr"
|
||||
QuickLogger "Cannot remove PARANOIA_DEBUG code from standard build."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
chmod +x "debug_$PROGRAM.sh"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot chmod debug_$PROGRAM.sh" "stderr"
|
||||
QuickLogger "Cannot chmod debug_$PROGRAM.sh"
|
||||
exit 1
|
||||
else
|
||||
QuickLogger "Prepared ./debug_$PROGRAM.sh"
|
||||
fi
|
||||
chmod +x "../$PROGRAM.sh"
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot chmod $PROGRAM.sh" "stderr"
|
||||
QuickLogger "Cannot chmod $PROGRAM.sh"
|
||||
exit 1
|
||||
else
|
||||
QuickLogger "Prepared ../$PROGRAM.sh"
|
||||
fi
|
||||
}
|
||||
|
||||
function __PREPROCESSOR_CopyCommons {
|
||||
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot assemble install." "stderr"
|
||||
QuickLogger "Cannot assemble install."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for subset in "${__PREPROCESSOR_SUBSETS[@]}"; do
|
||||
__PREPROCESSOR_MergeSubset "$subset" "${subset//SUBSET/SUBSET END}" "ofunctions.sh" "../tmp_install.sh"
|
||||
done
|
||||
|
||||
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot change install version." "stderr"
|
||||
QuickLogger "Cannot change install version."
|
||||
exit 1
|
||||
fi
|
||||
if [ -f "common_batch.sh" ]; then
|
||||
sed "s/\[prgname\]/$PROGRAM/g" common_batch.sh > ../$PROGRAM-batch.sh
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot assemble batch runner." "stderr"
|
||||
QuickLogger "Cannot assemble batch runner."
|
||||
exit 1
|
||||
fi
|
||||
chmod +x ../$PROGRAM-batch.sh
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot chmod $PROGRAM-batch.sh" "stderr"
|
||||
QuickLogger "Cannot chmod $PROGRAM-batch.sh"
|
||||
exit 1
|
||||
else
|
||||
QuickLogger "Prepared ../$PROGRAM-batch.sh"
|
||||
fi
|
||||
fi
|
||||
chmod +x ../install.sh
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot chmod install.sh" "stderr"
|
||||
QuickLogger "Cannot chmod install.sh"
|
||||
exit 1
|
||||
else
|
||||
QuickLogger "Prepared ../install.sh"
|
||||
fi
|
||||
rm -f ../tmp_install.sh
|
||||
if [ $? != 0 ]; then
|
||||
QuickLogger "Cannot chmod $PROGRAM.sh" "stderr"
|
||||
QuickLogger "Cannot chmod $PROGRAM.sh"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#### OFUNCTIONS MINI SUBSET ####
|
||||
|
||||
_OFUNCTIONS_VERSION=2.1-dev
|
||||
_OFUNCTIONS_BUILD=2016121106
|
||||
_OFUNCTIONS_BUILD=2016121107
|
||||
#### _OFUNCTIONS_BOOTSTRAP SUBSET ####
|
||||
_OFUNCTIONS_BOOTSTRAP=true
|
||||
#### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
|
||||
|
@ -271,13 +271,12 @@ function Logger {
|
|||
}
|
||||
#### Logger SUBSET END ####
|
||||
|
||||
#### QuickLogger SUBSET ####
|
||||
# QuickLogger subfunction, can be called directly
|
||||
function _QuickLogger {
|
||||
local value="${1}"
|
||||
local destination="${2}" # Destination: stdout, log, both
|
||||
|
||||
__CheckArguments 2 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||
|
||||
if ([ "$destination" == "log" ] || [ "$destination" == "both" ]); then
|
||||
echo -e "$(date) - $value" >> "$LOG_FILE"
|
||||
elif ([ "$destination" == "stdout" ] || [ "$destination" == "both" ]); then
|
||||
|
@ -289,14 +288,13 @@ function _QuickLogger {
|
|||
function QuickLogger {
|
||||
local value="${1}"
|
||||
|
||||
__CheckArguments 1 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||
|
||||
if [ $_LOGGER_SILENT == true ]; then
|
||||
if [ "$_LOGGER_SILENT" == true ]; then
|
||||
_QuickLogger "$value" "log"
|
||||
else
|
||||
_QuickLogger "$value" "stdout"
|
||||
fi
|
||||
}
|
||||
#### QuickLogger SUBSET END ####
|
||||
|
||||
# Portable child (and grandchild) kill function tester under Linux, BSD and MacOS X
|
||||
function KillChilds {
|
||||
|
@ -1045,6 +1043,7 @@ function HumanToNumeric {
|
|||
}
|
||||
#### HumanToNumeric SUBSET END ####
|
||||
|
||||
#### UrlEncode SUBSET ####
|
||||
## from https://gist.github.com/cdown/1163649
|
||||
function UrlEncode {
|
||||
local length="${#1}"
|
||||
|
@ -1062,6 +1061,7 @@ function UrlEncode {
|
|||
esac
|
||||
done
|
||||
}
|
||||
#### UrlEncode SUBSET END ####
|
||||
|
||||
function UrlDecode {
|
||||
local urlEncoded="${1//+/ }"
|
||||
|
@ -1090,9 +1090,8 @@ function ArrayContains () {
|
|||
}
|
||||
#### ArrayContains SUBSET END ####
|
||||
|
||||
#### GetLocalOS SUBSET ####
|
||||
function GetLocalOS {
|
||||
__CheckArguments 0 $# "$@" #__WITH_PARANOIA_DEBUG
|
||||
|
||||
local localOsVar
|
||||
|
||||
# There's no good way to tell if currently running in BusyBox shell. Using sluggish way.
|
||||
|
@ -1144,12 +1143,17 @@ function GetLocalOS {
|
|||
Logger "Running on unknown local OS [$localOsVar]." "WARN"
|
||||
return
|
||||
fi
|
||||
if [ "$_OFUNCTIONS_VERSION" != "" ]; then
|
||||
Logger "Running on >> $localOsVar << not supported. Please report to the author." "ERROR"
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
if [ "$_OFUNCTIONS_VERSION" != "" ]; then
|
||||
Logger "Local OS: [$localOsVar]." "DEBUG"
|
||||
fi
|
||||
}
|
||||
#### GetLocalOS SUBSET END ####
|
||||
|
||||
#### OFUNCTIONS MINI SUBSET END ####
|
||||
|
||||
|
|
Loading…
Reference in New Issue