crowbar/crowbar-core

View on GitHub
chef/cookbooks/provisioner/templates/default/net-post-install.sh.erb

Summary

Maintainability
Test Coverage
#!/bin/sh
# Copyright 2011, Dell
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This script is called by the net_ubuntu.seed file during
# ubuntu install.  It handles doing the manual sets needed to layout the
# filesystem the rest of the way before running the common_install.sh.
#
# The intent is that once the system is finished installing, the customer
# will edit the config.json file and run install.sh to complete installation
# and initial configuration.
#

#
# We are a net install.
#

<% @repos.keys.sort.each do |repo|
     @repos[repo].keys.sort.each do |url|
       case repo
       when "base" -%>
echo "deb <%=url%> <%= @os_codename %> main restricted" > \
    /target/etc/apt/sources.list.d/00-base.list
<%     else -%>
echo "<%=url%>" >> \
    /target/etc/apt/sources.list.d/10-barclamp-<%=repo%>.list
<%     end
     end
   end -%>

rm -f /target/etc/apt/sources.list

rsyslog_dir="/target/etc/rsyslog.d"
if [ -d "$rsyslog_dir" ]; then
    if [ ! -f "$rsyslog_dir/10-crowbar-client.conf" ]; then
        echo "*.* @@<%= @admin_ip %>" > "$rsyslog_dir/10-crowbar-client.conf"
    if ! wget -O "$rsyslog_dir/00-crowbar-debug.conf" -q http://<%=@provisioner_web%>/rsyslog.d/00-crowbar-debug.conf
    then
        rm -f "$rsyslog_dir/00-crowbar-debug.conf"
    fi
    fi
fi

mkdir -p /target/root/.ssh
chmod 700 /target/root/.ssh
if ! wget -O /target/root/.ssh/authorized_keys.wget -q <%=@provisioner_web%>/authorized_keys; then
    rm -f /target/root/.ssh/authorized_keys.wget
else
    chmod 644 /target/root/.ssh/authorized_keys
    cat /target/root/.ssh/authorized_keys.wget >>/target/root/.ssh/authorized_keys
    rm -f /target/root/.ssh/authorized_keys.wget
fi

wget -q <%=@web_path%>/crowbar_join.sh -O- > /target/etc/init.d/crowbar_join.sh

cat > /target/update_system2.sh <<"EOF"
#!/bin/bash

key_re='crowbar\.install\.key=([^ ]+)'
if [[ $(cat /proc/cmdline) =~ $key_re ]]; then
    export CROWBAR_KEY="${BASH_REMATCH[1]}"
    echo "$CROWBAR_KEY" >/etc/crowbar.install.key
elif [[ -f /etc/crowbar.install.key ]]; then
    export CROWBAR_KEY="$(cat /etc/crowbar.install.key)"
fi

post_state() {
  local curlargs=(-o /dev/null --connect-timeout 60 -s \
      -L -X POST --data-binary "{ \"name\": \"$1\", \"state\": \"$2\" }" \
      -H "Accept: application/json" -H "Content-Type: application/json" \
      --max-time 240 --insecure --location)
  [[ $CROWBAR_KEY ]] && curlargs+=(-u "$CROWBAR_KEY" --digest --anyauth)
  curl "${curlargs[@]}" "http://<%=@admin_ip%>/crowbar/crowbar/1.0/transition/default"
}

HOSTNAME=$(hostname -f)

export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
export LC_ALL=C LANGUAGE=C LANG=C
apt-get -y --force-yes remove apparmor
apt-get -y --force-yes install screen
sleep 30

post_state $HOSTNAME "installed"

# Wait for DHCP to update - this is mainly for virtual environments or really large deploys
sleep 30

EOF

mount /proc /target/proc
chmod +x /target/etc/init.d/crowbar_join.sh
chmod +x /target/update_system2.sh
chroot /target ln -s /etc/init.d/crowbar_join.sh /etc/rc3.d/S80crowbar
chroot /target ln -s /etc/init.d/crowbar_join.sh /etc/rc5.d/S80crowbar
chroot /target ln -s /etc/init.d/crowbar_join.sh /etc/rc2.d/S80crowbar
chroot /target /update_system2.sh
sync