From be05c2904ac8a6db8116df74f724a0b1ea123388 Mon Sep 17 00:00:00 2001 From: Tomas Bezouska Date: Wed, 7 Apr 2021 00:07:33 +0200 Subject: [PATCH] Allow spinning up different network versions Resolves #3 --- Vagrantfile | 8 +++++--- umbrel-dev | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 162a15f..01a790d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -21,14 +21,16 @@ umbrelLogo = <<-TEXT "%GGGGGG#" TEXT +network = File.open("network").read.strip + Vagrant.configure(2) do |config| # Install required plugins config.vagrant.plugins = {"vagrant-vbguest" => {"version" => "0.24.0"}} # Setup VM - config.vm.define "umbrel-dev" + config.vm.define "#{network}-umbrel-dev" config.vm.box = "debian/buster64" - config.vm.hostname = "umbrel-dev" + config.vm.hostname = "#{network}-umbrel-dev" config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)" config.vm.synced_folder ".", "/vagrant", type: "virtualbox" @@ -60,7 +62,7 @@ Vagrant.configure(2) do |config| config.vm.provision "shell", inline: <<-SHELL apt-get install -y fswatch rsync jq cd /vagrant/getumbrel/umbrel - sudo NETWORK=regtest ./scripts/configure + sudo NETWORK=#{network} ./scripts/configure docker-compose build --parallel docker-compose run dashboard -c yarn SHELL diff --git a/umbrel-dev b/umbrel-dev index c6b02bf..c98f6c4 100755 --- a/umbrel-dev +++ b/umbrel-dev @@ -106,6 +106,34 @@ if [[ "$command" = "init" ]]; then exit 1 fi + network="regtest" + shift 1 + + while (( "$#" )); do + case "$1" in + -n|--network) + if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then + network=$2 + shift 2 + else + echo "Error: Argument for $1 is missing" >&2 + exit 1 + fi + ;; + -*|--*=) # unsupported flags + echo "Error: Unsupported flag $1" >&2 + exit 1 + ;; + esac + done + + if [ "$network" != "mainnet" ] && [ "$network" != "testnet" ] && [ "$network" != "regtest" ]; then + echo "Error: Umbrel dev can only be configured for regtest (default), testnet or mainnet" + exit 1 + fi + + echo "Network is $network" + echo $network > "network" echo "Creating Vagrantfile..." cp "$(get_script_location)/Vagrantfile" . @@ -179,12 +207,13 @@ if [[ "$command" = "rebuild" ]]; then echo "A second argument is required!" exit 1 fi + network < "network" container="$2" run_in_vm " \ docker-compose build $container \ && docker-compose stop $container \ && docker-compose rm -f $container \ - && DEVICE_HOSTS=http://umbrel-dev.local docker-compose up -d $container" + && DEVICE_HOSTS=http://$network-umbrel-dev.local docker-compose up -d $container" exit fi