blob: c802a4a125e17eddde2071e945a1295a3ad4d2f5 [file] [log] [blame]
azvyagintsev6d453852018-02-26 16:56:37 +02001#!/bin/bash -xe
2
azvyagintsev29410ee2018-07-12 20:02:30 +03003if [ -f '/done_ubuntu_salt_bootstrap' ]; then
azvyagintsevb0daab12018-06-18 12:35:25 +03004 echo "INFO: ubuntu_salt_bootstrap already finished! Skipping.."
5 exit 0
6fi
7#
azvyagintsevffa75b42018-06-06 20:38:54 +03008CLUSTER_NAME=${CLUSTER_NAME:-lost_cluster_name_variable}
9CLUSTER_MODEL=${CLUSTER_MODEL:-https://github.com/Mirantis/mcp-offline-model.git}
azvyagintsevc86fbaf2018-03-02 18:57:03 +020010CLUSTER_MODEL_REF=${CLUSTER_MODEL_REF:-master}
11FORMULA_VERSION=${FORMULA_VERSION:-testing}
Petr Ruzicka9138b182018-08-22 17:38:30 +020012SALTSTACK_GPG=${SALTSTACK_GPG:-"https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2017.7/SALTSTACK-GPG-KEY.pub"}
13SALTSTACK_REPO=${SALTSTACK_REPO:-"http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2017.7 xenial main"}
azvyagintsev6d453852018-02-26 16:56:37 +020014APT_MIRANTIS_GPG=${APT_MIRANTIS_GPG:-"http://apt.mirantis.com/public.gpg"}
Richard Felkl47757902018-03-02 22:44:43 +010015APT_MIRANTIS_SALT_REPO=${APT_MIRANTIS_SALT_REPO:-"http://apt.mirantis.com/xenial/ $FORMULA_VERSION salt"}
azvyagintsev6d453852018-02-26 16:56:37 +020016GIT_SALT_FORMULAS_SCRIPTS=${GIT_SALT_FORMULAS_SCRIPTS:-"https://github.com/salt-formulas/salt-formulas-scripts"}
alexz8c4cfc72018-03-23 13:56:10 +010017GIT_SALT_FORMULAS_SCRIPTS_REF=${GIT_SALT_FORMULAS_SCRIPTS_REF:-master}
azvyagintsev6d453852018-02-26 16:56:37 +020018
azvyagintsev22dfc862018-09-25 13:20:05 +030019function process_repos(){
20# TODO: those should be unhardcoded and re-writed to mirror.mirantis.com logic
azvyagintsev6d453852018-02-26 16:56:37 +020021wget -O - ${SALTSTACK_GPG} | sudo apt-key add -
22wget -O - ${APT_MIRANTIS_GPG} | apt-key add -
azvyagintsev4b5603e2018-09-14 16:33:14 +030023echo "deb [arch=amd64] ${SALTSTACK_REPO}" > /etc/apt/sources.list.d/mcp_saltstack.list
azvyagintsev22dfc862018-09-25 13:20:05 +030024echo "deb [arch=amd64] http://mirror.mirantis.com/${FORMULA_VERSION}/extra/xenial xenial main" > /etc/apt/sources.list.d/mcp_extra.list
25# This Pin-Priority fix should be always aligned with
azvyagintsev4b5603e2018-09-14 16:33:14 +030026# https://github.com/Mirantis/reclass-system-salt-model/blob/master/linux/system/repo/mcp/apt_mirantis/saltstack.yml
azvyagintsev22dfc862018-09-25 13:20:05 +030027# saltstack
azvyagintsev4b5603e2018-09-14 16:33:14 +030028cat <<EOF >> /etc/apt/preferences.d/mcp_saltstack
29Package: libsodium18
30Pin: release o=SaltStack
31Pin-Priority: 50
32
33Package: *
34Pin: release o=SaltStack
35Pin-Priority: 1100
36EOF
azvyagintsev22dfc862018-09-25 13:20:05 +030037# reclass
38cat <<EOF >> /etc/apt/preferences.d/mcp_extra
39Package: *
40Pin: release o=Mirantis
41Pin-Priority: 1100
42EOF
43}
44
45process_repos
azvyagintsev6d453852018-02-26 16:56:37 +020046apt-get update
azvyagintsev22dfc862018-09-25 13:20:05 +030047apt-get install git-core reclass -y
alexz8c4cfc72018-03-23 13:56:10 +010048
azvyagintsev6d453852018-02-26 16:56:37 +020049for g_host in ${CLUSTER_MODEL} ${GIT_SALT_FORMULAS_SCRIPTS} ; do
50 _tmp_host=$(echo ${g_host} | awk -F/ '{print $3}')
51 ssh-keyscan -T 1 -H ${_tmp_host} >> ~/.ssh/known_hosts || true
52done
53
alexz8c4cfc72018-03-23 13:56:10 +010054if [[ ! -d /srv/salt/reclass ]]; then
55 git clone --recursive ${CLUSTER_MODEL} /srv/salt/reclass
56 pushd /srv/salt/reclass/
57 git checkout ${CLUSTER_MODEL_REF}
58 popd
59fi
60
61if [[ ! -d /srv/salt/scripts ]]; then
62 git clone --recursive ${GIT_SALT_FORMULAS_SCRIPTS} /srv/salt/scripts
63 pushd /srv/salt/scripts/
64 git checkout ${GIT_SALT_FORMULAS_SCRIPTS_REF}
65 popd
66fi
67
azvyagintsev6d453852018-02-26 16:56:37 +020068# bootstrap.sh opts
69export FORMULAS_SOURCE=pkg
azvyagintsevffa75b42018-06-06 20:38:54 +030070export HOSTNAME=${BS_HOSTNAME:-lost_bs_hostname_variable}
azvyagintsev6d453852018-02-26 16:56:37 +020071export DOMAIN="${CLUSTER_NAME}.local"
azvyagintsevbf6d3fd2018-07-31 16:08:43 +030072export EXTRA_FORMULAS=${EXTRA_FORMULAS:-"ntp aptly nginx iptables docker git maas jenkins logrotate"}
azvyagintsev6d453852018-02-26 16:56:37 +020073export APT_REPOSITORY=" deb [arch=amd64] ${APT_MIRANTIS_SALT_REPO} "
74export APT_REPOSITORY_GPG=${APT_MIRANTIS_GPG}
azvyagintsev0f697cf2018-06-22 11:44:13 +030075export SALT_STOPSTART_WAIT=${SALT_STOPSTART_WAIT:-10}
azvyagintsev4b5603e2018-09-14 16:33:14 +030076echo "INFO: build in offline build!"
77export BOOTSTRAP_SALTSTACK_COM="file:///tmp/bootstrap.saltstack.com.sh"
78# extra opts will push bootstrap script NOT install upstream repos.
79export BOOTSTRAP_SALTSTACK_OPTS=${BOOTSTRAP_SALTSTACK_OPTS:- -dXr $BOOTSTRAP_SALTSTACK_VERSION }
azvyagintsev6d453852018-02-26 16:56:37 +020080#
alexz8c4cfc72018-03-23 13:56:10 +010081
82if [[ ! -f /srv/salt/scripts/bootstrap.sh ]]; then
83 echo "ERROR: File /srv/salt/scripts/bootstrap.sh not found"
84 exit 1
85fi
azvyagintsev6d453852018-02-26 16:56:37 +020086bash -x /srv/salt/scripts/bootstrap.sh || true
azvyagintsev29410ee2018-07-12 20:02:30 +030087touch /done_ubuntu_salt_bootstrap