From ef897995747bfe3cd005b35951bf8d15c6e74f55 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Wed, 3 Jan 2018 18:34:50 +0000
Subject: [PATCH] I think it's about time I committed this.... :P

---
 .gitignore              |  8 ++++
 cloudcatcher-info.sh    | 90 +++++++++++++++++++++++++++++++++++++++++
 cloudcatcher.sh         | 24 +++++++++++
 parse_interface_ips.awk | 16 ++++++++
 4 files changed, 138 insertions(+)
 create mode 100644 .gitignore
 create mode 100755 cloudcatcher-info.sh
 create mode 100755 cloudcatcher.sh
 create mode 100644 parse_interface_ips.awk

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c493f59
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+.cloudcatcher_settings
+
+# Created by https://www.gitignore.io/api/git
+
+### Git ###
+*.orig
+
+# End of https://www.gitignore.io/api/git
diff --git a/cloudcatcher-info.sh b/cloudcatcher-info.sh
new file mode 100755
index 0000000..327c276
--- /dev/null
+++ b/cloudcatcher-info.sh
@@ -0,0 +1,90 @@
+#!/usr/bin/env bash
+
+
+#############################################
+# ███████ ███████ ████████ ██    ██ ██████  #
+# ██      ██         ██    ██    ██ ██   ██ #
+# ███████ █████      ██    ██    ██ ██████  #
+#      ██ ██         ██    ██    ██ ██      #
+# ███████ ███████    ██     ██████  ██      #
+#############################################
+
+tmpdir="$(mktemp --directory --suffix -cloudcatcher)/";
+
+##########################
+### Colour Definitions ###
+#### ANSI color codes ####
+RS="\033[0m"    # reset
+HC="\033[1m"    # hicolor
+UL="\033[4m"    # underline
+INV="\033[7m"   # inverse background and foreground
+LC="\033[2m"    # locolor / dim
+FBLK="\033[30m" # foreground black
+FRED="\033[31m" # foreground red
+FGRN="\033[32m" # foreground green
+FYEL="\033[33m" # foreground yellow
+FONG="\033[38;5;214m" # foreground orange
+FBLE="\033[34m" # foreground blue
+FMAG="\033[35m" # foreground magenta
+FCYN="\033[36m" # foreground cyan
+FWHT="\033[37m" # foreground white
+BBLK="\033[40m" # background black
+BRED="\033[41m" # background red
+BGRN="\033[42m" # background green
+BYEL="\033[43m" # background yellow
+BBLE="\033[44m" # background blue
+BMAG="\033[45m" # background magenta
+BCYN="\033[46m" # background cyan
+BWHT="\033[47m" # background white
+##########################
+
+
+###################################################################################
+#  ██████  ██████  ██      ██      ███████  ██████ ████████ ██  ██████  ███    ██ #
+# ██      ██    ██ ██      ██      ██      ██         ██    ██ ██    ██ ████   ██ #
+# ██      ██    ██ ██      ██      █████   ██         ██    ██ ██    ██ ██ ██  ██ #
+# ██      ██    ██ ██      ██      ██      ██         ██    ██ ██    ██ ██  ██ ██ #
+#  ██████  ██████  ███████ ███████ ███████  ██████    ██    ██  ██████  ██   ████ #
+###################################################################################
+
+function calc_reboot_required {
+	if [ -f /var/run/reboot-required ]; then
+		echo "${HC}${FRED}*** System restart required ***${RS}";
+	fi
+}
+
+# Apt package pending upgrade count
+/usr/lib/update-notifier/apt-check --human-readable | head -n1 >${tmpdir}apt-packages.txt &
+# Distribution name
+lsb_release -ds | awk '{ gsub("GNU/Linux |[()]", ""); print($0); }' >${tmpdir}distro-description.txt &
+
+# Hostname
+hostname >${tmpdir}hostname.txt &
+# Kernel version
+uname -r >${tmpdir}kernel-version.txt &
+# Uptime
+uptime --pretty | sed -e 's/up //' >${tmpdir}uptime.txt &
+# Current ips
+ip addr show scope global | awk -f ./parse_interface_ips.awk >${tmpdir}ips.txt &
+# Load
+cat /proc/loadavg | cut -d' ' -f 2 >${tmpdir}load.txt &
+
+# Last login
+last -1 | awk '{ print $1,"on",$5,$6,$7,"\n\tfrom",$3; exit; }' >${tmpdir}last_login.txt &
+# Whether a reboot is required
+calc_reboot_required >${tmpdir}reboot_required.txt &
+
+wait
+
+echo -e "Welcome to $(cat ${tmpdir}hostname.txt)";
+echo -e "    ${LC}running $(cat ${tmpdir}distro-description.txt)${RS}";
+echo -e "Kernel: ${FRED}$(cat ${tmpdir}kernel-version.txt)${RS}";
+echo -e "Uptime: ${FGRN}$(cat ${tmpdir}uptime.txt)${RS}";
+echo -e "Load:   ${FONG}$(cat ${tmpdir}load.txt)${RS}";
+echo -e "IPs:    ${FBLE}$(cat ${tmpdir}ips.txt)${RS}";
+cat ${tmpdir}apt-packages.txt;
+cat ${tmpdir}reboot_required.txt;
+
+### Cleanup ###
+
+rm -r ${tmpdir};
diff --git a/cloudcatcher.sh b/cloudcatcher.sh
new file mode 100755
index 0000000..63f2aa8
--- /dev/null
+++ b/cloudcatcher.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+### Settings ###
+logo_filename="logo.txt";
+info_filename=$(mktemp --suffix -cloudcatcher);
+
+if [ -f .cloudcatcher_settings ]; then
+	source .cloudcatcher_settings;
+fi
+
+################
+
+cloudcatcher-info.sh >${info_filename}
+
+### Output ###
+echo 
+pr -mtJ ${logo_filename} ${info_filename};
+
+##############
+
+### Cleanup ###
+rm "${info_filename}"
+
+###############
diff --git a/parse_interface_ips.awk b/parse_interface_ips.awk
new file mode 100644
index 0000000..d32074e
--- /dev/null
+++ b/parse_interface_ips.awk
@@ -0,0 +1,16 @@
+BEGIN {
+	ORS = ""; # We control the output separator in END
+	ip_count = 0;
+}
+
+/inet6?/ {
+	gsub("/[0-9]+$", "", $2); # Remove the subnet from the end
+	ips[ip_count++] = $2;
+}
+
+END {
+	for(i = 0 ; i < ip_count ; i++) {
+		print(ips[i]);
+		if(i < ip_count - 1) print(", ");
+	}
+}
