blob: 3510b8515d032c6a11b856307e456c0cac496479 [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 -
azvyagintsevb1bcb8d2018-09-26 18:03:14 +030023wget -O - http://mirror.mirantis.com/${FORMULA_VERSION}/extra/xenial/archive-extra.key | apt-key add -
24
azvyagintsev4b5603e2018-09-14 16:33:14 +030025echo "deb [arch=amd64] ${SALTSTACK_REPO}" > /etc/apt/sources.list.d/mcp_saltstack.list
azvyagintsev22dfc862018-09-25 13:20:05 +030026echo "deb [arch=amd64] http://mirror.mirantis.com/${FORMULA_VERSION}/extra/xenial xenial main" > /etc/apt/sources.list.d/mcp_extra.list
azvyagintsevb1bcb8d2018-09-26 18:03:14 +030027
azvyagintsev22dfc862018-09-25 13:20:05 +030028# This Pin-Priority fix should be always aligned with
azvyagintsev4b5603e2018-09-14 16:33:14 +030029# https://github.com/Mirantis/reclass-system-salt-model/blob/master/linux/system/repo/mcp/apt_mirantis/saltstack.yml
azvyagintsev22dfc862018-09-25 13:20:05 +030030# saltstack
azvyagintsev4b5603e2018-09-14 16:33:14 +030031cat <<EOF >> /etc/apt/preferences.d/mcp_saltstack
32Package: libsodium18
33Pin: release o=SaltStack
34Pin-Priority: 50
35
36Package: *
37Pin: release o=SaltStack
38Pin-Priority: 1100
39EOF
azvyagintsev22dfc862018-09-25 13:20:05 +030040# reclass
41cat <<EOF >> /etc/apt/preferences.d/mcp_extra
42Package: *
43Pin: release o=Mirantis
44Pin-Priority: 1100
45EOF
46}
47
48process_repos
azvyagintsev6d453852018-02-26 16:56:37 +020049apt-get update
azvyagintsev22dfc862018-09-25 13:20:05 +030050apt-get install git-core reclass -y
alexz8c4cfc72018-03-23 13:56:10 +010051
azvyagintsevb1bcb8d2018-09-26 18:03:14 +030052rm -v /etc/apt/sources.list.d/mcp_extra.list /etc/apt/preferences.d/mcp_extra
53
azvyagintsev6d453852018-02-26 16:56:37 +020054for g_host in ${CLUSTER_MODEL} ${GIT_SALT_FORMULAS_SCRIPTS} ; do
55 _tmp_host=$(echo ${g_host} | awk -F/ '{print $3}')
56 ssh-keyscan -T 1 -H ${_tmp_host} >> ~/.ssh/known_hosts || true
57done
58
alexz8c4cfc72018-03-23 13:56:10 +010059if [[ ! -d /srv/salt/reclass ]]; then
60 git clone --recursive ${CLUSTER_MODEL} /srv/salt/reclass
61 pushd /srv/salt/reclass/
62 git checkout ${CLUSTER_MODEL_REF}
63 popd
64fi
65
66if [[ ! -d /srv/salt/scripts ]]; then
67 git clone --recursive ${GIT_SALT_FORMULAS_SCRIPTS} /srv/salt/scripts
68 pushd /srv/salt/scripts/
69 git checkout ${GIT_SALT_FORMULAS_SCRIPTS_REF}
70 popd
71fi
72
azvyagintsev6d453852018-02-26 16:56:37 +020073# bootstrap.sh opts
74export FORMULAS_SOURCE=pkg
azvyagintsevffa75b42018-06-06 20:38:54 +030075export HOSTNAME=${BS_HOSTNAME:-lost_bs_hostname_variable}
azvyagintsev6d453852018-02-26 16:56:37 +020076export DOMAIN="${CLUSTER_NAME}.local"
azvyagintsevbf6d3fd2018-07-31 16:08:43 +030077export EXTRA_FORMULAS=${EXTRA_FORMULAS:-"ntp aptly nginx iptables docker git maas jenkins logrotate"}
azvyagintsev6d453852018-02-26 16:56:37 +020078export APT_REPOSITORY=" deb [arch=amd64] ${APT_MIRANTIS_SALT_REPO} "
79export APT_REPOSITORY_GPG=${APT_MIRANTIS_GPG}
azvyagintsev0f697cf2018-06-22 11:44:13 +030080export SALT_STOPSTART_WAIT=${SALT_STOPSTART_WAIT:-10}
azvyagintsev4b5603e2018-09-14 16:33:14 +030081echo "INFO: build in offline build!"
82export BOOTSTRAP_SALTSTACK_COM="file:///tmp/bootstrap.saltstack.com.sh"
83# extra opts will push bootstrap script NOT install upstream repos.
84export BOOTSTRAP_SALTSTACK_OPTS=${BOOTSTRAP_SALTSTACK_OPTS:- -dXr $BOOTSTRAP_SALTSTACK_VERSION }
azvyagintsev6d453852018-02-26 16:56:37 +020085#
alexz8c4cfc72018-03-23 13:56:10 +010086
87if [[ ! -f /srv/salt/scripts/bootstrap.sh ]]; then
88 echo "ERROR: File /srv/salt/scripts/bootstrap.sh not found"
89 exit 1
90fi
azvyagintsev6d453852018-02-26 16:56:37 +020091bash -x /srv/salt/scripts/bootstrap.sh || true
azvyagintsev29410ee2018-07-12 20:02:30 +030092touch /done_ubuntu_salt_bootstrap