Automated Package Installation and Configuration Script for Ubuntu

In my last post, I discussed about how I created my first Amazon EC2 instance and ran our Java web server on it. One of the most important things that I have realized over the years is that if you work with a small group of developers, you ought to think about automating certain jobs like testing, deployment, setting up server etc. So that you can concentrate on the real work rather than spending valuable time in doing repetitive tasks. The benefit against spending extra time in writing scripts may not be prominent at first, but over time you will realize the gain in terms of person hours and headaches saved because of the automated scripts.

Soon after creating the remote instance on cloud, I created a simple script to push and deploy the changes to AWS. Nothing fancy, you will still need to trigger it manually, but helpful nonetheless. My plan is to later create a script hooked to our online code repository to detect any changes being pushed and trigger the deployment automatically. But in the next weekend after that, I created a script to quickly configure the server after being created, installing and configuring the most basic packages including Java, Mysql-server, firewall etc.

The script basically does the below jobs:

  1. It installs the following packages – default-jre and mysql-server. Along with that, it also installs a couple of packages which are needed to automate the installation of other packages or the execution of other scripts.
  2. It executes the ‘mysql_secure_installation’ script to make the mysql server permissions more restricted and to disable some of the default configurations. It uses an expect script to automatically provide the input while the script is executed and it does not require any user interaction.
  3. It enables the ufw (uncomplicated firewall) and allows the given http port. The port number is mentioned as a configuration in the script itself.

The script should be run with administrative privilege and the root password for the mysql-server should be passed as the only command line argument to the script. Sample usage command is as followed –

sudo ./automate.sh <mysql_root_password>

The script is tested on Ubuntu Server 16.04. To execute the script on other versions of Ubuntu, the mysql-server version number needs to be updated in the script. The source code is hosted on my Github account and it can be accessed via this link.

Advertisements

I am a software engineer, an open-source enthusiast and a hobbyist blogger.

Tagged with: , , , , ,
Posted in Blog, Shell, Ubuntu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: