Question

Please review my 12 lines Ubuntu-Nginx environment script

Posted January 22, 2018 811 views
NginxUbuntu 16.04

Please review my 12 lines Ubuntu-Nginx environment script:

#!/bin/bash
ufw --force enable && ufw allow 22,25,80,443,9000/tcp
apt-get update -y && add-apt-repository ppa:certbot/certbot -y && apt-get update -y
apt-get upgrade zip unzip tree unattended-upgrades sshguard nginx python-certbot-nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
DEBIAN_FRONTEND=noninteractive apt-get upgrade postfix -y
sed -i "s/post_max_size = .M/post_max_size = 250M/ ; s/upload_max_filesize = .M/upload_max_filesize = 250M/" /etc/php/*/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/*/fpm/php.ini
wget -P ~/myAddons/ https://raw.githubusercontent.com/benqzq/unse/master/{nwsm.sh,pma.sh,imb.sh,daily.sh,weekly.sh,appendix.sh}
curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > /usr/local/bin/wp
echo -e "0 0 * * * ~/myAddons/daily.sh \n0 0 * * 0 ~/myAddons/weekly.sh" | crontab
chmod +x ~/myAddons/* /usr/local/bin/wp && source ~/myAddons/appendix.sh && rss
# sed -i "s/# gzip_/gzip_/g" /etc/nginx/nginx.conf

What can I shorten/automate here? It feels to me a bit heavy, even though it is quite short.

Comfortable Github link.

edited by kamaln7

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello,

The script looks alright. What I could suggest maybe is adding some error handling with some if the conditions to stop the script if any of the commands fail.

For example, you could add the following:

# exit when any command fails
set -e

That way the script would stop if any of the commands fail.

I usually use this site here to check my shell scripts for some issues and advises on best practices:

https://www.shellcheck.net/

Regards,
Bobby

Submit an Answer