PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 30, 2022

[FIXED] How do I set env variables in bash script for a packer image

 October 30, 2022     bash, eof     No comments   

Issue

I am trying to bake an AMI with Maven and Gradle in Packer. Below is my json file.

#!/bin/bash
sudo yum -y update
sudo yum install -y httpd
sudo mkdir -p /usr/local/apache-maven
cd /usr/local/apache-maven
sudo wget http://mirror.olnevhost.net/pub/apache/maven/binaries/apache-maven-3.2.2-bin.tar.gz
sudo tar xvf apache-maven-3.2.2-bin.tar.gz
echo "Maven is installed at usr local apache-maven #maven"
sudo mkdir /opt/gradle
cd /opt/gradle
sudo wget https://services.gradle.org/distributions/gradle-3.4.1-bin.zip
sudo unzip -d /opt/gradle gradle-3.4.1-bin.zip
echo "Gradle is installed at opt gradle #gradle"
cat > set-vars1.sh
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.2
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export PATH=$PATH:/opt/gradle/gradle-3.4.1/bin
eval $(./set-vars1.sh)

I am unable to exit the script and unable to export the variables. How do I exit and run the script?

What I am trying to do is create an AMI instance with a packer for which I am writing the above script as a provisioner. I am able to download and unzip maven and gradle but the env variables are not getting exported.

So basically I want to set variables in an instance at runtime.


Solution

cat << EOF > set-vars1.sh
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.2
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export PATH=$PATH:/opt/gradle/gradle-3.4.1/bin
EOF


Answered By - Pierre François
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing