From c40577534dfe8000c591c46cc4eb9c26ecf1eef7 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Mon, 16 Jan 2023 01:38:04 -0600 Subject: [PATCH] + gumosh reboot_check zman --- gumosh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ reboot_check | 37 +++++++++++++++++++++++++++++++++++++ zman | 4 ++++ 3 files changed, 92 insertions(+) create mode 100755 gumosh create mode 100755 reboot_check create mode 100755 zman diff --git a/gumosh b/gumosh new file mode 100755 index 0000000..93f34c5 --- /dev/null +++ b/gumosh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# This script parses the ssh config at ~/.ssh/config to find user@host +# entries, then uses gum choose to select one user@host to ssh into. + +# Check for gum. +if ! test -x "$(command -v gum)"; then + echo "Missing dependency: gum" + echo "See github.com/charmbracelet/gum" + exit 1 +fi + +SSH_CONFIG="${HOME}/.ssh/config" +usern_array=() +hostn_array=() +logins=() + +# Read Users from ssh config and store them in usern_array. +while IFS= read -r line; do + if [[ "$line" == *"User"* ]]; then + usern=$(echo $line | awk '{ print $2 }') + usern_array+=($usern) + fi +done < "${SSH_CONFIG}" + +# Read HostNames from ssh config and store them in hostn_array. +while IFS= read -r line; do + if [[ "$line" == *"HostName"* ]]; then + hostn=$(echo $line | awk '{ print $2 }') + hostn_array+=($hostn) + fi +done < "${SSH_CONFIG}" + +# Set the array_len to the size of usern_array - 1. +let "array_len = ${#usern_array[@]} - 1" + +# Iterate through usern_array and hostn_array and match user and host +# pairs, then store them in the logins array in "user@host" format. +for i in $(seq 0 $array_len); do + userhost=$(printf "%s@%s" "${usern_array[i]}" "${hostn_array[i]}") + logins+=($userhost) +done + +# Print each member of logins array on a new line and pipe to gum choose. +# Store selection. +selection=$(printf "%s\n" "${logins[@]}" | gum choose --limit=1) + +# If $selection is non-empty, pass it to the ssh -X command. +if test -n "${selection}"; then + mosh "${selection}" +fi diff --git a/reboot_check b/reboot_check new file mode 100755 index 0000000..b67e0ab --- /dev/null +++ b/reboot_check @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# This script reads user@host lines from ~/.server_hosts. Each host +# is a RHEL-like operating system where the dnf-utils and +# dnf-automatic packages are installed. dnf-automatic is configured +# to download and apply updates periodically. The 'needs-restarting' +# command provided by the dnf-utils packages is assumed to be +# available on each host. Each host is checked via SSH to see if it +# needs-restarting after core libraries and services have been +# updated since the last boot-up. If a restart has been initiated for +# a given host, notify-send will notify the user. + +set -euo pipefail + +HOST_FILE="${HOME}/.server_hosts" +host_array=() +RED='\033[1;31m' +YELLOW='\033[1;33m' +GREEN='\033[1;32m' +NC='\033[0m' + +# Read hosts from ~/.server_hosts +while IFS= read -r line; do + host=$(echo $line) + host_array+=($host) +done < "${HOST_FILE}" + +for host in "${host_array[@]}"; do + hostname=$(echo $host | cut --delimiter="@" --fields=2) + if ssh "$host" -- sudo needs-restarting -r >/dev/null; then + echo -e "$hostname: ${GREEN}OK${NC}" + else + ssh "$host" -- sudo systemctl reboot >/dev/null + echo -e "$hostname: ${RED}Restart initiated${NC}" + notify-send "$hostname: Restart initiated" + fi +done diff --git a/zman b/zman new file mode 100755 index 0000000..be33957 --- /dev/null +++ b/zman @@ -0,0 +1,4 @@ +#!/usr/bin/env zsh + +CMD=$(gum input --placeholder="command") +zellij action new-pane -- man "$CMD"