summarylogtreecommitdiffstats
path: root/netbird-multiconfig.sh
blob: 284758d81487a97b0844fae8c18e88aa56636d66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

# get all available configs from /etc/netbird/*.json directory

# user can override the config folder by setting NETBIRD_CONFIG_FOLDER
CONFIG_FOLDER=${NETBIRD_CONFIG_FOLDER:-/etc/netbird}

# check if the config folder exists
if [ ! -d "$CONFIG_FOLDER" ]; then
  echo "Warning: Config folder $CONFIG_FOLDER does not exist, exiting early..." >&2
  exit 0
fi

for file in "$CONFIG_FOLDER"/*.json; do
  if [ -f "$file" ]; then
    # get name of the file without the extension
    filename=$(basename "$file" .json)
    command_name="netbird-$filename"
    alias $command_name="/usr/bin/netbird --daemon-addr unix:///var/run/netbird-$filename.sock"
    complete -o default -F __start_netbird $command_name
  fi
done

function __netbird__noop() {
  if [[ "__complete" == "$1" ]]; then
    exit 0
  fi

  printf 'You are using a multi-config setup. Please use the config name as a command, e.g. netbird-<config_name>.\n'
}

alias "netbird"="__netbird__noop"