mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
complete refactoring for start-mailserver.sh
(#1605)
* completely refactored `start-mailserver.sh` * added braces; correctly formatted tabs / spaces * included `start-mailserver` into shellcheck checks * cleanup * removed unnecessary shellcheck comments adding braces and "" where necessary * corrected some mistakes in CONTRIBUTING * Makefile now uses correct shellcheck
This commit is contained in:
parent
9b5d4d307c
commit
566eaa0e13
|
@ -51,10 +51,10 @@ The development workflow is the following:
|
|||
|
||||
### Bash and Shell
|
||||
|
||||
When refactoring, writing or altering Script, that is Shell and Bash scripts, in any way, adhere to these rules:
|
||||
When refactoring, writing or altering scripts, that is Shell and Bash scripts, in any way, adhere to these rules:
|
||||
|
||||
1. **Adjust your style of coding to the style that is already present**! Even if you do not like it, this is due to consistency. Look up the GNU coding style guide. There was a lot of work involved in making these scripts consistent.
|
||||
2. **Use `shellcheck` to check your scripts**! Your contributions are checked by TravisCI with shellcheck.
|
||||
2. **Use `shellcheck` to check your scripts**! Your contributions are checked by TravisCI with shellcheck. You can check your scripts like Travis with `make shellcheck`.
|
||||
3. There is a **`.editorconfig`** file. Make your IDE use it or adhere to it manually!
|
||||
4. It's okay to use `/bin/bash` instead of `/bin/sh`. You can alternatively use `/usr/bin/env bash`.
|
||||
5. `setup.sh` provides a good starting point to look for.
|
||||
|
@ -84,15 +84,15 @@ When writing a script, provide the version and the script's task. We use [semant
|
|||
if [[ <CONDITION1> ]] && [[ -f ${FILE} ]]
|
||||
then
|
||||
<CODE TO RUN>
|
||||
# when running code, you don't need them
|
||||
# when running commands, you don't need braces
|
||||
elif <COMMAND TO RUN>
|
||||
<CODE TO TUN>
|
||||
else
|
||||
<CODE TO TUN>
|
||||
fi
|
||||
|
||||
# equality checks with numbers, use
|
||||
# -eq/-ne/-lt/-ge, not != or ==
|
||||
# equality checks with numbers are done
|
||||
# with -eq/-ne/-lt/-ge, not != or ==
|
||||
if [[ $VAR -ne 42 ]] || [[ $SOME_VAR -eq 6 ]]
|
||||
then
|
||||
<CODE TO RUN>
|
||||
|
@ -133,7 +133,7 @@ function _<name_underscored_and_lowercase>()
|
|||
<CODE TO RUN>
|
||||
|
||||
# variables that can be local should be local
|
||||
local _<LOCAL_VARIABLE_NAME>
|
||||
local <LOCAL_VARIABLE_NAME>
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -157,23 +157,6 @@ function _report_err()
|
|||
|
||||
Comments should only describe non-obvious matters. Comments should start lowercase when they aren't sentences. Make the code **self-descriptive** by using meaningful names! Make comments not longer than approximately 80 columns, then wrap the line.
|
||||
|
||||
A negative example:
|
||||
|
||||
``` BASH
|
||||
# adds one to the first argument and print it to stdout
|
||||
function _add_one()
|
||||
{
|
||||
# save the first variable
|
||||
local FIRST=$1
|
||||
|
||||
# add one here
|
||||
local RESULT=$(( _FIRST + 1 ))
|
||||
|
||||
# print it to stdout
|
||||
echo "$_RESULT"
|
||||
}
|
||||
```
|
||||
|
||||
A positive example:
|
||||
|
||||
``` BASH
|
||||
|
@ -184,14 +167,31 @@ function _add_one()
|
|||
}
|
||||
```
|
||||
|
||||
A negative example:
|
||||
|
||||
``` BASH
|
||||
# adds one to the first argument and print it to stdout
|
||||
function _add_one()
|
||||
{
|
||||
# save the first variable
|
||||
local FIRST=$1
|
||||
|
||||
# add one here
|
||||
local RESULT=$(( FIRST + 1 ))
|
||||
|
||||
# print it to stdout
|
||||
echo "$_RESULT"
|
||||
}
|
||||
```
|
||||
|
||||
### YAML
|
||||
|
||||
When formatting YAML files, you can opt for [Prettier][prettier]. There are any plugins for IDEs around.
|
||||
When formatting YAML files, you can opt for [Prettier][prettier]. There are many plugins for IDEs around.
|
||||
|
||||
[//]: # (Links)
|
||||
|
||||
[commit]: https://help.github.com/articles/closing-issues-via-commit-messages/
|
||||
[gpg]: https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key
|
||||
[semver]: https://semver.org/
|
||||
[regex]: https://regex101.com/r/ikzJpF/4
|
||||
[regex]: https://regex101.com/r/ikzJpF/5
|
||||
[prettier]: https://prettier.io
|
||||
|
|
4
Makefile
4
Makefile
|
@ -167,11 +167,9 @@ shellcheck:
|
|||
@ echo -e "Testing shell / bash scripts with shellcheck\n"
|
||||
@ /usr/bin/shellcheck --version
|
||||
@ echo ''
|
||||
# currently without `start-mailserver` as this is to be merged separately
|
||||
@ if find -iname "*.sh" -not -path "./test/*" -not -path "./target/docker-configomat/*" -not -wholename ./target/start-mailserver.sh -exec /usr/bin/shellcheck -S style -Cauto -o all -e SC2250,SC2154 -W 50 {} \; | grep .; then\
|
||||
@ if find -iname "*.sh" -not -path "./test/*" -not -path "./target/docker-configomat/*" -exec /usr/bin/shellcheck -S style -Cauto -o all -e SC2154 -W 50 {} \; | grep .; then\
|
||||
echo -e "\nError" ;\
|
||||
exit 1 ;\
|
||||
else\
|
||||
echo -e '\nSuccess' ;\
|
||||
fi
|
||||
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
# Report a quota usage warning to an user
|
||||
|
||||
PERCENT=$1
|
||||
USER=$2
|
||||
DOMAIN=$3
|
||||
PERCENT="${1}"
|
||||
USER="${2}"
|
||||
DOMAIN="${3}"
|
||||
|
||||
# shellcheck disable=SC2250
|
||||
cat << EOF | /usr/lib/dovecot/dovecot-lda -d "$USER" -o "plugin/quota=maildir:User quota:noenforcing"
|
||||
From: postmaster@$DOMAIN
|
||||
Subject: quota warning
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue