Coding style compliance

pull/36/head
deajan 9 years ago
parent 4bfe74de59
commit c4388c242b

@ -6,8 +6,13 @@ KNOWN ISSUES
RECENT CHANGES
--------------
- Added LSB info to init script for Debian based distros
- Improved Logging
!- Updated osync to be fully compliant with coding style
- Uploaded coding style manifest
- Integrated new realpath emulation from https://github.com/mkropat/sh-realpath
v0-v1.0x - Jun 2013 - Sep 2015
- Added LSB info to init script for Debian based distros
- 22 Jul. 2015: Osync v1.00a released
- Small improvements in osync-batch.sh time management
- Improved various logging on error

@ -0,0 +1,66 @@
Coding style used for my bash projects (v2 Sep 2015)
1. Indentation
Using tabs
Transform old shell scripts using unexpand command
2. Comments
# Some comment
## Some important comment for the next function
################################################# Some separation
3. Functions
Every word in a function begins with an uppercase (ex: SomeFunctionDoesThings)
Define functions this way. Use sed ':a;N;$!ba;s/\n{\n/ {\n/g' to adapt when opening bracket is on a new line.
function something {
}
If function has some arguments, use local variable names that are more readable than $1...$n. Explain via comments what those variables contain if needed.
function anotherthing {
local var_name="${1}"
local other_var_name="${2}" # This variable contains stuff
}
Functions should always have return status
function thirdthing {
some_command
return $?
}
3.1 Sub functions
When a function is a subroutine of another function, it is called _SomethingAsSubFunction
4. If statements
If statements will be fully written (word "if" must be used). then is written on the same line.
(Use sed ':a;N;$!ba;s/]\n\t*then/]; then/g' to convert files to this format... Replace "],new line, zero or more tabs, then" by "; then")
if [ something ]; then
stuff
else
other stuff
fi
5. Logging
A logging function is available with the following levels of logging:
- DEBUG: Only log this when DEBUG flas is set in program. Any command forged for eval should be logged by this.
- NOTICE: Standard messages
- WARN: Requires attention
- ERROR: Program produced an error but continues execution
- CRITICAL: Program execution is halted
6. Eval
The eval command should always contain 2>1&.
There's a special case where this is needed:
eval "some;commands" 2>> "$LOG_FILE" in order to get error messages into the log.

@ -27,13 +27,15 @@ Some users report osync to work on MacOS X too. Microsoft Windows is supported v
## Installation
Please note that development of version 1.1 has begun. Stable release is v1.01.
Osync has been designed to not delete any data, but rather make backups of conflictual files or soft deletes.
Nevertheless, you should always have a neat backup of your data before trying a new sync tool.
You can download the latest stable release of Osync at www.netpower.fr/osync
You may also get the last development version at https://github.com/deajan/osync with the following command
$ git clone https://github.com/deajan/osync
$ git clone -b "v1.01" https://github.com/deajan/osync
$ sh install.sh
Osync will install itself to /usr/local/bin and an example configuration file will be installed to /etc/osync

@ -6,14 +6,12 @@ SCRIPT_BUILD=2015090801
## Tested on RHEL / CentOS 6 & 7 and Mint 17
## Please adapt this to fit your distro needs
if [ "$(whoami)" != "root" ]
then
if [ "$(whoami)" != "root" ]; then
echo "Must be run as root."
exit 1
fi
if [ ! -d /etc/osync ]
then
if [ ! -d /etc/osync ]; then
mkdir /etc/osync
fi

