From e548aec9f8c3773044b4faf617ca19f03eb0a92e Mon Sep 17 00:00:00 2001 From: allan Date: Sun, 26 Oct 2025 14:41:49 +0000 Subject: [PATCH] initial commit --- LICENSE | 21 ++++++++++ README.md | 67 ++++++++++++++++++++++++++++++ last-tested | 4 ++ postfixinstall | 108 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 last-tested create mode 100755 postfixinstall diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3eaaa81 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Allan Christensen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6d2454e --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +# Postfix for Ubuntu 24.04 Server +[![OS](https://img.shields.io/badge/ubuntu-24.04-E95420)](#) +[![Shell](https://img.shields.io/badge/shell-bash-121011)](#) +[![MailServer](https://img.shields.io/badge/server-postfix-8B1E3F)](#) +[![License](https://img.shields.io/badge/License-MIT-green)](./LICENSE) + +Automated Bash installer for deploying **Postfix** non-interactively on Ubuntu 24.04 Server — ideal when you just need a working mail server and don’t want a screen full of configuration prompts. The script comes with an optional Mailutils installation flag. + +This is a **production-focused installer**, not a demo. + +--- + +### Preparing + +Update your package index before running the installer: + +``` +sudo apt update -y +``` + +--- + +### Download the Script + +Clone the repository from your Git server: + +``` +git clone https://git.x-files.dk/mail/postfix-ubuntu.git +``` + +``` +cd postfix-ubuntu +``` + +### Usage + +Run the script using the `-m` flag to control whether Mailutils will be installed as well (`yes` or `no`). + +``` +sudo ./postfixinstall -m +``` + +### Example + +Install Postfix **with** Mailutils: + +``` +sudo ./postfixinstall -m yes +``` + +Install Postfix **only**: + +``` +sudo ./postfixinstall -m no +``` + +--- + +### More Information + +More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk) + +--- + +### License + +Licensed under the [MIT License](./LICENSE). diff --git a/last-tested b/last-tested new file mode 100644 index 0000000..5995529 --- /dev/null +++ b/last-tested @@ -0,0 +1,4 @@ +------------------------------------ +Last tested: 26-10-2025 (DD-MM-YYYY) +Environment: Ubuntu Server 24.04 LTS +------------------------------------ diff --git a/postfixinstall b/postfixinstall new file mode 100755 index 0000000..1233132 --- /dev/null +++ b/postfixinstall @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# Author : Allan Christensen +# First Created : 17102020 (DD-MM-YYYY) +# Description : Installs Postfix and optionally Mailutils on Ubuntu 24.04 +# License : MIT License (see LICENSE file for details) + +# +# Are we root +# +if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit ; fi + +# +# Define variables and functions +# +install_utils="no" + +# +# Function to check if a service is already running or not +# +serviceyes () { printf "\n%s" $service ; printf " is already running cannot continue...\n\n"; } +servicealive () { status=$(systemctl is-active $service); if [[ "$status" == "active" ]]; then serviceyes ; exit 1; fi; } + +# +# Usage function +# +usage() { + printf "\nUsage:\n" + printf " sudo ./postfixinstall [-m yes|no]\n\n" + printf "Options:\n" + printf " -m Install Mailutils (defaults to no)\n" + printf " -h Show this help message\n\n" + printf "Examples:\n" + printf " sudo ./postfixinstall # install Postfix only\n" + printf " sudo ./postfixinstall -m yes # install Postfix + Mailutils\n\n" + exit 1 +} + +# +# If Postfix is already running then die +# +service="postfix" ; servicealive + +# +# Let's go +# +clear + +# +# Parse options +# +while getopts ":m:h" opt; do + case "${opt}" in + m) + arg="${OPTARG}" + if [[ -z "$arg" ]]; then + printf "\nOption -m requires an argument (yes/no).\n" + usage + fi + case "${arg,,}" in + y|yes) install_utils="yes" ;; + n|no) install_utils="no" ;; + *) usage ;; + esac + ;; + h) + usage + ;; + :) + printf "\nOption -%s requires an argument (yes/no).\n" "$OPTARG" + usage + ;; + \?) + printf "\nInvalid option: -%s\n" "$OPTARG" + usage + ;; + esac +done + +# +# Require -m flag +# +if [[ "$OPTIND" -eq 1 ]]; then + printf "\nMissing required option: -m \n" + usage +fi + +# +# Install Postfix (non-interactive) and backup main.cf +# +printf "\nInstalling Postfix...\n" +DEBIAN_FRONTEND=noninteractive apt-get install -y postfix >/dev/null 2>&1 +[[ -f /etc/postfix/main.cf ]] && cp -p /etc/postfix/main.cf /etc/postfix/main.cf.bak.$(date +%d-%m-%Y-%H%M%S) +systemctl enable postfix >/dev/null 2>&1 && systemctl restart postfix + +# +# Optionally install Mailutils +# +if [[ "$install_utils" == "yes" ]]; then apt-get install -y mailutils >/dev/null 2>&1 ; fi + +# +# All done +# +printf "\nAll Done...\n" + +# +# End of script +#