Basic Nginx server environment creation script
Error handling

The script misses error handling at several places.
The downloads could fail or be corrupt,
but the script will continue until the end,
and finding the failure point can be difficult.
Worse, if a failure is quiet enough,
it might not even get noticed.

Checking the exit code of every single command can be tedious.
An alternative is to add this near the top of the script:

set -euo pipefail


This will cause the script abort on the first failure,
and also treat suspicious operations as failure.

Long lines

Long lines are harder to read.
Instead of this:


cd /usr/local/src &amp;&amp; wget http://www.rfxn.com/downloads/maldetect-current.tar.gz &amp;&amp; tar -xzf maldetect-current.tar.gz



It would be easier to read with one line per command:

cd /usr/local/src \
  &amp;&amp; wget http://www.rfxn.com/downloads/maldetect-current.tar.gz \
  &amp;&amp; tar -xzf maldetect-current.tar.gz


Changing directories in scripts

Be careful with changing directories in scripts.
If an error happens in the middle of the operation,
the next operation may find itself in an unexpected directory (in the absence of adequate error handling).

Changing directories can become safer using (...) sub-shells.
For example instead of this, with a cd ~ at the end:


cd /usr/local/src &amp;&amp; wget http://www.rfxn.com/downloads/maldetect-current.tar.gz &amp;&amp; tar -xzf maldetect-current.tar.gz
cd maldetect-* &amp;&amp; bash ./install.sh &amp;&amp; cd ~



You could do this, without the need for the cd ~ at the end:

(
    cd /usr/local/src &amp;&amp; wget http://www.rfxn.com/downloads/maldetect-current.tar.gz &amp;&amp; tar -xzf maldetect-current.tar.gz
    cd maldetect-* &amp;&amp; bash ./install.sh
)


Function declaration style

This is the recommended writing style:

nginx() {
    # ...
}


That is, no function keyword, and () after the name.

I would also give this function a more descriptive name.

Tips

Instead of:


mkdir /root/backups /root/backups/db /root/backups/dirs



You could write more compactly as:

mkdir -p /root/backups/{db,dirs}


Instead of cd ~, you could write simply cd.