Updates docs for SR1 with final revision
[genesis.git] / fuel / build / f_isoroot / f_bootstrap / bootstrap_admin_node.sh.orig
1 #!/bin/bash
2 FUEL_RELEASE=$(grep release: /etc/fuel/version.yaml | cut -d: -f2 | tr -d '" ')
3
4 function countdown() {
5   local i
6   sleep 1
7   for ((i=$1-1; i>=1; i--)); do
8     printf '\b\b%02d' "$i"
9     sleep 1
10   done
11 }
12
13 function fail() {
14   echo "ERROR: Fuel node deployment FAILED! Check /var/log/puppet/bootstrap_admin_node.log for details" 1>&2
15   exit 1
16 }
17 # LANG variable is a workaround for puppet-3.4.2 bug. See LP#1312758 for details
18 export LANG=en_US.UTF8
19 showmenu="no"
20 if [ -f /root/.showfuelmenu ]; then
21   . /root/.showfuelmenu
22 fi
23
24 echo -n "Applying default Fuel settings..."
25 fuelmenu --save-only --iface=eth0
26 echo "Done!"
27
28 if [[ "$showmenu" == "yes" || "$showmenu" == "YES" ]]; then
29   fuelmenu
30   else
31   #Give user 15 seconds to enter fuelmenu or else continue
32   echo
33   echo -n "Press a key to enter Fuel Setup (or press ESC to skip)... 15"
34   countdown 15 & pid=$!
35   if ! read -s -n 1 -t 15 key; then
36     echo -e "\nSkipping Fuel Setup..."
37   else
38     { kill "$pid"; wait $!; } 2>/dev/null
39     case "$key" in
40       $'\e')  echo "Skipping Fuel Setup.."
41               ;;
42       *)      echo -e "\nEntering Fuel Setup..."
43               fuelmenu
44               ;;
45     esac
46   fi
47 fi
48
49
50 #Reread /etc/sysconfig/network to inform puppet of changes
51 . /etc/sysconfig/network
52 hostname "$HOSTNAME"
53
54 service docker start
55
56 if [ -f /root/.build_images ]; then
57   #Fail on all errors
58   set -e
59   trap fail EXIT
60
61   echo "Loading Fuel base image for Docker..."
62   docker load -i /var/www/nailgun/docker/images/fuel-images.tar
63
64   echo "Building Fuel Docker images..."
65   WORKDIR=$(mktemp -d /tmp/docker-buildXXX)
66   SOURCE=/var/www/nailgun/docker
67   REPO_CONT_ID=$(docker -D run -d -p 80 -v /var/www/nailgun:/var/www/nailgun fuel/centos sh -c 'mkdir /var/www/html/os;ln -sf /var/www/nailgun/centos/x86_64 /var/www/html/os/x86_64;/usr/sbin/apachectl -DFOREGROUND')
68   RANDOM_PORT=$(docker port $REPO_CONT_ID 80 | cut -d':' -f2)
69
70   for imagesource in /var/www/nailgun/docker/sources/*; do
71     if ! [ -f "$imagesource/Dockerfile" ]; then
72       echo "Skipping ${imagesource}..."
73       continue
74     fi
75     image=$(basename "$imagesource")
76     cp -R "$imagesource" $WORKDIR/$image
77     mkdir -p $WORKDIR/$image/etc
78     cp -R /etc/puppet /etc/fuel $WORKDIR/$image/etc
79     sed -e "s/_PORT_/${RANDOM_PORT}/" -i $WORKDIR/$image/Dockerfile
80     sed -e 's/production:.*/production: "docker-build"/' -i $WORKDIR/$image/etc/fuel/version.yaml
81     docker build -t fuel/${image}_${FUEL_RELEASE} $WORKDIR/$image
82   done
83   docker rm -f $REPO_CONT_ID
84   rm -rf "$WORKDIR"
85
86   #Remove trap for normal deployment
87   trap - EXIT
88   set +e
89 else
90   echo "Loading docker images. (This may take a while)"
91   docker load -i /var/www/nailgun/docker/images/fuel-images.tar
92 fi
93
94 # apply puppet
95 puppet apply --detailed-exitcodes -d -v /etc/puppet/modules/nailgun/examples/host-only.pp
96 if [ $? -ge 4 ];then
97   fail
98 fi
99 rmdir /var/log/remote && ln -s /var/log/docker-logs/remote /var/log/remote
100
101 dockerctl check || fail
102 bash /etc/rc.local
103
104 # Enable updates repository
105 cat > /etc/yum.repos.d/mos${FUEL_RELEASE}-updates.repo << EOF
106 [mos${FUEL_RELEASE}-updates]
107 name=mos${FUEL_RELEASE}-updates
108 baseurl=http://mirror.fuel-infra.org/mos/centos-6/mos${FUEL_RELEASE}/updates/
109 gpgcheck=0
110 skip_if_unavailable=1
111 EOF
112
113 # Enable security repository
114 cat > /etc/yum.repos.d/mos${FUEL_RELEASE}-security.repo << EOF
115 [mos${FUEL_RELEASE}-security]
116 name=mos${FUEL_RELEASE}-security
117 baseurl=http://mirror.fuel-infra.org/mos/centos-6/mos${FUEL_RELEASE}/security/
118 gpgcheck=0
119 skip_if_unavailable=1
120 EOF
121
122 #Check if repo is accessible
123 echo "Checking for access to updates repository..."
124 repourl=$(grep baseurl /etc/yum.repos.d/*updates* 2>/dev/null | cut -d'=' -f2- | head -1)
125 if urlaccesscheck check "$repourl" ; then
126   UPDATE_ISSUES=0
127 else
128   UPDATE_ISSUES=1
129 fi
130
131 if [ $UPDATE_ISSUES -eq 1 ]; then
132   warning="WARNING: There are issues connecting to Fuel update repository.\
133 \nPlease fix your connection and update this node with \`yum update\`\
134 \nThen run \`dockerctl destroy all; bootstrap_admin_node.sh;\`\
135 \nto repeat bootstrap on Fuel Master with the latest updates.\
136 \nFor more information, check out Fuel documentation at:\
137 \nhttp://docs.mirantis.com/fuel"
138 else
139   warning="WARNING: There may be updates available for Fuel.\
140 \nYou should update this node with \`yum update\`. If there are available\
141 \n updates, run \`dockerctl destroy all; bootstrap_admin_node.sh;\`\
142 \nto repeat bootstrap on Fuel Master with the latest updates.\
143 \nFor more information, check out Fuel documentation at:\
144 \nhttp://docs.mirantis.com/fuel"
145 fi
146 echo
147 echo "*************************************************"
148 echo -e "$warning"
149 echo "*************************************************"
150 echo "Sending notification to Fuel UI..."
151 fuel notify --topic warning --send "$warning"
152 echo "Fuel node deployment complete!"