#!/bin/bash set -e pkg=sshguard export DEBIAN_FRONTEND=noninteractive # ansible.builtin.script: # chdir: /root # just in case one runs the script outside ansible cd /root/ [[ ! -x `which dpkg` ]] && echo error: dpkg executable not found && exit 1 # we do not check for latest version right here echo -n checking $pkg package ... if dpkg -s $pkg >/dev/null 2>&1; then # ok=1 changed=0 echo already else echo missing echo -n update package cache ... apt-get -q -y update >/dev/null 2>&1 && echo done || echo FAIL # eventually failed=1 echo -n installing $pkg ... apt-get -q -y install $pkg >/dev/null 2>&1 && echo done || echo FAIL changed=1 systemctl enable sshguard --now fi [[ -z $changed ]] && echo nothing changed && exit 0 # ok=1 changed=1 echo changed - all done