propagate errors from augtool
[ovirt-node/TEMP.git] / scripts / ovirt-config-hostname
blobf369d0eee40b34667782811886bc043f1a3fb14c
1 #!/bin/bash
3 # Configures the hostname file based on kernel cmdline or user prompt
4 # Source functions library
5 . /etc/init.d/functions
6 . /etc/init.d/ovirt-functions
8 trap '__st=$?; stop_log; exit $__st' 0
9 trap 'exit $?' 1 2 13 15
11 HOSTNAME_FILE="/etc/sysconfig/network"
13 function set_hostname {
14 start_log
15 augtool <<EOF
16 set /files$HOSTNAME_FILE/HOSTNAME "$1"
17 EOF
18 rc=$?
19 stop_log
20 return $rc
23 function remove_hostname {
24 start_log
25 augtool <<EOF
26 rm /files$HOSTNAME_FILE/HOSTNAME
27 EOF
28 rc=$?
29 stop_log
30 return $rc
33 function prompt_user {
34 printf "\n"
35 read -p "What is the hostname for this node? "
37 if [ -n "$REPLY" ]; then
38 if set_hostname $REPLY; then
39 printf "\nHostname has been set\n"
40 else
41 printf "\nSetting hostname failed\n"
42 return 1
44 else
45 printf "\n"
46 read -p "Enter (Y|y) to blank out the hostname, or (N|n) to skip. "
47 case $REPLY in
48 Y|y)
49 if remove_hostname; then
50 printf "\nHostname was removed.\n"
51 return 0
52 else
53 printf "\nRemoving hostname failed\n"
54 return 1
57 N|n)
58 printf "\nNo changes made.\n"
59 return 0
61 *) ;;
62 esac
66 # AUTO for auto-install
67 if [ "$1" = "AUTO" ]; then
68 if [ -n "$OVIRT_HOSTNAME" ]; then
69 if set_hostname $OVIRT_HOSTNAME; then
70 printf "\nHostname has been set\n"
71 else
72 printf "\nSetting hostname failed\n"
74 else
75 printf "\nHostname not provided. Skipping.\n"
77 else
78 printf "\n\n oVirt Node Hostname Configuration\n\n"
79 prompt_user