aboutsummaryrefslogtreecommitdiff
path: root/lib/hydra/config
blob: b62c0c7344baaa3931b00f46cca792b68e69020b (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash

# Setup main configuration and load preferences
function hydra_config_load {
  local folder="`dirname $CONFIG`"

  if [ -f "$folder" ]; then
    echo "Converting legacy configuration scheme..."
    mv $folder $folder.tmp
    mkdir -p $folder
    mv $folder.tmp $CONFIG
  fi

  if [ ! -e "$CONFIG" ]; then
    echo "Creating $CONFIG..."
    mkdir `dirname $CONFIG`
    touch $CONFIG
    chmod 600 $CONFIG
    echo "# Hydra config file." > $CONFIG
    echo "" >> $CONFIG
  fi

  hydra_config_load_preferences
}

# Load config preferences
function hydra_config_load_preferences {
  # Load custom preferences
  if [ ! -z "$PREFERENCES" ] && [ -f "$PREFERENCES" ]; then
    source $PREFERENCES
  fi

  hydra_check_preferences
}

# Check preferences
function hydra_check_preferences {
  # Check for parameters that should not be set in preferences anymore
  if [ ! -z "$PUPPET" ]; then
    echo "Using deprecated config PUPPET, please update $PREFERENCES."
  fi

  if [ ! -z "$REMOTE_REPOS" ]; then
    echo "Using deprecated config REMOTE_REPOS, please update $PREFERENCES."
  fi

  if [ ! -z "$PRIVATE_REPOS" ]; then
    echo "Using deprecated config PRIVATE_REPOS, please update $PREFERENCES."
  fi

  # Set basic variables
  PUPPET="$HYDRA_FOLDER/puppet"
  PUPPET_KEYS="$PUPPET/keys"

  export HYDRA_CONNECT="ssh -T -q -o ConnectTimeout=15"
}

# Load a parameter from config
function hydra_config {
  if [ -z "$CONFIG" ]; then
    echo "Your have to set CONFIG variable in the code"
    exit 1
  elif [ -e "$CONFIG" ]; then
    grep -e "^$1=" $CONFIG | tail -n 1 | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | sed -e 's/ *#.*$//'
  else
    echo "Config file not found: $CONFIG"
    exit 1
  fi
}

# Configure puppet-boostrap.
function hydra_bootstrap_config {
  local config="$1"

  if [ -z "$config" ] || [ ! -d "$config" ]; then
    return
  fi

  (
    cd $config
    make deps
    make submodules
    make config
  )
}

# Get a configuration parameter if not previously defined by a sourced file
function hydra_user_config {
  local param="$1"
  local default="$2"
  shift 2

  if [ -z "`eval echo '$'$param`" ]; then
    hydra_user_input $param $default $*
  fi
}