From 08bd9b2f0d584c77c34d5fee1e95724ac3765d96 Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Sun, 19 May 2024 23:27:56 +0200 Subject: [PATCH] Fixup --- installers/000_apt.sh | 1 + installers/001_bash.sh | 1 + installers/002_timezone.sh | 1 + installers/003_dos2unix.sh | 2 +- installers/004_gpgagent.sh | 3 +- installers/050_runit.sh | 1 + installers/100_cron.sh | 1 + installers/101_rsyslog.sh | 1 + installers/102_logrotate.sh | 1 + installers/900_utils.sh | 1 + installers/901_jq.sh | 1 + installers/902_cpu_monitoring.sh | 3 +- installers/903_version_control.sh | 1 + installers/904_redis.sh | 1 + installers/905_xtail.sh | 1 + installers/999_cleanup.sh | 1 + usr/local/lib/marshall_installer | 157 ++++++++++++++++++++++++++++++ 17 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 usr/local/lib/marshall_installer diff --git a/installers/000_apt.sh b/installers/000_apt.sh index 4dae777..7e38356 100755 --- a/installers/000_apt.sh +++ b/installers/000_apt.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091,SC2312 source /installers/config echo "force-unsafe-io" >/etc/dpkg/dpkg.cfg.d/force-unsafe-io diff --git a/installers/001_bash.sh b/installers/001_bash.sh index 1c1df7a..7fe9012 100755 --- a/installers/001_bash.sh +++ b/installers/001_bash.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /installers/config ${APT_GET} bash diff --git a/installers/002_timezone.sh b/installers/002_timezone.sh index a04c849..80ad5b8 100755 --- a/installers/002_timezone.sh +++ b/installers/002_timezone.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /installers/config ${APT_GET} tzdata diff --git a/installers/003_dos2unix.sh b/installers/003_dos2unix.sh index 8591dff..4ad4cfd 100755 --- a/installers/003_dos2unix.sh +++ b/installers/003_dos2unix.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bashset -e # shellcheck disable=SC1091 source /installers/config ${APT_GET} dos2unix diff --git a/installers/004_gpgagent.sh b/installers/004_gpgagent.sh index 805b833..bceccd3 100755 --- a/installers/004_gpgagent.sh +++ b/installers/004_gpgagent.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /installers/config -${APT_GET} gpg-agent +${APT_GET} gpg-agent gnupg diff --git a/installers/050_runit.sh b/installers/050_runit.sh index 56c1ffd..d5ebd27 100755 --- a/installers/050_runit.sh +++ b/installers/050_runit.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /installers/config ${APT_GET} \ diff --git a/installers/100_cron.sh b/installers/100_cron.sh index 41c1f81..ff69ea3 100755 --- a/installers/100_cron.sh +++ b/installers/100_cron.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /installers/config ${APT_GET} cron diff --git a/installers/101_rsyslog.sh b/installers/101_rsyslog.sh index 9b31db8..7d62a37 100755 --- a/installers/101_rsyslog.sh +++ b/installers/101_rsyslog.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /installers/config ${APT_GET} rsyslog diff --git a/installers/102_logrotate.sh b/installers/102_logrotate.sh index 4942bc5..67665ad 100755 --- a/installers/102_logrotate.sh +++ b/installers/102_logrotate.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e mkdir -p /etc/service/logrotate mv /etc/service/logrotate/logrotate.runit /etc/service/logrotate/run chmod +x /etc/service/logrotate/run diff --git a/installers/900_utils.sh b/installers/900_utils.sh index c7666e1..03f1b5c 100755 --- a/installers/900_utils.sh +++ b/installers/900_utils.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /usr/local/lib/marshall_installer title "Utils" diff --git a/installers/901_jq.sh b/installers/901_jq.sh index 437b4be..4a308a4 100644 --- a/installers/901_jq.sh +++ b/installers/901_jq.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /usr/local/lib/marshall_installer add_ppa ppa:rmescandon/yq diff --git a/installers/902_cpu_monitoring.sh b/installers/902_cpu_monitoring.sh index d277a3f..5fb65af 100755 --- a/installers/902_cpu_monitoring.sh +++ b/installers/902_cpu_monitoring.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /usr/local/lib/marshall_installer -install htop btop cpulimit +install htop cpulimit diff --git a/installers/903_version_control.sh b/installers/903_version_control.sh index b45e67d..8cfb9cb 100755 --- a/installers/903_version_control.sh +++ b/installers/903_version_control.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091,SC2164 source /usr/local/lib/marshall_installer title "Installing version control tools" diff --git a/installers/904_redis.sh b/installers/904_redis.sh index 4dabe1e..9fc5d0b 100644 --- a/installers/904_redis.sh +++ b/installers/904_redis.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /usr/local/lib/marshall_installer install redis-tools diff --git a/installers/905_xtail.sh b/installers/905_xtail.sh index 6ac7768..b89cea5 100755 --- a/installers/905_xtail.sh +++ b/installers/905_xtail.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /usr/local/lib/marshall_installer install "xtail" diff --git a/installers/999_cleanup.sh b/installers/999_cleanup.sh index b08ce28..e5ff1c0 100755 --- a/installers/999_cleanup.sh +++ b/installers/999_cleanup.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e # shellcheck disable=SC1091 source /installers/config cd / diff --git a/usr/local/lib/marshall_installer b/usr/local/lib/marshall_installer new file mode 100644 index 0000000..0d00878 --- /dev/null +++ b/usr/local/lib/marshall_installer @@ -0,0 +1,157 @@ +#!/bin/bash +set -e +# Define our pool of colours +export COLOUR_BLACK='\e[30m' +export COLOUR_RED='\e[31m' +export COLOUR_GREEN='\e[32m' +export COLOUR_YELLOW='\e[33m' +export COLOUR_BLUE='\e[34m' +export COLOUR_MAGENTA='\e[35m' +export COLOUR_CYAN='\e[36m' +export COLOUR_DIM_WHITE='\e[37m' +export COLOUR_BRIGHT_BLACK='\e[90m' +export COLOUR_BRIGHT_RED='\e[91m' +export COLOUR_BRIGHT_GREEN='\e[92m' +export COLOUR_BRIGHT_YELLOW='\e[93m' +export COLOUR_BRIGHT_BLUE='\e[94m' +export COLOUR_BRIGHT_MAGENTA='\e[95m' +export COLOUR_BRIGHT_CYAN='\e[96m' +export COLOUR_WHITE='\e[97m' +export COLOUR_RESET='\e[0m' +export COLOUR_BOLD='\e[1m' +export COLOUR_UNDERLINE='\e[4m' + +# Add some aliases for colours +export COLOUR_FAIL=$COLOUR_BRIGHT_RED +export COLOUR_SUCCESS=$COLOUR_BRIGHT_GREEN + +export DEFAULT_TZ='Europe/London' + +export LC_ALL=C +export DEBIAN_FRONTEND=noninteractive +export DEBIAN_PRIORITY=critical +export DEBCONF_NONINTERACTIVE_SEEN=true +export APT_UPDATE='apt-get -yqq update' +export APT_UPGRADE='apt-get -yqq upgrade ' +export APT_GET='apt-get -yqq install' +export APT_REMOVE='apt-get -yqq remove' +export APT_CLEAN='apt-get -yqq clean' +export APT_AUTOREMOVE='apt-get -yqq autoremove' + +UBUNTU_VERSION=$(grep "VERSION=" /etc/os-release | cut -d'=' -f2 | sed -e 's/\"//g') +UBUNTU_VERSION_CODENAME=$(grep "VERSION_CODENAME=" /etc/os-release | cut -d'=' -f2 | sed -e 's/\"//g') +export UBUNTU_VERSION +export UBUNTU_VERSION_CODENAME + +DU='du --exclude /proc' + +function disk_usage(){ + $DU -hs / | cut -f1 +} + +function indent(){ + for ((n=0;n<${1};n++)); do + printf ' ' + done +} +function title() { + indent 0 + printf ' > %s' "$1" + if [ -n "$2" ]; then + printf ' %b%s%b' "$COLOUR_SUCCESS" "$2" "$COLOUR_RESET" + fi + printf '\n' +} +function subtitle(){ + indent 1 + title "$@" +} +function subsubtitle(){ + indent 2 + title "$@" +} +function install() { + for var in "$@" + do + printf ' > Installing: %b%s%b\n' "$COLOUR_SUCCESS" "$var" "$COLOUR_RESET" + done + # shellcheck disable=SC2086 + $APT_GET "$@" +} +function update(){ + printf ' > APT: %b%s%b\n' "$COLOUR_SUCCESS" "Update" "$COLOUR_RESET" + $APT_UPDATE +} +function upgrade(){ + printf ' > APT: %b%s%b\n' "$COLOUR_SUCCESS" "Upgrade" "$COLOUR_RESET" + $APT_UPGRADE 2>/dev/null 1>&2 +} + +function remove() { + for var in "$@" + do + printf ' > Removing: %b%s%b\n' "$COLOUR_SUCCESS" "$var" "$COLOUR_RESET" + done + # shellcheck disable=SC2086 + $APT_REMOVE "$@" 2>/dev/null 1>&2 +} + +function package_clean(){ + title "Cleaning up packages"; + $APT_AUTOREMOVE 2>/dev/null 1>&2; + $APT_CLEAN 2>/dev/null 1>&2; +} + +function add_ppa() { + PPA=$([ "$1" == "-y" ] && echo "$2" || echo "$1") + PPA_NAME=${PPA/#ppa:/} + + AUTHOR=$(echo "$PPA_NAME" | cut -d'/' -f1); + PACKAGE=$(echo "$PPA_NAME" | cut -d'/' -f2); + SIGNING_KEY="/usr/share/keyrings/${AUTHOR}-${PACKAGE}.gpg" + FILENAME="${AUTHOR}-${PACKAGE}-${UBUNTU_VERSION_CODENAME}.list" + FULL_APT_SOURCES_PATH="/etc/apt/sources.list.d/$FILENAME.list" + if [ -f "$FULL_APT_SOURCES_PATH" ]; then + subtitle "Skipping existing PPA:" "$PPA_NAME"; + return; + fi + + subtitle "Adding PPA:" "$PPA_NAME"; + KEY=$(curl --silent "https://launchpad.net/~$AUTHOR/+archive/ubuntu/$PACKAGE/" | grep "" | tr -d ' ' | sed 's/<[^>]*>//g'); + SEARCH=$(echo "$KEY" | cut -d'/' -f2); + PPA_PATH="https://ppa.launchpadcontent.net/${AUTHOR}/${PACKAGE}/ubuntu" + + if [ ! -f "$SIGNING_KEY" ]; then + curl --silent "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x$SEARCH" | gpg --dearmor -o "$SIGNING_KEY" + fi + + echo "deb [signed-by=${SIGNING_KEY}] ${PPA_PATH} ${UBUNTU_VERSION_CODENAME} main" > "$FULL_APT_SOURCES_PATH"; + echo "# deb-src [signed-by=${SIGNING_KEY}] ${PPA_PATH} ${UBUNTU_VERSION_CODENAME} main" >> "$FULL_APT_SOURCES_PATH"; + + update +} +function detect_package(){ + PACKAGE_COUNT=$(dpkg --get-selections | grep -v deinstall | cut -f1 | grep -c "$1") + printf " > There are %b%d%b packages matching %b%s%b\n" \ + "$COLOUR_MAGENTA" "$PACKAGE_COUNT" "$COLOUR_RESET" \ + "$COLOUR_BRIGHT_CYAN" "$1" "$COLOUR_RESET" + dpkg --get-selections | grep -v deinstall | cut -f1 | grep "$1" + printf "\n" +} +function largest_files_in_path(){ + printf "Disk usage by %bfile%b size in %b%s%b:\n" \ + "$COLOUR_BRIGHT_RED" "$COLOUR_RESET" \ + "$COLOUR_MAGENTA" "$1" "$COLOUR_RESET" + # shellcheck disable=SC2012 + $DU --max-depth=1 "$1" | sed '$ d' | sort -h | tac | head -n10 + printf "\n" +} + +function largest_directories_in_path(){ + printf "Disk usage by %bdirectory%b size in %b%s%b:\n" \ + "$COLOUR_BRIGHT_RED" "$COLOUR_RESET" \ + "$COLOUR_MAGENTA" "$1" "$COLOUR_RESET" + # shellcheck disable=SC2012 + $DU "$1" | sed '$ d' | sort -h | tac | head -n10 + printf "\n" +}