Refactor
* De-duplicate scripts
* Fix kernels to latest lts-xenial virt
Change-Id: I01280ad119146345eb02518ba80c2c6e8d37c40e
diff --git a/mirror-image/scripts/base.sh b/common/ubuntu_base.sh
similarity index 83%
rename from mirror-image/scripts/base.sh
rename to common/ubuntu_base.sh
index d23be8b..bae5120 100644
--- a/mirror-image/scripts/base.sh
+++ b/common/ubuntu_base.sh
@@ -60,20 +60,3 @@
# Disable apt-daily
systemctl disable apt-daily.timer
-
-# Motd
-apt-get -y install update-motd
-rm -vf /etc/update-motd.d/*
-echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S' -u)" > /etc/image_version
-echo "BUILD_TIMESTAMP_RFC=\"$(date -u -R)\"" >> /etc/image_version
-cat << 'EOF' >> /etc/update-motd.d/00-header-mirantis
-#!/bin/sh
-#
-# 00-header - create the header of the MOTD
-#
-[ -r /etc/image_version ] && . /etc/image_version
-echo "Ubuntu 16.04 \"Xenial\" Mirantis cloud image"
-echo "Build date: ${BUILD_TIMESTAMP_RFC}"
-EOF
-chmod +x /etc/update-motd.d/00-header-mirantis
-
diff --git a/mirror-image/scripts/cleanup.sh b/common/ubuntu_cleanup.sh
similarity index 100%
rename from mirror-image/scripts/cleanup.sh
rename to common/ubuntu_cleanup.sh
diff --git a/mirror-image/scripts/network.sh b/common/ubuntu_network.sh
similarity index 100%
rename from mirror-image/scripts/network.sh
rename to common/ubuntu_network.sh
diff --git a/mirror-image/scripts/security.sh b/common/ubuntu_security.sh
similarity index 100%
rename from mirror-image/scripts/security.sh
rename to common/ubuntu_security.sh
diff --git a/mirror-image/scripts/base.sh b/mirror-image/scripts/base.sh
new file mode 120000
index 0000000..140d77f
--- /dev/null
+++ b/mirror-image/scripts/base.sh
@@ -0,0 +1 @@
+../../common/ubuntu_base.sh
\ No newline at end of file
diff --git a/mirror-image/scripts/cleanup.sh b/mirror-image/scripts/cleanup.sh
new file mode 120000
index 0000000..cf970b6
--- /dev/null
+++ b/mirror-image/scripts/cleanup.sh
@@ -0,0 +1 @@
+../../common/ubuntu_cleanup.sh
\ No newline at end of file
diff --git a/mirror-image/scripts/motd.sh b/mirror-image/scripts/motd.sh
new file mode 100644
index 0000000..839a3e4
--- /dev/null
+++ b/mirror-image/scripts/motd.sh
@@ -0,0 +1,17 @@
+#!/bin/bash -xe
+# Motd
+apt-get -y install update-motd
+rm -vf /etc/update-motd.d/*
+echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S' -u)" > /etc/image_version
+echo "BUILD_TIMESTAMP_RFC=\"$(date -u -R)\"" >> /etc/image_version
+cat << 'EOF' >> /etc/update-motd.d/00-header-mirantis
+#!/bin/sh
+#
+# 00-header - create the header of the MOTD
+#
+[ -r /etc/image_version ] && . /etc/image_version
+echo "Ubuntu 16.04 \"Xenial\" Mirantis offline cloud image"
+echo "Build date: ${BUILD_TIMESTAMP_RFC}"
+EOF
+chmod +x /etc/update-motd.d/00-header-mirantis
+
diff --git a/mirror-image/scripts/network.sh b/mirror-image/scripts/network.sh
new file mode 120000
index 0000000..ab1de37
--- /dev/null
+++ b/mirror-image/scripts/network.sh
@@ -0,0 +1 @@
+../../common/ubuntu_network.sh
\ No newline at end of file
diff --git a/mirror-image/scripts/security.sh b/mirror-image/scripts/security.sh
new file mode 120000
index 0000000..3bd840a
--- /dev/null
+++ b/mirror-image/scripts/security.sh
@@ -0,0 +1 @@
+../../common/ubuntu_security.sh
\ No newline at end of file
diff --git a/mirror-image/template.json b/mirror-image/template.json
index f606787..819c8f1 100644
--- a/mirror-image/template.json
+++ b/mirror-image/template.json
@@ -66,6 +66,7 @@
"expect_disconnect": "true",
"scripts": [
"scripts/base.sh",
+ "scripts/motd.sh",
"scripts/network.sh",
"scripts/salt_bootstrap.sh",
"scripts/reboot.sh"
diff --git a/ubuntu-16.04/scripts/base.sh b/ubuntu-16.04/scripts/base.sh
deleted file mode 100644
index 9ab9e1e..0000000
--- a/ubuntu-16.04/scripts/base.sh
+++ /dev/null
@@ -1,74 +0,0 @@
-## Base packages and setup
-export DEBIAN_FRONTEND=noninteractive
-echo "exit 101" > /usr/sbin/policy-rc.d
-chmod +x /usr/sbin/policy-rc.d
-
-echo "Acquire::CompressionTypes::Order gz;" >/etc/apt/apt.conf.d/99compression-workaround-salt
-
-# Overwrite default mirrors
-echo "deb mirror://mirrors.ubuntu.com/mirrors.txt xenial main restricted multiverse universe" > /etc/apt/sources.list
-echo "deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-updates main restricted multiverse universe" >> /etc/apt/sources.list
-echo "deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-security main restricted multiverse universe" >> /etc/apt/sources.list
-echo "deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-backports main restricted multiverse universe" >> /etc/apt/sources.list
-
-# Add apt repository
-echo "deb [arch=amd64] http://apt.mirantis.com/xenial/ nightly salt" > /etc/apt/sources.list.d/mcp_salt.list
-echo "deb [arch=amd64] http://apt.mirantis.com/xenial/ nightly extra" > /etc/apt/sources.list.d/mcp_extra.list
-curl -sf http://apt.mirantis.com/public.gpg | apt-key add -
-
-apt-get clean
-apt-get update
-
-# Useful tools
-apt-get -y install byobu curl ethtool htop iputils-ping lsof strace tcpdump tmux traceroute tree vim-nox wget
-# Install common prerequisites
-apt-get -y install apt-transport-https libmnl0 python-apt python-m2crypto python-psutil
-
-# Cleanup old kernels, ensure latest is installed via virtual package
-apt-get purge -y linux-image-* linux-headers-*
-if [ ! -f /tmp/no_install_kernel ]; then
- # Use HWE kernel
- ## Temporary disable latest hwe due to: https://bugs.launchpad.net/ubuntu/+source/linux-hwe-edge/+bug/1679823
- #apt-get install -y linux-image-4.8.0-41-generic linux-image-extra-4.8.0-41-generic
- apt-get install -y linux-image-generic-hwe-16.04
-
- # Update grub cmdline
- sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8"|g' /etc/default/grub
- sed -i 's|GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8"|g' /etc/default/grub
- update-grub
-fi
-
-apt-get -y upgrade
-apt-get -y dist-upgrade
-
-apt-get autoremove --purge
-
-# Tmux fixes
-cat << 'EOF' >> /etc/tmux.conf
-set -g default-terminal "screen-256color"
-set -g set-titles on
-set -g xterm-keys on
-EOF
-
-# Setup cloud-init
-apt-get -y install cloud-init
-
-# Disable apt-daily
-systemctl disable apt-daily.timer
-
-# Motd
-apt-get -y install update-motd
-rm -vf /etc/update-motd.d/*
-echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S' -u)" > /etc/image_version
-echo "BUILD_TIMESTAMP_RFC=\"$(date -u -R)\"" >> /etc/image_version
-cat << 'EOF' >> /etc/update-motd.d/00-header-mirantis
-#!/bin/sh
-#
-# 00-header - create the header of the MOTD
-#
-[ -r /etc/image_version ] && . /etc/image_version
-echo "Ubuntu 16.04 \"Xenial\" Mirantis cloud image"
-echo "Build date: ${BUILD_TIMESTAMP_RFC}"
-EOF
-chmod +x /etc/update-motd.d/00-header-mirantis
-
diff --git a/ubuntu-16.04/scripts/base.sh b/ubuntu-16.04/scripts/base.sh
new file mode 120000
index 0000000..140d77f
--- /dev/null
+++ b/ubuntu-16.04/scripts/base.sh
@@ -0,0 +1 @@
+../../common/ubuntu_base.sh
\ No newline at end of file
diff --git a/ubuntu-16.04/scripts/cleanup.sh b/ubuntu-16.04/scripts/cleanup.sh
deleted file mode 100644
index 4d43fa7..0000000
--- a/ubuntu-16.04/scripts/cleanup.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-apt-get -y autoremove --purge
-apt-get -y clean
-rm -rf /var/lib/apt/lists/*
-
-rm -f /usr/sbin/policy-rc.d || true
-
-echo "cleaning up hostname"
-sed -i "/.*ubuntu-1604.*/d" /etc/hosts
-
-echo "cleaning up guest additions"
-rm -rf VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.? || true
-
-echo "cleaning up dhcp leases"
-rm -f /var/lib/dhcp/* || true
-
-echo "cleaning up udev rules"
-rm -f /etc/udev/rules.d/70-persistent-net.rules || true
-rm -rf /dev/.udev/ || true
-rm -f /lib/udev/rules.d/75-persistent-net-generator.rules || true
-
-echo "cleaning up minion_id for salt"
-rm -f /etc/salt/minion_id || true
-
diff --git a/ubuntu-16.04/scripts/cleanup.sh b/ubuntu-16.04/scripts/cleanup.sh
new file mode 120000
index 0000000..cf970b6
--- /dev/null
+++ b/ubuntu-16.04/scripts/cleanup.sh
@@ -0,0 +1 @@
+../../common/ubuntu_cleanup.sh
\ No newline at end of file
diff --git a/ubuntu-16.04/scripts/motd.sh b/ubuntu-16.04/scripts/motd.sh
new file mode 100644
index 0000000..ac02585
--- /dev/null
+++ b/ubuntu-16.04/scripts/motd.sh
@@ -0,0 +1,17 @@
+#!/bin/bash -xe
+# Motd
+apt-get -y install update-motd
+rm -vf /etc/update-motd.d/*
+echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S' -u)" > /etc/image_version
+echo "BUILD_TIMESTAMP_RFC=\"$(date -u -R)\"" >> /etc/image_version
+cat << 'EOF' >> /etc/update-motd.d/00-header-mirantis
+#!/bin/sh
+#
+# 00-header - create the header of the MOTD
+#
+[ -r /etc/image_version ] && . /etc/image_version
+echo "Ubuntu 16.04 \"Xenial\" Mirantis cloud image"
+echo "Build date: ${BUILD_TIMESTAMP_RFC}"
+EOF
+chmod +x /etc/update-motd.d/00-header-mirantis
+
diff --git a/ubuntu-16.04/scripts/network.sh b/ubuntu-16.04/scripts/network.sh
deleted file mode 100644
index 3885590..0000000
--- a/ubuntu-16.04/scripts/network.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-echo "timeout 10;
-backoff-cutoff 0;
-initial-interval 0;
-retry 15;" >> /etc/dhcp/dhclient.conf
diff --git a/ubuntu-16.04/scripts/network.sh b/ubuntu-16.04/scripts/network.sh
new file mode 120000
index 0000000..ab1de37
--- /dev/null
+++ b/ubuntu-16.04/scripts/network.sh
@@ -0,0 +1 @@
+../../common/ubuntu_network.sh
\ No newline at end of file
diff --git a/ubuntu-16.04/scripts/salt.sh b/ubuntu-16.04/scripts/salt.sh
index 0213bfc..dd13dfd 100644
--- a/ubuntu-16.04/scripts/salt.sh
+++ b/ubuntu-16.04/scripts/salt.sh
@@ -1,3 +1,10 @@
+#!/bin/bash -xe
+
+# Add apt repository
+echo "deb [arch=amd64] http://apt.mirantis.com/xenial/ nightly salt" > /etc/apt/sources.list.d/mcp_salt.list
+echo "deb [arch=amd64] http://apt.mirantis.com/xenial/ nightly extra" > /etc/apt/sources.list.d/mcp_extra.list
+curl -sf http://apt.mirantis.com/public.gpg | apt-key add -
+
wget -O - https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
echo "deb http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" >/etc/apt/sources.list.d/saltstack.list
apt-get update
diff --git a/ubuntu-16.04/scripts/security.sh b/ubuntu-16.04/scripts/security.sh
deleted file mode 100644
index 32ff37e..0000000
--- a/ubuntu-16.04/scripts/security.sh
+++ /dev/null
@@ -1,50 +0,0 @@
-# Auto login root on tty1
-sed 's|/sbin/agetty|/sbin/agetty --autologin root|g' /etc/systemd/system/getty.target.wants/getty@tty1.service > /etc/systemd/system/getty-autologin@.service
-systemctl daemon-reload
-systemctl disable getty@tty1.service
-systemctl enable getty-autologin@tty1.service
-
-# Libvirt serial console support
-cat << 'EOF' >> /etc/systemd/system/serial-getty@.service
-[Unit]
-Description=Getty on %I
-Documentation=man:agetty(8) man:systemd-getty-generator(8)
-Documentation=http://0pointer.de/blog/projects/serial-console.html
-After=systemd-user-sessions.service plymouth-quit-wait.service
-After=rc-local.service
-
-Before=getty.target
-IgnoreOnIsolate=yes
-
-ConditionPathExists=/dev/ttyS0
-
-[Service]
-ExecStart=-/sbin/agetty --autologin root -8 --noclear %I 115200 $TERM
-Type=idle
-Restart=always
-RestartSec=0
-UtmpIdentifier=%I
-TTYPath=/dev/%I
-TTYReset=yes
-TTYVHangup=yes
-TTYVTDisallocate=yes
-KillMode=process
-IgnoreSIGPIPE=no
-SendSIGHUP=yes
-
-Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
-
-[Install]
-WantedBy=getty.target
-DefaultInstance=ttyS0
-EOF
-
-systemctl daemon-reload
-systemctl enable serial-getty@ttyS0.service
-
-# Disable password root login
-usermod -p '!' root
-
-# Disable SSH password authentication and permit root login
-sed -i 's|[#]*PasswordAuthentication yes|PasswordAuthentication no|g' /etc/ssh/sshd_config
-sed -i 's|[#]*PermitRootLogin no|PermitRootLogin yes|g' /etc/ssh/sshd_config
diff --git a/ubuntu-16.04/scripts/security.sh b/ubuntu-16.04/scripts/security.sh
new file mode 120000
index 0000000..3bd840a
--- /dev/null
+++ b/ubuntu-16.04/scripts/security.sh
@@ -0,0 +1 @@
+../../common/ubuntu_security.sh
\ No newline at end of file
diff --git a/ubuntu-16.04/template.json b/ubuntu-16.04/template.json
index aa80d0a..564dd69 100644
--- a/ubuntu-16.04/template.json
+++ b/ubuntu-16.04/template.json
@@ -14,6 +14,7 @@
"virtualbox-iso": {
"scripts": [
"scripts/base.sh",
+ "scripts/motd.sh",
"scripts/salt.sh",
"scripts/network.sh",
"scripts/vagrant.sh",
@@ -26,6 +27,7 @@
"vmware-iso": {
"scripts": [
"scripts/base.sh",
+ "scripts/motd.sh",
"scripts/salt.sh",
"scripts/vmware.sh",
"scripts/security.sh",
@@ -36,6 +38,7 @@
"qemu": {
"scripts": [
"scripts/base.sh",
+ "scripts/motd.sh",
"scripts/salt.sh",
"scripts/network.sh",
"scripts/security.sh",
@@ -47,6 +50,7 @@
"scripts": [
"scripts/docker.sh",
"scripts/base.sh",
+ "scripts/motd.sh",
"scripts/salt.sh",
"scripts/cleanup.sh"
]
@@ -54,6 +58,7 @@
"digitalocean": {
"scripts": [
"scripts/base.sh",
+ "scripts/motd.sh",
"scripts/salt.sh",
"scripts/security.sh",
"scripts/cleanup.sh"