#!/bin/bash set -e [[ -z $1 ]] && echo ansible host group? && exit 1 ansible_group=$1 # just in case one runs the script outside ansible [[ `pwd` != /root ]] && echo error: assuming current working directory /root/ && exit 1 [[ ! -x `which lsb_release` ]] && echo error: lsb_release executable not found && exit 1 [[ ! -x `which systemctl` ]] && echo error: systemctl executable not found && exit 1 [[ ! -x `which update-alternatives` ]] && echo error: update-alternatives executable not found && exit 1 export DEBIAN_FRONTEND=noninteractive export SYSTEMD_COLORS=0 export SYSTEMD_URLIFY=0 export LANG=en_US.UTF-8 export LANGUAGE=en_US:en export LC_ALL=en_US.UTF-8 # no need for graphical startup on a server if [[ $ansible_group != stations ]]; then echo -n disable x11 at boot-time ... [[ `systemctl get-default` != multi-user.target ]] && systemctl set-default multi-user && echo done || echo already fi distro=`lsb_release -is 2>/dev/null` if [[ $distro = Ubuntu ]]; then echo -n remove ubuntu-advantage-tools package ... [[ -n `dpkg -l | grep advantage` ]] && \ apt-get -q -y purge ubuntu-advantage-tools >/dev/null 2>&1 && echo done || echo already rm -rf /etc/ubuntu-advantage/ rm -rf /var/lib/ubuntu-advantage/ rm -rf /var/lib/update-manager/ fi echo -n update package cache \(/var/tmp/few_packages.log\) ... apt-get -q -y update > /var/tmp/few_packages.log 2>&1 && echo done || echo FAIL echo '' >> /var/tmp/few_packages.log echo -n install few packages \(/var/tmp/few_packages.log\) ... apt-get -q -y install \ bash-completion \ bind9-dnsutils \ colordiff \ curl \ gnupg1 \ ifupdown \ jq \ lsb-release \ man-db \ manpages \ mlocate \ net-tools \ vim-nox \ wget >> /var/tmp/few_packages.log 2>&1 && echo done || echo FAIL echo '' >> /var/tmp/few_packages.log # todo handle /etc/bash.bashrc from template echo -n vim-nox as default vi ... update-alternatives --set vi /usr/bin/vim.nox && echo done || echo FAIL echo -n vim-nox as default editor ... update-alternatives --set editor /usr/bin/vim.nox && echo done || echo FAIL # todo - take advantage of connecting ansible username if there is any for homedir in /root `find /home/ -maxdepth 1 -mindepth 1 -type d`; do user=${homedir##*/} [[ $user = root ]] && grp=root || grp=users echo -n tuning $homedir/.vimrc ... [[ ! -f $homedir/.vimrc ]] && cat > $homedir/.vimrc < $homedir/.selected_editor < /etc/sudoers.clean grep -vE '^#|^$' /etc/sudoers.dist > /etc/sudoers elif [[ ! -f /etc/sudoers ]]; then echo no sudoers file fi # assuming w/o oslogin echo -n cleaning-up sshd_config ... if [[ -f /etc/ssh/sshd_config && -f /etc/ssh/sshd_config.dist ]]; then echo already elif [[ ! -f /etc/ssh/sshd_config ]]; then echo openssh-server does not seem to be installed else mv -i /etc/ssh/sshd_config /etc/ssh/sshd_config.dist grep -vE '^#|^$' /etc/ssh/sshd_config.dist > /etc/ssh/sshd_config.clean grep -vE '^#|^$' /etc/ssh/sshd_config.dist > /etc/ssh/sshd_config && echo done changed=1 fi echo -n cleaning-up ssh_config ... if [[ -f /etc/ssh/ssh_config && -f /etc/ssh/ssh_config.dist ]]; then echo already elif [[ ! -f /etc/ssh/ssh_config ]]; then echo openssh-client does not seem to be installed else mv -i /etc/ssh/ssh_config /etc/ssh/ssh_config.dist grep -vE '^#|^$' /etc/ssh/ssh_config.dist > /etc/ssh/ssh_config.clean grep -vE '^#|^$' /etc/ssh/ssh_config.dist > /etc/ssh/ssh_config && echo done changed=1 fi # ok=1 changed=0 [[ -z $changed ]] && echo ok - nothing \(or almost nothing\) changed && exit 0 # ok=1 changed=1 echo changed - all done