ovirt-node 2.2.0 release
[ovirt-node.git] / scripts / ovirt-process-config
blobddb068a02d923fde501dd45266082ef869a9907e
1 #!/bin/bash
3 # Takes as input a reference to an encoded configuration file
4 # and produces from that a kernel module file and a network
5 # configuration file. It then restarts the networking service
6 # and saves the configuration files.
8 . /usr/libexec/ovirt-functions
10 ME=$(basename "$0")
11 warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
12 die() { warn "$*"; exit 1; }
14 try_h() { printf "Try \`$ME -h' for more information.\n" >&2; exit 1;}
15 try_help() { printf "Usage: \`$ME [config] [module output] [config output]\n" >&2; exit 1;}
17 case $# in
18 0|1|2) warn "too few arguments"; try_help;;
19 3) ;;
20 *) warn "too many arguments"; try_help;;
21 esac
23 CONFIG=$1
24 OVIRT_KERNEL_MODULE_FILE=$2
25 OVIRT_CONFIG_OUTPUT_FILE=$3
27 modconf=$(awk '/^[ \t]*bonding=.+/ {
28 match($0, "^[ \t]*bonding=(.+)", data)
29 printf "data[2] = %s\n", data[2]
31 if (match("[^[:alnum:]=_@-]", data[2]) >= 0) {
32 printf "invalid bonding alias: \"%s\"\n", data[2];
33 exit 1;
36 alias=data[2]
38 printf("install %s bonding", alias)
39 }' $CONFIG)
41 echo "$modconf" > $OVIRT_KERNEL_MODULE_FILE
43 networking=$(awk '/^[ \t]*ifcfg=/ {
44 match($0, "^[ \t]*ifcfg=(.*)", data)
45 split(data[1], ifcfg, "|")
47 mac = ifcfg[1]
48 iface = ifcfg[2]
49 ifcfg_dir = "/files/etc/sysconfig/network-scripts"
51 printf("rm %s/ifcfg-%s\n", ifcfg_dir, iface)
52 printf("set %s/ifcfg-%s/DEVICE %s\n", ifcfg_dir, iface, iface)
54 for (line in ifcfg) {
55 if(line > 2) {
56 match(ifcfg[line], "(^[^=]+)=(.*)", values)
57 field=values[1]
58 value=values[2]
60 if(length(field) == 0) {
61 print "Missing field name."
62 exit 1
65 if(length(value) == 0) {
66 print "Missing field value."
67 exit 2
70 printf("set %s/ifcfg-%s/%s %s\n", ifcfg_dir, iface, field, value)
74 }' $CONFIG)
76 SUCCESS=$?
78 if [ $SUCCESS != 0 ]; then
79 case $SUCCESS in
80 1) error="missing field name";;
81 2) error="missing field value";;
82 esac
84 die "Bad data received: ${error}"
87 echo "$networking" > $OVIRT_CONFIG_OUTPUT_FILE
89 if [ -f $OVIRT_CONFIG_OUTPUT_FILE ]; then
90 augtool $OVIRT_CONFIG_OUTPUT_FILE \
91 && RESULT=0 || RESULT=1
92 # FIXME do not store ifcfg-lo
93 if ls /etc/sysconfig/network-scripts/ifcfg* >/dev/null 2>/dev/null; then
94 ovirt_store_config /etc/sysconfig/network-scripts/ifcfg*
98 exit $RESULT