In a Vagrantfile, I want to run scripts.
But some part of them shouldn't run in provision mode.
I've sat a local variable update = "true" (or false) depending of the value of the Vagrant command.
A puts shows me that it is valued by "false", by example,
but then, I'm unable to send its content to a bash script, for parameter.
I've tried $update, #update, #{update}, update without success
on the line bash common/300_Kafka.sh "3.4.0" "2.12" $update
Part of the Vagrantfile:
if ARGV[0] == "provision"
update = "true"
else
update = "false"
end
puts "Vagrant box. Démarrage en mode mise à jour : " + update
config.vm.provision "file", source: "../common", destination: "common"
config.vm.provision "shell", privileged: false, inline: <<-SHELL
bash common/050_Certificats.sh
bash common/070_Utilitaires.sh
bash common/100_JDK.sh "17"
bash common/150_Postgresql-Postgis.sh "15" "3" "postgres"
bash common/200_NodeJS-Angular.sh "16"
bash common/250_ELK.sh "7.x"
bash common/300_Kafka.sh "3.4.0" "2.12" $update
SHELL
Message on console:
Vagrant box. Démarrage en mode mise à jour : false
default: Indiquez si Kafka est en installation initiale (false) ou update (true). n'est pas accepté.
The bash script called, testing the values:
#!/bin/bash
# $1: Version de Kafka [3.4.0]
# $2: Version de Scala associée [2.12]
# $3: Mode update (true) ou installation initiale (false)
echo "300 : Installation de Kafka $1 basé sur Scala $2"
export DEBIAN_FRONTEND=noninteractive
if [ -z "$1" ]; then
echo "Précisez la version de Kafka à installer. [Recommandée : 3.4.0]" >&2;
exit 1;
fi
if [ -z "$2" ]; then
echo "Précisez la version de Scala liée. [Recommandée : 2.12]" >&2;
exit 1;
fi
if [ "$3" != "true" ] && [ "$3" != "false" ]; then
echo "Indiquez si Kafka est en installation initiale (false) ou update (true). $3 n'est pas accepté." >&2;
exit 1;
fi
update=$3
if [ "$update" == "false" ]; then
cd /tmp && wget -q "https://downloads.apache.org/kafka/$1/kafka_$2-$1.tgz"
sudo tar -xf "kafka_$2-$1.tgz" -C /opt
echo "export KAFKA_HOME=/opt/kafka_$2-$1" >> ~/.profile
else
echo "En mode update, Kafka ne se réinstallera pas."
fi
My way of sending parameters to shell script isn't correct.
It looks working but doesn't perfectly, inside of an
inline <<-SHELL.I found myself successful with that, instead: