Skip to content

Instantly share code, notes, and snippets.

@discrete-javascript
Last active October 1, 2022 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save discrete-javascript/b0f96aae6f89ff810597dcc457c34519 to your computer and use it in GitHub Desktop.
Save discrete-javascript/b0f96aae6f89ff810597dcc457c34519 to your computer and use it in GitHub Desktop.
Setup for Java, Maven, Git, Jenkins and LAMP
# setup Java, Maven, Git, Jenkins and LAMP in ubuntu
#!/bin/bash
sudo apt-get update
echo "Starting setup"
echo "Will install Java, Maven, Git, Jenkins and LAMP"
process_id=""
resetVar() {
while [ "${#}" -ge 1 ]; do
unset "${1}"
shift
done
}
waitForProcess() {
echo "Waiting for $1 to complete"
local process_id=$1
echo "Process ID: $process_id"
wait $process_id
}
updateAll() {
echo "Updating all"
sudo apt-get update
waitForProcess $!
sudo apt-get upgrade
waitForProcess $!
}
checkFunction() {
echo "Checking if $1 is already installed"
$1 --version
# $? is the exit status of the last executed command.
if [ "$?" = "0" ]; then
echo "$1 is already installed"
else
echo "$1 is not installed"
echo "Installing $1"
sudo apt-get install $1 -y
waitForProcess $!
updateAll
fi
}
resetVar process_id
echo "Checking if java is already installed"
JAVA_VERSION=$(java --version)
if [ "$JAVA_VERSION" = "" ]; then
echo "Java is not installed"
echo "Installing Java"
updateAll
sudo apt install default-jre
updateAll
sudo apt install default-jdk
updateAll
else
echo "Java is already installed"
fi
resetVar JAVA_VERSION
updateAll
checkFunction "maven"
checkFunction "git"
echo "Checking if jenkins is installed"
JENKINS_VERSION=$(sudo service jenkins status)
if [ "$JENKINS_VERSION" = "" ]; then
echo "Jenkins is not installed"
echo "Installing Jenkins"
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
waitForProcess $!
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
waitForProcess $!
updateAll
sudo apt install jenkins -y
waitForProcess $!
echo "Opening the Firewall for 8080 for jenkins"
sudo ufw allow 8080
sudo ufw status
echo "Starting Jenkins"
# sudo systemctl start jenkins
# waitForProcess $!
else
echo "Jenkins is already installed"
fi
resetVar JENKINS_VERSION
LAMPSetup() {
echo "Checking if lamp is installed"
LAMP_VERSION=$(sudo service apache2 status)
if [ "$LAMP_VERSION" = "" ]; then
echo "LAMP is not installed"
echo "Installing LAMP"
sudo apt-get install apache2 apache2-doc apache2-npm-prefork apache2-utils libexpat1 ssl-cert -y
waitForProcess $!
echo "Apache installation completed"
sudo apt-get install mysql-server -y
waitForProcess $!
sudo apt-get install mysql-client libmysqlclient-dev -y
waitForProcess $!
echo "Mysql installation completed"
echo "Installing PHP"
sudo apt-get install php libapache2-mod-php php-mysql -y
waitForProcess $!
echo "PHP installation completed"
echo "Installing PHP extensions"
sudo apt-get install php-common -y
waitForProcess $!
sudo apt-get install php-dev -y
waitForProcess $!
sudo apt-get install php-curl -y
waitForProcess $!
sudo apt-get install php-gd -y
waitForProcess $!
sudo apt-get install php-pear -y
waitForProcess $!
sudo apt-get install php-mbstring -y
waitForProcess $!
sudo apt-get install php-xml -y
waitForProcess $!
sudo apt-get install php-mcrypt -y
waitForProcess $!
sudo apt-get install php-soap -y
waitForProcess $!
sudo apt-get install php-intl -y
waitForProcess $!
sudo apt-get install php-ldap -y
waitForProcess $!
sudo apt-get install php-imagick -y
waitForProcess $!
sudo apt-get install php-ps -y
waitForProcess $!
sudo apt-get install php-xsl -y
waitForProcess $!
sudo apt-get install php-imap -y
waitForProcess $!
sudo apt-get install php-bz2 -y
waitForProcess $!
sudo apt-get install php-json -y
waitForProcess $!
sudo apt-get install php-xmlrpc -y
waitForProcess $!
sudo apt-get install php-zip -y
waitForProcess $!
echo "PHP extensions installation completed"
echo "Installing PHPMyAdmin"
sudo apt-get install phpmyadmin -y
waitForProcess $!
echo "PHPMyAdmin installation completed"
else
echo "LAMP is already installed"
fi
echo "LAMP installation completed"
resetVar LAMP_VERSION
}
LAMPSetup
echo "Setup completed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment