diff --git a/scripts/before_install.sh b/scripts/before_install.sh index 21812cf..f38a4b4 100644 --- a/scripts/before_install.sh +++ b/scripts/before_install.sh @@ -1,43 +1,43 @@ #!/usr/bin/env bash -set -e # Exit immediately if a command exits with a non-zero status -set -x # Print commands and their arguments as they are executed +touch /home/ubuntu/status.txt -# Log function to capture error messages -log() { - echo "$1" >> /var/log/codedeploy_before_install.log -} +sudo apt-get -y update +# sudo rm -rf /home/ubuntu/install +echo "A" >> /home/ubuntu/status.txt -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 - 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; } + # install CodeDeploy agent + echo "B" >> /home/ubuntu/status.txt + sudo apt-get -y install ruby + sudo apt-get -y install wget cd /home/ubuntu - 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; } + wget https://aws-codedeploy-eu-north-1.s3.amazonaws.com/latest/install + sudo chmod +x ./install + sudo ./install auto + echo "C" >> /home/ubuntu/status.txt fi -log "Installing golang-go" -sudo apt-get -y install golang-go || { log "golang-go installation failed"; exit 1; } +# install golang +sudo apt-get -y install golang-go + echo "D" >> /home/ubuntu/status.txt -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 nodeJS and npm +sudo apt -y install nodejs +echo "E" >> /home/ubuntu/status.txt +sudo apt -y install npm +echo "F" >> /home/ubuntu/status.txt -log "Checking for MongoDB installation" +# Install MongoDB only if not already present if [ ! -f "/usr/bin/mongod" ]; then - 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; } + echo "G" >> /home/ubuntu/status.txt + 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 + echo "H" >> /home/ubuntu/status.txt fi - -log "BeforeInstall script completed successfully"