#!/bin/bash # here be dragons... see http://fvue.nl/wiki/Bash:_Error_handling set -eux config_fqdn=$(hostname --fqdn) config_domain=$(hostname --domain) echo "127.0.0.1 $config_fqdn" >>/etc/hosts # disable IPv6. cat >/etc/sysctl.d/98-disable-ipv6.conf <<'EOF' net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 EOF systemctl restart procps sed -i -E 's,(GRUB_CMDLINE_LINUX=.+)",\1 ipv6.disable=1",' /etc/default/grub update-grub2 # update the package cache. apt-get -y update # vim. apt-get install -y --no-install-recommends vim cat >/etc/vim/vimrc.local <<'EOF' syntax on set background=dark set esckeys set ruler set laststatus=2 set nobackup autocmd BufNewFile,BufRead Vagrantfile set ft=ruby EOF # create a self-signed certificate. pushd /etc/ssl/private openssl genrsa \ -out $config_fqdn-keypair.pem \ 2048 \ 2>/dev/null chmod 400 $config_fqdn-keypair.pem openssl req -new \ -sha256 \ -subj "/CN=$config_fqdn" \ -key $config_fqdn-keypair.pem \ -out $config_fqdn-csr.pem openssl x509 -req -sha256 \ -signkey $config_fqdn-keypair.pem \ -extensions a \ -extfile <(echo "[a] subjectAltName=DNS:$config_fqdn extendedKeyUsage=serverAuth ") \ -days 365 \ -in $config_fqdn-csr.pem \ -out $config_fqdn-crt.pem popd # install and configure nginx to proxy to nexus. # see https://books.sonatype.com/nexus-book/3.3/reference/install.html#reverse-proxy apt-get install -y --no-install-recommends nginx rm -f /etc/nginx/sites-enabled/default cat >/etc/nginx/sites-available/$config_fqdn.conf <nexus3/etc/nexus.properties sed -i -E 's,(application-host=).+,\1127.0.0.1,g' nexus3/etc/nexus.properties sed -i -E 's,nexus-pro-,nexus-oss-,g' nexus3/etc/nexus.properties diff -u etc/nexus-default.properties nexus3/etc/nexus.properties || true sed -i -E 's,\.\./sonatype-work/,,g' bin/nexus.vmoptions popd # start nexus. cat >/etc/systemd/system/nexus.service <<'EOF' [Unit] Description=Nexus After=network.target [Service] Type=simple User=nexus Group=nexus ExecStart=/opt/nexus/bin/nexus run WorkingDirectory=/opt/nexus Restart=always [Install] WantedBy=multi-user.target EOF systemctl enable nexus systemctl start nexus # install tools. apt-get install -y --no-install-recommends httpie apt-get install -y --no-install-recommends jq # wait for nexus to come up. bash -c 'while [[ "$(wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq -r .data.data.status.value.edition)" != "OSS" ]]; do sleep 5; done' # print the version using the API. wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq --raw-output .data.data.uiSettings.value.title wget -qO- http://localhost:8081/service/extdirect/poll/rapture_State_get | jq .data.data.status.value # configure nexus with the groovy script. bash /vagrant/provision/execute-provision.groovy-script.sh # clean packages. apt-get -y autoremove apt-get -y clean