#!/bin/bash # # Federated Checks PATH=$HOME/.docker/cli-plugins:/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin check_docker() { OSRELEASE=`lsb_release -a 2>/dev/null | grep ID | awk -F: '{ print $2 }' | xargs` if ! command -v docker &> /dev/null; then echo -ne "\n* Couldn't find docker, installing.." spin & SPINPID=$! # Install Docker on Ubuntu if [ $OSRELEASE == "Ubuntu" ]; then # Update list of packages sudo apt-get update -y &> /dev/null [ $? -ne 0 ] && failcheck "Couldn't run sudo apt-get update" # Install packages which let apt use packages over HTTPS sudo apt install apt-transport-https ca-certificates curl software-properties-common -y &> /dev/null [ $? -ne 0 ] && failcheck "Couldn't run sudo apt install for https packages" # Add GPG key for the official Docker repository to this system curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - &> /dev/null [ $? -ne 0 ] && failcheck "Couldn't run curl to add Docker GPG key" # Add the docker repository to our APT sources list sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable" -y &> /dev/null [ $? -ne 0 ] && failcheck "Couldn't run sudo add-apt-repository" # Install docker packages sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose -y &> /dev/null [ $? -ne 0 ] && failcheck "Couldn't run sudo apt install docker packages" fi kill -9 $SPINPID &> /dev/null echo -ne "done." fi if ! command -v docker-compose &> /dev/null; then echo -ne "\n* Couldn't find docker-compose, installing.." spin & SPINPID=$! # Install Docker compose on Ubuntu if [ $OSRELEASE == "Ubuntu" ]; then sudo apt-get install docker-compose -y &> /dev/null fi kill -9 $SPINPID &> /dev/null echo -ne "done." fi } check_ports() { EXTERNALIP=`dig @resolver4.opendns.com myip.opendns.com +short 2> /dev/null` [ $? -ne 0 ] && failcheck "Couldn't run dig, dns is not working" # Check if ss command exists if command -v ss &> /dev/null; then # Check every port we need if it's in use for i in 25 53 80 143 389 587 993 8000; do SS=`ss -tulwn | grep LISTEN | awk '{ print $5 }' | awk -F: '{ print $NF }' | grep "^$i$" | head -1` # If port 53 (dns) in use by system-resolvd (Ubuntu) then auto fix if [ "$SS" == 53 ]; then if [ $OSRELEASE == "Ubuntu" ]; then if [ `pgrep -x systemd-resolve` ]; then echo -ne "\n* Port 53 in use by systemd-resolved, fixing.." spin & SPINPID=$! # Install resolvconf to fix sudo apt install resolvconf -y &> /dev/null [ $? -eq 0 ] && echo -ne "." || failcheck "Failed running sudo apt install resolvconf" # Shut down systemd-resolved systemctl stop systemd-resolved &> /dev/null [ $? -ne 0 ] && failcheck "Failed running systemctl stop systemd-resolved" systemctl disable systemd-resolved &> /dev/null [ $? -ne 0 ] && failcheck "Failed running systemctl stop systemd-resolved" # Put nameserver entries so will exist on reboot echo "nameserver 8.8.8.8" > /etc/resolvconf/resolv.conf.d/tail echo "nameserver 8.8.8.8" > /run/resolvconf/resolv.conf kill -9 $SPINPID &> /dev/null echo -ne "done." else echo -ne "\nFAILED - Port 53 (dns) is already in use\n\n" && exit 2 fi fi elif [ "$SS" == "$i" ]; then failcheck "FAILED - Port $i is already in use" fi done fi }