mirror of
https://github.com/YunoHost/ynh-dev.git
synced 2024-09-03 20:05:59 +02:00
[enh] Be able to run multiple vagrant instances (#18)
* [enh] Be able to run multiple vagrant instances * [fix] Don't delete /etc/hosts content
This commit is contained in:
parent
e1f084feb5
commit
571ddbb81b
1 changed files with 29 additions and 4 deletions
33
ynh-dev
33
ynh-dev
|
@ -58,6 +58,7 @@ if [ "$#" = "1" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BASE_DIR=./
|
BASE_DIR=./
|
||||||
|
IP_BASE="192.168.33."
|
||||||
|
|
||||||
##################
|
##################
|
||||||
## Help message ##
|
## Help message ##
|
||||||
|
@ -120,15 +121,12 @@ elif [ "$1" = "run" ]; then
|
||||||
if [ "$VERSION" = "stable" ]; then
|
if [ "$VERSION" = "stable" ]; then
|
||||||
BOX_NAME="yunohost/jessie-stable"
|
BOX_NAME="yunohost/jessie-stable"
|
||||||
BOX_URL="https://build.yunohost.org/yunohost-jessie-stable.box"
|
BOX_URL="https://build.yunohost.org/yunohost-jessie-stable.box"
|
||||||
IP="192.168.33.80"
|
|
||||||
elif [ "$VERSION" = "testing" ]; then
|
elif [ "$VERSION" = "testing" ]; then
|
||||||
BOX_NAME="yunohost/jessie-testing"
|
BOX_NAME="yunohost/jessie-testing"
|
||||||
BOX_URL="https://build.yunohost.org/yunohost-jessie-testing.box"
|
BOX_URL="https://build.yunohost.org/yunohost-jessie-testing.box"
|
||||||
IP="192.168.33.81"
|
|
||||||
elif [ "$VERSION" = "unstable" ]; then
|
elif [ "$VERSION" = "unstable" ]; then
|
||||||
BOX_NAME="yunohost/jessie-unstable"
|
BOX_NAME="yunohost/jessie-unstable"
|
||||||
BOX_URL="https://build.yunohost.org/yunohost-jessie-unstable.box"
|
BOX_URL="https://build.yunohost.org/yunohost-jessie-unstable.box"
|
||||||
IP="192.168.33.82"
|
|
||||||
else
|
else
|
||||||
echo "ERROR: Incorrect version '$VERSION'. See '$(basename $0) --help' for usage."
|
echo "ERROR: Incorrect version '$VERSION'. See '$(basename $0) --help' for usage."
|
||||||
exit 102
|
exit 102
|
||||||
|
@ -141,12 +139,39 @@ elif [ "$1" = "run" ]; then
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Deduce the vm name
|
||||||
|
VMNAME=${DOMAIN//./_}
|
||||||
|
|
||||||
|
|
||||||
|
# Add the vm vagrant config in Vagrantfile
|
||||||
|
vagrant status $VMNAME &> /dev/null || {
|
||||||
|
|
||||||
|
# Find an available ip
|
||||||
|
for i in `seq 1 254`;
|
||||||
|
do
|
||||||
|
grep "${IP_BASE//./\.}$i" Vagrantfile &> /dev/null || {
|
||||||
|
IP="${IP_BASE}$i"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done
|
||||||
|
|
||||||
|
sed -i "/ ### END AUTOMATIC YNH-DEV ###/ i \\
|
||||||
|
config.vm.define \"${VMNAME}\" do |${VMNAME}| \
|
||||||
|
\n ${VMNAME}.vm.box = \"yunohost/jessie-${VERSION}\" \
|
||||||
|
\n ${VMNAME}.vm.network :private_network, ip: \"${IP}\" \
|
||||||
|
\n end \
|
||||||
|
\n" ./Vagrantfile
|
||||||
|
}
|
||||||
|
|
||||||
# Run VM
|
# Run VM
|
||||||
vagrant up $VERSION --provider virtualbox
|
vagrant up $VERSION --provider virtualbox
|
||||||
|
|
||||||
# Warn user about hosts file
|
# Warn user about hosts file
|
||||||
|
IP_LINE="\s\s*${VMNAME}.vm.network\s\s*:private_network,\s*ip:\s*\""
|
||||||
|
IP=$(grep "$IP_LINE" Vagrantfile | sed "s/${IP_LINE}//")
|
||||||
|
IP=${IP::-1}
|
||||||
echo "/!\ Please add '$IP $DOMAIN' to your /etc/hosts file /!\\"
|
echo "/!\ Please add '$IP $DOMAIN' to your /etc/hosts file /!\\"
|
||||||
echo "sudo su -c \"echo '$IP $DOMAIN' >> /etc/hosts\" root"
|
echo "sudo sh -s 'echo \"$IP $DOMAIN\" >> /etc/hosts'"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Log into the VM
|
# Log into the VM
|
||||||
|
|
Loading…
Add table
Reference in a new issue