Change flat network name for nosdn fdio scenario
[apex-tripleo-heat-templates.git] / scripts / hosts-config.sh
1 #!/bin/bash
2 set -eux
3 set -o pipefail
4
5 write_entries() {
6     local file="$1"
7     local entries="$2"
8
9     # Don't do anything if the file isn't there
10     if [ ! -f "$file" ]; then
11         return
12     fi
13
14     if grep -q "^# HEAT_HOSTS_START" "$file"; then
15         temp=$(mktemp)
16         (
17         sed '/^# HEAT_HOSTS_START/,$d' "$file"
18         echo -ne "\n# HEAT_HOSTS_START - Do not edit manually within this section!\n"
19         echo "$entries"
20         echo -ne "# HEAT_HOSTS_END\n\n"
21         sed '1,/^# HEAT_HOSTS_END/d' "$file"
22         ) > "$temp"
23         echo "INFO: Updating hosts file $file, check below for changes"
24         diff "$file" "$temp" || true
25         cat "$temp" > "$file"
26     else
27         echo -ne "\n# HEAT_HOSTS_START - Do not edit manually within this section!\n" >> "$file"
28         echo "$entries" >> "$file"
29         echo -ne "# HEAT_HOSTS_END\n\n" >> "$file"
30     fi
31
32 }
33
34 if [ ! -z "$hosts" ]; then
35     for tmpl in /etc/cloud/templates/hosts.*.tmpl ; do
36         write_entries "$tmpl" "$hosts"
37     done
38     write_entries "/etc/hosts" "$hosts"
39 else
40     echo "No hosts in Heat, nothing written."
41 fi