@ -18,8 +18,7 @@ MAX_EXECUTION_TIME=36000
MAX_RERUNS=3
## Log file path
if [ -w /var/log ]
then
if [ -w /var/log ]; then
LOG_FILE=/var/log/osync-batch.log
else
LOG_FILE=./osync-batch.log
@ -27,8 +26,7 @@ fi
# No need to edit under this line ##############################################################
function Log
{
function Log {
prefix="TIME: $SECONDS - "
echo -e "$prefix$1" >> "$LOG_FILE"
@ -38,8 +36,7 @@ function Log
fi
}
function CheckEnvironment
{
function CheckEnvironment {
## Osync executable full path can be set here if it cannot be found on the system
if ! type -p osync.sh > /dev/null 2>&1
then
@ -58,20 +55,17 @@ function CheckEnvironment
fi
## Check for CONF_FILE_PATH
if [ ! -d "$CONF_FILE_PATH" ]
then
if [ ! -d "$CONF_FILE_PATH" ]; then
Log "Cannot find conf file path $CONF_FILE_PATH"
Usage
fi
}
function Batch
{
function Batch {
## Get list of .conf files
for i in $(ls $CONF_FILE_PATH/*.conf)
do
if [ "$RUN" == "" ]
then
if [ "$RUN" == "" ]; then
RUN="$i"
else
RUN=$RUN" $i"
@ -85,11 +79,9 @@ function Batch
for i in $RUN
do
$OSYNC_EXECUTABLE "$i" $opts
if [ $? != 0 ]
then
if [ $? != 0 ]; then
Log "Run instance $(basename $i) failed"
if [ "RUN_AGAIN" == "" ]
then
if [ "RUN_AGAIN" == "" ]; then
RUN_AGAIN="$i"
else
RUN_AGAIN=$RUN_AGAIN" $i"
@ -104,8 +96,7 @@ function Batch
done
}
function Usage
{
function Usage {
echo "$PROGRAM $PROGRAM_BUILD"
echo $AUTHOR
echo $CONTACT

@ -26,20 +26,17 @@ confdir=/etc/osync
pidfile=/var/run/$prog
SCRIPT_BUILD=1304201502
if [ ! -f $progpath/$progexec ] && [ ! -f $progexec ]
then
if [ ! -f $progpath/$progexec ] && [ ! -f $progexec ]; then
echo "Cannot find $prog executable in $progpath nor in local path."
exit 1
fi
if [ ! -w $(dirname $pidfile) ]
then
if [ ! -w $(dirname $pidfile) ]; then
pidfile=./$prog
fi
start() {
if [ ! -f $confdir/*.conf ]
then
if [ ! -f $confdir/*.conf ]; then
echo "Cannot find any configuration files in $confdir."
exit 1
fi
@ -48,11 +45,9 @@ start() {
for cfgfile in $confdir/*.conf
do
if [ -f $progpath/$progexec ]
then
if [ -f $progpath/$progexec ]; then
$progpath/$progexec $cfgfile --on-changes > /dev/null 2>&1 &
elif [ -f ./$progexec ]
then
elif [ -f ./$progexec ]; then
./$progexec $cfgfile --on-changes > /dev/null 2>&1 &
else
echo "Cannot find $prog executable in $progpath"
@ -62,8 +57,7 @@ start() {
pid=$!
retval=$?
if [ $? == 0 ]
then
if [ $? == 0 ]; then
echo $pid > "$pidfile-$(basename $cfgfile)"
echo "$prog successfully started for configuration file $cfgfile"
else
@ -76,8 +70,7 @@ start() {
}
stop() {
if [ ! -f $pidfile-* ]
then
if [ ! -f $pidfile-* ]; then
echo "No running $prog instances found."
exit 1
fi
@ -87,8 +80,7 @@ stop() {
if ps -p$(cat $pfile) > /dev/null 2>&1
then
kill -TERM $(cat $pfile)
if [ $? == 0 ]
then
if [ $? == 0 ]; then
rm -f $pfile
echo "$prog instance $(basename $pfile) stopped."
else
@ -102,8 +94,7 @@ stop() {
}
status() {
if [ ! -f $pidfile-* ]
then
if [ ! -f $pidfile-* ]; then
echo "Cannot find any running $prog instance."
exit 1
fi

File diff suppressed because it is too large Load Diff

@ -19,14 +19,12 @@ CMD3=
LOG_FILE=~/.ssh/ssh_filter.log
function Log
{
function Log {
DATE=$(date)
echo "$DATE - $1" >> $LOG_FILE
}
function Go
{
function Go {
eval $SSH_ORIGINAL_COMMAND
}
@ -48,31 +46,24 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
"mv")
Go ;;
"$CMD1")
if [ "$CMD1" != "" ]
then
if [ "$CMD1" != "" ]; then
Go ;;
fi
"$CMD2")
if [ "$CMD2" != "" ]
then
if [ "$CMD2" != "" ]; then
Go ;;
fi
"$CMD3")
if [ "$CMD3" != "" ]
then
if [ "$CMD3" != "" ]; then
Go ;;
fi
"sudo")
if [ "$SUDO_EXEC" == "yes" ]
then
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]
then
if [ "$SUDO_EXEC" == "yes" ]; then
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo du"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo du"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]
then
@ -89,22 +80,16 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]]
then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]
then
if [ "$CMD1" != "" ]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then
if [ "$CMD1" != "" ]; then
Go
fi
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]
then
if [ "$CMD2" != "" ]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]; then
if [ "$CMD2" != "" ]; then
Go
fi
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]
then
if [ "$CMD3" != "" ]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]; then
if [ "$CMD3" != "" ]; then
Go
fi
else

Loading…
Cancel
Save