Created
October 4, 2019 05:49
-
-
Save yashhere/910648acc88a490c5f60e7c219f11373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
set -e | |
set -o nounset # Exit, with error message, when attempting to use an undefined variable. | |
set -o errexit # Abort script at first error, when a command exits with non-zero status. | |
set -o pipefail # Returns exit status of the last command in the pipe that returned a non-zero return value. | |
IFS=$'\n\t' # Defines how Bash splits words and iterates arrays. This defines newlines and tabs as delimiters. | |
export INSTALL_COMMAND="apt-get -q -y" | |
output_file="output.log" | |
# Set the machine's timezone | |
# Arguments: | |
# tz data timezone | |
function setTimezone() { | |
local timezone=${1} | |
echo "${1}" | sudo tee /etc/timezone | |
sudo ln -fs "/usr/share/zoneinfo/${timezone}" /etc/localtime # https://bugs.launchpad.net/ubuntu/+source/tzdata/+bug/1554806 | |
sudo dpkg-reconfigure -f noninteractive tzdata | |
} | |
# Gets the amount of physical memory in GB (rounded up) installed on the machine | |
function getPhysicalMemory() { | |
local phymem | |
phymem="$(free -g|awk '/^Mem:/{print $2}')" | |
if [[ ${phymem} == '0' ]]; then | |
echo 1 | |
else | |
echo "${phymem}" | |
fi | |
} | |
function setupTimezone() { | |
echo -ne "Enter the timezone for the server (Default is 'Asia/Kolkata'):\n" >&3 | |
read -r timezone | |
if [ -z "${timezone}" ]; then | |
timezone="Asia/Kolkata" | |
fi | |
setTimezone "${timezone}" | |
echo "Timezone is set to $(cat /etc/timezone)" >&3 | |
} | |
function installPackages() { | |
# EXECUTION | |
# Initialization | |
$INSTALL_COMMAND update | |
$INSTALL_COMMAND upgrade | |
# Build Tools | |
$INSTALL_COMMAND install build-essential # Essential for compiling source (includes GCC compiler, etc). | |
$INSTALL_COMMAND install libreadline6 libreadline6-dev # CLI. | |
$INSTALL_COMMAND install zlib1g zlib1g-dev # Compression. | |
$INSTALL_COMMAND install libssl-dev # SSL. | |
$INSTALL_COMMAND install libpcre3 libpcre3-dev # Regular Expressions. | |
$INSTALL_COMMAND install libyaml-dev # YAML. | |
$INSTALL_COMMAND install libxml2-dev # XML. | |
$INSTALL_COMMAND install libxslt-dev # XSLT. | |
# Package Management | |
$INSTALL_COMMAND install python-software-properties # Provides the "add-apt-repository" command. | |
# Git | |
$INSTALL_COMMAND install git-core | |
# Java | |
$INSTALL_COMMAND install default-jdk default-jre | |
# Docker | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" | |
$INSTALL_COMMAND install docker-ce docker-compose | |
usermod -aG docker ${USER} | |
} | |
function main() { | |
setupTimezone | |
installPackages | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment