By benqzq
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.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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:
Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.