7b6e6bd71e6b19701e0bd187e304bfea271f47d8
[genesis.git] / fuel / build / f_isoroot / f_bootstrap / bootstrap_admin_node.sh.orig
1 #!/bin/bash
2
3 function countdown() {
4   local i
5   sleep 1
6   for ((i=$1-1; i>=1; i--)); do
7     printf '\b\b%02d' "$i"
8     sleep 1
9   done
10 }
11
12 function fail() {
13   echo "ERROR: Fuel node deployment FAILED! Check /var/log/puppet/bootstrap_admin_node.log for details" 1>&2
14   exit 1
15 }
16 # LANG variable is a workaround for puppet-3.4.2 bug. See LP#1312758 for details
17 export LANG=en_US.UTF8
18 showmenu="no"
19 if [ -f /root/.showfuelmenu ]; then
20   . /root/.showfuelmenu
21 fi
22
23 echo -n "Applying default Fuel settings..."
24 fuelmenu --save-only --iface=eth0
25 echo "Done!"
26
27 if [[ "$showmenu" == "yes" || "$showmenu" == "YES" ]]; then
28   fuelmenu
29   else
30   #Give user 15 seconds to enter fuelmenu or else continue
31   echo
32   echo -n "Press a key to enter Fuel Setup (or press ESC to skip)... 15"
33   countdown 15 & pid=$!
34   if ! read -s -n 1 -t 15 key; then
35     echo -e "\nSkipping Fuel Setup..."
36   else
37     { kill "$pid"; wait $!; } 2>/dev/null
38     case "$key" in
39       $'\e')  echo "Skipping Fuel Setup.."
40               echo -n "Applying default Fuel setings..."
41               fuelmenu --save-only --iface=eth0
42               echo "Done!"
43               ;;
44       *)      echo -e "\nEntering Fuel Setup..."
45               fuelmenu
46               ;;
47     esac
48   fi
49 fi
50 #Reread /etc/sysconfig/network to inform puppet of changes
51 . /etc/sysconfig/network
52 hostname "$HOSTNAME"
53
54 ### docker stuff
55 images_dir="/var/www/nailgun/docker/images"
56
57 # extract docker images
58 mkdir -p $images_dir $sources_dir
59 rm -f $images_dir/*tar
60 pushd $images_dir &>/dev/null
61
62 echo "Extracting and loading docker images. (This may take a while)"
63 lrzip -d -o fuel-images.tar fuel-images.tar.lrz && tar -xf fuel-images.tar && rm -f fuel-images.tar
64 popd &>/dev/null
65 service docker start
66
67 # load docker images
68 for image in $images_dir/*tar ; do
69     echo "Loading docker image ${image}..."
70     docker load -i "$image"
71     # clean up extracted image
72     rm -f "$image"
73 done
74
75 # apply puppet
76 puppet apply --detailed-exitcodes -d -v /etc/puppet/modules/nailgun/examples/host-only.pp
77 if [ $? -ge 4 ];then
78   fail
79 fi
80 rmdir /var/log/remote && ln -s /var/log/docker-logs/remote /var/log/remote
81
82 dockerctl check || fail
83 bash /etc/rc.local
84 echo "Fuel node deployment complete!"