dotfiles

*nix config files
git clone git://git.pyratebeard.net/dotfiles.git
Log | Files | Refs | README

ahoy (7407B)


      1 #!/usr/bin/env bash
      2 #            ██
      3 #           ░██                ██   ██
      4 #   ██████  ░██       ██████  ░░██ ██
      5 #  ░░░░░░██ ░██████  ██░░░░██  ░░███
      6 #   ███████ ░██░░░██░██   ░██   ░██
      7 #  ██░░░░██ ░██  ░██░██   ░██   ██
      8 # ░░████████░██  ░██░░██████   ██
      9 #  ░░░░░░░░ ░░   ░░  ░░░░░░   ░░
     10 #
     11 #  author ▓▒ pyratebeard
     12 #    code ▓▒ https://git.pyratebeard.net/
     13 #
     14 # TODO
     15 # * add rkhunter check
     16 # * add clamav check
     17 # * server details
     18 
     19 basename="${0##*/}"
     20 
     21 # colours
     22 black="\e[30m"
     23 red="\e[31m"
     24 green="\e[32m"
     25 yellow="\e[33m"
     26 blue="\e[34m"
     27 magenta="\e[35m"
     28 cyan="\e[36m"
     29 white="\e[37m"
     30 light_black="\e[1;30m"
     31 light_red="\e[1;31m"
     32 light_green="\e[1;32m"
     33 light_yellow="\e[1;33m"
     34 light_blue="\e[1;34m"
     35 light_magenta="\e[1;35m"
     36 light_cyan="\e[1;36m"
     37 light_white="\e[1;37m"
     38 lighter_black="\e[38;5;241m"
     39 reset="\e[0m"
     40 
     41 display_tasks=0
     42 
     43 usage() {
     44 	echo "Usage: ${basename} [-b] [-h] [-m] [-t] [-r] [-s <hostname>] [-w]
     45 
     46 	-b: backups
     47 	-h: help (this page)
     48 	-m: mail
     49 	-t: tasking
     50 	-r: rss
     51 	-s: show <hostname> details, use 'all' to show all
     52 	-w: weather
     53 "
     54 }
     55 
     56 heading() {
     57 	header="$(echo ${1} | sed -e 's/\(.\)/\1 /g')"
     58 	echo -e "${lighter_black}├┄ ${light_white}${header}${reset}"
     59 }
     60 
     61 tasking() {
     62 	heading ${FUNCNAME[0]}
     63 	total_tasks=$(cat $HOME/.todo | wc -l)
     64 
     65 	echo -e "${lighter_black}│${reset}you have ${light_green}${total_tasks}${reset} task(s)"
     66 }
     67 
     68 # check nightly backups
     69 backups() {
     70 	heading ${FUNCNAME[0]}
     71 	local backup_success=0
     72 	local failed=""
     73 	_repos=$(find /var/dedup/* -maxdepth 1 -type d -prune -printf '%f\n')
     74 	for r in ${_repos} ; do
     75 		_latest=$(find /var/dedup/${r}/archive -type f \
     76 					-exec stat -c '%X %n' {} \; | \
     77 					sort -nr | \
     78 					awk -F\/ 'NR==1 {print $NF}')
     79 		if [[ "${_latest}" -lt $(date +%Y%m%d) ]] ; then
     80 			backup_success=$(( backup_success + 1 ))
     81 			failed+="${r} "
     82 		fi
     83 	done
     84 	[[ ${backup_success} -gt 0 ]] \
     85 		&& echo -e "${lighter_black}│${reset}frak! ${failed}${red}failed${reset}" \
     86 		|| echo -e "${lighter_black}│${reset}schway! backup ${light_green}successful${reset}"
     87 }
     88 
     89 # weather in current location
     90 weather() {
     91 	heading ${FUNCNAME[0]}
     92 	if [ -f /tmp/weather ] ; then
     93 		wttr=$(cat /tmp/weather | awk -F\: '{print $2}' | cut -c 2-)
     94 		echo -e "${lighter_black}│${reset}${wttr}"
     95 	else
     96 		$HOME/bin/weather
     97 	fi
     98 }
     99 
    100 # you've got mail
    101 mail() {
    102 	heading ${FUNCNAME[0]}
    103 	local -r mail_dir="$HOME/var/mbox"
    104 
    105 	local -r pyratebeard_mail=$(find "${mail_dir}"/pyratebeard/INBOX/new/ -type f | wc -l)
    106 	local -r unread_mail=$(find "${mail_dir}"/pyratebeard/INBOX/cur/ -type f ! -name "*S" | wc -l)
    107 	echo -e "${lighter_black}│${reset}you have ${light_green}${pyratebeard_mail}${reset} new mail(s)"
    108 	echo -e "${lighter_black}│${reset}you have ${light_green}${unread_mail}${reset} unread mail(s)"
    109 }
    110 
    111 # not currently used but keeping for future reference
    112 getnews() {
    113 	local -r api_key=$(pass websites/newsapi/key)
    114 	curl 'https://newsapi.org/v2/top-headlines' -s -G \
    115 	-d sources="$1" \
    116 	-d pageSize=5 \
    117 	-d apiKey="${api_key}" | jq -r 'def default: "\u001b[0m"; def grey: "\u001b[1;30m"; .articles[] | .title, grey + .url, "" + default' | tr -d '\t'
    118 }
    119 
    120 rss() {
    121 	heading ${FUNCNAME[0]}
    122 	if [ -f ~/.newsboat/cache.db.lock ] ; then
    123 		echo -e "${lighter_black}│${reset}${light_black}waiting for newsboat refresh...${reset}" 
    124 		sleep 10
    125 	fi
    126 	local unread_count
    127 	unread_count=$(sqlite3 ~/.newsboat/cache.db "select count(unread) from rss_item where unread = 1;")
    128 	local queued_pods
    129 	queued_pods=$(wc -l ~/.newsboat/queue | awk '{print $1}')
    130 	echo -e "${lighter_black}│${reset}there are ${light_green}${unread_count}${reset} unread items"
    131 	echo -e "${lighter_black}│${reset}you have ${light_green}${queued_pods}${reset} queued podcasts"
    132 }
    133 
    134 servers() {
    135 	echo -e "${cyan}
    136     ┐─┐┬─┐┬─┐┐ ┬┬─┐┬─┐┐─┐
    137     └─┐├─ │┬┘│┌┘├─ │┬┘└─┐
    138     ──┘┴─┘┆└┘└┘ ┴─┘┆└┘──┘
    139 ${reset}"
    140 	local server="$1"
    141 	if [ "${server}" == "all" ] ; then
    142 		for node in blacksun grimoire pyratetube mordhaus ; do
    143 			heading "${node}"
    144 			uptime=$(ssh -q "${node}" "uptime -p | cut -b4- | sed 's/\(,\|ear\|eek\(s\)\|ay\(s\)\|our\(s\)\|inute\(s\)\)//g'")
    145 			echo -e "uptime is ${uptime}"
    146 			echo
    147 		done
    148 	else
    149 		heading "${server}"
    150 		uptime=$(ssh -q "${server}" "uptime -p | cut -b4- | sed 's/\(,\|ear\|eek(s)\|ay(s)\|our(s)\|inute(s)\)//g'")
    151 
    152 		echo -e "uptime is ${uptime}"
    153 		echo
    154 	fi
    155 }
    156 
    157 main() {
    158 # 	echo -e "${blue}│${magenta} ┳━┓┳ ┳┏━┓┓ ┳
    159 #${blue}│${magenta} ┃━┫┃━┫┃ ┃┗┏┛
    160 #${blue}│${magenta} ┛ ┇┇ ┻┛━┛ ┇
    161 #${blue}└──┄┄────┄┄───┐${yellow}
    162 #  $(whoami) ${blue}│
    163 #┌──┄┄────┄┄───┘${reset}"
    164 #${lighter_black}┊ ${light_blue}██    ▄  █ ████▄ ▀▄    ▄ ▄
    165 #${lighter_black}┊ ${light_blue}█ █  █   █ █   █   █  █ █
    166 #${lighter_black}│ ${light_blue}▓▄▄█ ▓▓▀▀█ ▓   █    ▀█ █
    167 #${lighter_black}┊ ${light_blue}▓  ▒ ▓   ▓ ▀▓▓▒▒    ▓  ▒
    168 #${lighter_black}│ ${light_blue}   ▒    ▒         ▄▀
    169 #${lighter_black}├───${light_blue}▒${lighter_black}────${light_blue}▀${lighter_black}┄┄ ${light_yellow}$(whoami)${light_blue} ▀
    170 #${lighter_black}│ ${light_blue} ▀${reset}"
    171 	echo -e "
    172 ${lighter_black}┊ ${light_blue} ██  █ █ ██  █ █ ${reset}${light_black}   ▄█████▄
    173 ${lighter_black}┊ ${light_blue} █ █ █ █ █ █ █ █ ${reset}${light_black}  ▄███████▄
    174 ${lighter_black}│ ${light_blue} ▓ █ ▓ █ ▓ █ ▓ █ ${reset}${light_black} ░██ ░█ ░██
    175 ${lighter_black}┊ ${light_blue} ▓▓▓ ▓▓▓ ▓ ▓  ▓  ${reset}${light_black} ░░███████
    176 ${lighter_black}│ ${light_blue} ▒ ▒ ▒ ▒ ▒▒▒  ▒  ${reset}${light_black}  ░░█░█░█
    177 ${lighter_black}├────${light_blue}▒${lighter_black}─${light_blue}▒${lighter_black}┄ ${light_yellow}$(whoami) ${reset}${light_black}░ ░ ░
    178 ${lighter_black}│    ${light_blue}▒ ▒${reset}"
    179 #     ┳━┓┳ ┳┏━┓┓ ┳
    180 #     ┃━┫┃━┫┃ ┃┗┏┛
    181 #     ┛ ┇┇ ┻┛━┛ ┇
    182 #      ┳━┓┳ ┳┏━┓o
    183 #      ┃━┫┃━┫┃ ┃┃
    184 #      ┛ ┇┇ ┻┛━┛┇
    185 #	 かいぞく
    186 # ░█▀█░█░█░█▀█░█░█░
    187 # ░█▀█░█▀█░█░█░░█░░
    188 # ░▀░▀░▀░▀░▀▀▀░░▀░░
    189 #
    190 	#echo -e "  greetings, ${white}\033[7m $(whoami) ${reset}\n"
    191 
    192 	tasking
    193 	echo -e "${lighter_black}│${reset}"
    194 	backups
    195 	echo -e "${lighter_black}│${reset}"
    196 	weather
    197 	echo -e "${lighter_black}│${reset}"
    198 	mail
    199 	echo -e "${lighter_black}│${reset}"
    200 	rss
    201 	echo -e "${lighter_black}└──┄┄────┄┄${reset}"
    202 }
    203 
    204 if [ $# -eq 0 ] ; then
    205 	main
    206 else
    207 	while getopts ":bhmtrws:" opt ; do
    208 		case ${opt} in
    209 			b) backups ;;
    210 			h) usage ;;
    211 			m) mail ;;
    212 			t) display_tasks=1 ; tasking ;;
    213 			r) rss ;;
    214 			w) weather ;;
    215 			s) servers "${OPTARG}" ;;
    216 			*) usage ;;
    217 		esac
    218 	done
    219 fi