Update before_install.sh

This commit is contained in:
Chigozirim Igweamaka 2024-05-18 11:07:03 +01:00 committed by GitHub
parent 8863b2373c
commit d2dd1069bd

View file

@ -1,33 +1,43 @@
#!/usr/bin/env bash
sudo apt-get -y update
# sudo rm -rf /home/ubuntu/install
set -e # Exit immediately if a command exits with a non-zero status
set -x # Print commands and their arguments as they are executed
# Log function to capture error messages
log() {
echo "$1" >> /var/log/codedeploy_before_install.log
}
log "Updating apt-get"
sudo apt-get -y update || { log "apt-get update failed"; exit 1; }
log "Checking for /home/ubuntu/install"
if [ ! -f "/home/ubuntu/install" ]; then
# install CodeDeploy agent
sudo apt-get -y install ruby
sudo apt-get -y install wget
log "Installing CodeDeploy agent"
sudo apt-get -y install ruby || { log "ruby installation failed"; exit 1; }
sudo apt-get -y install wget || { log "wget installation failed"; exit 1; }
cd /home/ubuntu
wget https://aws-codedeploy-eu-north-1.s3.amazonaws.com/latest/install
sudo chmod +x ./install
sudo ./install auto
wget https://aws-codedeploy-eu-north-1.s3.amazonaws.com/latest/install || { log "wget failed"; exit 1; }
sudo chmod +x ./install
sudo ./install auto || { log "CodeDeploy agent installation failed"; exit 1; }
fi
# install golang
sudo apt-get -y install golang-go
log "Installing golang-go"
sudo apt-get -y install golang-go || { log "golang-go installation failed"; exit 1; }
# install nodeJS and npm
sudo apt -y install nodejs
sudo apt -y install npm
log "Installing nodejs and npm"
sudo apt -y install nodejs || { log "nodejs installation failed"; exit 1; }
sudo apt -y install npm || { log "npm installation failed"; exit 1; }
# Install MongoDB only if not already present
log "Checking for MongoDB installation"
if [ ! -f "/usr/bin/mongod" ]; then
sudo apt-get install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
--dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo apt-get install -y mongosh
log "Installing MongoDB"
sudo apt-get install -y gnupg curl || { log "gnupg or curl installation failed"; exit 1; }
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor || { log "MongoDB GPG key download failed"; exit 1; }
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list || { log "MongoDB repository addition failed"; exit 1; }
sudo apt-get update || { log "apt-get update failed after adding MongoDB repository"; exit 1; }
sudo apt-get install -y mongodb-org || { log "mongodb-org installation failed"; exit 1; }
sudo apt-get install -y mongosh || { log "mongosh installation failed"; exit 1; }
fi
log "BeforeInstall script completed successfully"