From 66269f910f09f3c49e2a319f8689293cba2e4337 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Thu, 1 May 2014 19:13:00 +0000 Subject: [PATCH] make a bash function to use everywhere we apt-get-install (`DEBIAN_FRONTEND=noninteractive apt-get -qq -y `) ensures the output is quiet --- scripts/dkim.sh | 4 +++- scripts/dns.sh | 4 +++- scripts/functions.sh | 21 +++++++++++++++++++++ scripts/mail.sh | 3 ++- scripts/spamassassin.sh | 4 +++- scripts/system.sh | 10 ++++++---- scripts/web.sh | 4 +++- scripts/webmail.sh | 4 ++-- 8 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 scripts/functions.sh diff --git a/scripts/dkim.sh b/scripts/dkim.sh index 88dc36e..45925de 100644 --- a/scripts/dkim.sh +++ b/scripts/dkim.sh @@ -4,8 +4,10 @@ # After this, you'll still need to run dns_update.sh to get the DKIM # signature in the DNS zones. +source scripts/functions.sh # load our functions + # Install DKIM -apt-get install -q -y opendkim opendkim-tools +apt_install opendkim opendkim-tools # Make sure configuration directories exist. mkdir -p /etc/opendkim; diff --git a/scripts/dns.sh b/scripts/dns.sh index 4244cbc..4ac7790 100644 --- a/scripts/dns.sh +++ b/scripts/dns.sh @@ -7,6 +7,8 @@ # # This script will turn on DNS for $PUBLIC_HOSTNAME. +source scripts/functions.sh # load our functions + # Install nsd, our DNS server software. # ...but first, we have to create the user because the @@ -20,7 +22,7 @@ fi # Okay now install the package. -apt-get -qq -y install nsd +apt_install nsd # Prepare nsd's configuration. diff --git a/scripts/functions.sh b/scripts/functions.sh new file mode 100644 index 0000000..2cf8e15 --- /dev/null +++ b/scripts/functions.sh @@ -0,0 +1,21 @@ +function apt_install { + # Report any packages already installed. + PACKAGES=$@ + TO_INSTALL="" + for pkg in $PACKAGES; do + if dpkg -s $pkg 2>/dev/null | grep "^Status: install ok installed" > /dev/null; then + echo $pkg is already installed \(`dpkg -s $pkg | grep ^Version: | sed -e "s/.*: //"`\) + else + TO_INSTALL="$TO_INSTALL""$pkg " + fi + done + + # List the packages about to be installed. + if [[ ! -z "$TO_INSTALL" ]]; then + echo installing $TO_INSTALL... + fi + + # 'DEBIAN_FRONTEND=noninteractive' is to prevent dbconfig-common from asking you questions. + DEBIAN_FRONTEND=noninteractive apt-get -qq -y install $PACKAGES > /dev/null; +} + diff --git a/scripts/mail.sh b/scripts/mail.sh index 9a5d0e2..e43fc9d 100755 --- a/scripts/mail.sh +++ b/scripts/mail.sh @@ -12,9 +12,10 @@ # Install packages. +source scripts/functions.sh # load our functions source /etc/mailinabox.conf # load global vars -DEBIAN_FRONTEND=noninteractive apt-get -q -y install \ +apt_install \ postfix postgrey \ dovecot-core dovecot-imapd dovecot-lmtpd dovecot-sqlite sqlite3 \ openssl diff --git a/scripts/spamassassin.sh b/scripts/spamassassin.sh index 71f969a..f66a3b2 100644 --- a/scripts/spamassassin.sh +++ b/scripts/spamassassin.sh @@ -9,8 +9,10 @@ # plugin. The tools/mail.py tool creates the necessary sieve script for each mail # user when the mail user is created. +source scripts/functions.sh # load our functions + # Install packages. -apt-get -q -y install spampd razor pyzor dovecot-sieve dovecot-antispam +apt_install spampd razor pyzor dovecot-sieve dovecot-antispam # Allow spamassassin to download new rules. tools/editconf.py /etc/default/spamassassin \ diff --git a/scripts/system.sh b/scripts/system.sh index 5b2c806..293549b 100755 --- a/scripts/system.sh +++ b/scripts/system.sh @@ -1,10 +1,12 @@ +source scripts/functions.sh # load our functions + # Base system configuration. apt-get -q -q update apt-get -q -y upgrade # Install openssh-server to ensure that the end result is consistent across all Mail-in-a-Boxes. -apt-get -q -y install openssh-server +apt_install openssh-server # Check that SSH login with password is disabled. Stop if it's enabled. if grep -q "^PasswordAuthentication yes" /etc/ssh/sshd_config \ @@ -18,7 +20,7 @@ if grep -q "^PasswordAuthentication yes" /etc/ssh/sshd_config \ exit fi -apt-get -q -y install python3 +apt_install python3 # Turn on basic services: # @@ -28,11 +30,11 @@ apt-get -q -y install python3 # # These services don't need further configuration and are started immediately after installation. -apt-get -q -y install ntp fail2ban +apt_install ntp fail2ban # Turn on the firewall. First allow incoming SSH, then turn on the firewall. # Other ports will be opened at the point where we set up those services. -apt-get -q -y install ufw; +apt_install ufw ufw allow ssh; ufw --force enable; diff --git a/scripts/web.sh b/scripts/web.sh index c078679..9277e9f 100755 --- a/scripts/web.sh +++ b/scripts/web.sh @@ -1,12 +1,14 @@ # HTTP: Turn on a web server serving static files ################################################# +source scripts/functions.sh # load our functions + # Remove Apache before installing Nginx. Apache may leave # some unwanted configuration files around (e.g. a ufw # application config), so purge the packages. apt-get purge -q -y apache2 apache2.2-common -apt-get install -q -y nginx php5-cgi +apt_install nginx php5-cgi rm -f /etc/nginx/sites-enabled/default diff --git a/scripts/webmail.sh b/scripts/webmail.sh index c19215a..d842911 100755 --- a/scripts/webmail.sh +++ b/scripts/webmail.sh @@ -1,6 +1,7 @@ # Webmail: Using roundcube ########################## +source scripts/functions.sh # load our functions source /etc/mailinabox.conf # load global vars # Ubuntu's roundcube-core has a dependency on Apache & MySQL, which we don't want, so we can't @@ -8,10 +9,9 @@ source /etc/mailinabox.conf # load global vars # dependencies of roundcube that we know we need, and then we'll manually install debs for the # roundcube version we want from Debian. # -# 'DEBIAN_FRONTEND=noninteractive' is to prevent dbconfig-common from asking you questions. # The dependencies are from 'apt-cache showpkg roundcube-core'. -DEBIAN_FRONTEND=noninteractive apt-get -q -q -y install \ +apt_install \ dbconfig-common \ php5 php5-sqlite php5-mcrypt php5-intl php5-json php5-common php-auth php-net-smtp php-net-socket php-net-sieve php-mail-mime php-crypt-gpg php5-gd php5-pspell \ tinymce libjs-jquery libjs-jquery-mousewheel libmagic1