#!/bin/bash # shellcheck disable=SC1091 ### # Variables for commonly needed info ### # # All variables must start with FERAL_ to avoid issues with potentially existing variables. # # the /dev/ of the user's drive -- might not map to ${HOME} directly FERAL_DRIVE=$(df -h ~ | grep -v grep | grep dev | awk '{print $1}') export FERAL_DRIVE # i.e. ext4 or zfs FERAL_FSTYPE=$(df -T "${FERAL_DRIVE}" | awk '{print $2}' | grep -v Type) export FERAL_FSTYPE # Avoiding magic URLS FERAL_ALIASES_URL="https://git.io/vsuVp" export FERAL_ALIASES_URL FERAL_HOST="$(hostname -s)" ### # App lists ### # Array of strings separated by :. The first part is the friendly name of the app, the second is the directory to look for to see if it is installed # This is for stuff staff traditionally supports FERAL_CORE_APPS=( "plex:${HOME}/private/plex" "mysql:${HOME}/private/mysql" "deluge:${HOME}/private/deluge" "rtorrent:${HOME}/private/rtorrent" "transmission:${HOME}/private/transmission" "nginx:${HOME}/.nginx" "openvpn:${HOME}/private/vpn" ) # No staff support -- most of the time FERAL_EXTRA_APPS=( "feral_aliases:${HOME}/.feral_aliases" "autodl-irssi:${HOME}/.autodl" ) ### # /App lists ### ### # /Variables ### ### # Functions ### # # All functions must start with FERAL_ to avoid issues with potentially existing variables. # function feral_iostat(){ if [[ ! "${FERAL_FSTYPE}" == "ext4" ]]; then echo "Sorry, this command only works on ext4 drives." else export FERAL_REPEAT=${1:-6} export FERAL_DELAY=${2:-5} if [[ "${FERAL_REPEAT}" == "u" ]]; then FERAL_REPEAT="" echo "Hit control-c to cancel this when you are done reviewing" else echo "This will monitor for $(($FERAL_REPEAT * $FERAL_DELAY)) seconds" echo "Hit control-c to cancel this early" fi echo "This tool measures how busy your hard drive is, as a percent of how busy it can be." echo "Seeing 100 frequently could be a sign of a problem" # iostat -x ${FERAL_DELAY} "${FERAL_REPEAT}" -d "${FERAL_DRIVE}" | grep -v %util | awk '{print $14}' | tr '\n' ' ' iostat -x ${FERAL_DELAY} "${FERAL_REPEAT}" -d "${FERAL_DRIVE}" | awk '{print $14}' unset FERAL_REPEAT FERAL_DELAY fi } function feral_aliases_update(){ wget -qO ~/.feral_aliases "${FERAL_ALIASES_URL}" if [[ "$?" -eq 0 ]]; then echo "Fetch successful..." . ~/.feral_aliases fi } function feral_aliases_install () { if [[ -e "${HOME}/.bashrc" ]]; then if [[ $(grep "FERAL_ALIASES" -c ~/.bashrc) -eq "0" ]]; then echo "Adding these aliases to ~/.bashrc..." { echo "### Do not modify this block by hand ###" echo "# import FERAL_ALIASES by default for all new shells" echo "if [[ -e "~/.feral_aliases" ]]; then" echo " . ~/.feral_aliases" echo "fi" echo "###/Do not modify this block by hand ###" } >> ~/.bashrc fi if [[ $(grep "FERAL_ALIASES" -c ~/.bashrc) -gt "0" ]]; then echo "Feral aliases added this to ~/.bashrc!" fi else echo "Your ~/.bashrc appears to be missing... unable to install" fi } function feral_usage(){ echo "The feral_aliases package adds the following commands (possibly more than is listed here:" echo " feral_iostat: This helps check the disk IO on your slot" echo " Accepts two arguments. The first is the number of times to check (or u for unlimited)," echo " the second is the delays between checks" echo " feral_aliases_update: This updates all the feral_aliases" echo " feral_aliases_install: This installs these commands for all future SSH sessions" echo " feral_aliases_remove: This removes these commands from the running shell (does not modify ~/.bashrc)" echo " feral_list_installed: This lists installed feral software -- accepts 'extra' argument" echo " feral_paste: This accepts in put on standard in, and uploads it to a pastebin for sharing" echo " feral_server_info: This outputs basic info about the server you are on. Accepts 'all' as an argument" echo " feral_deluge_info: This outputs basic info about the deluge configuration, for use accessing it remotely (thin client)" } function feral_aliases_remove(){ for FUNCTION in $(declare -F | grep 'feral_' | sed 's|declare -f ||g'); do unset -f "${FUNCTION}" done echo "All feral aliases removed from running shell" } function feral_list_installed(){ if [[ "${1}" == "extras" ]]; then FERAL_APPS=( "${FERAL_EXTRA_APPS[@]}" ) printf "%s\n" "These applications are community supported:" elif [[ "${1}" == "all" ]]; then printf "%s\n" "These applications are a mix of community and official support:" FERAL_APPS=( "${FERAL_EXTRA_APPS[@]} ${FERAL_CORE_APPS[@]}" ) else FERAL_APPS=( "${FERAL_CORE_APPS[@]}" ) printf "%s\n" "These applications are community and officially supported:" fi for FERAL_APP in "${FERAL_APPS[@]}"; do FERAL_APP_NAME="$(echo ${FERAL_APP} | cut -d: -f1)" FERAL_APP_LOCATION="$(echo ${FERAL_APP} | cut -d: -f2)" if [[ -e "${FERAL_APP_LOCATION}" ]]; then printf '%15s %14s \n' "${FERAL_APP_NAME}:" "Installed" if [[ "${FERAL_APP_NAME}" == "nginx" ]]; then # Nginx/Apache are mutually exclusive printf '%15s %14s \n' "Apache:" "Not Installed" fi else printf '%15s %14s \n' "${FERAL_APP_NAME}:" "Not Installed" if [[ "${FERAL_APP_NAME}" == "nginx" ]]; then # Nginx/Apache are mutually exclusive printf '%15s %14s \n' "Apache" "Installed" fi fi done FERAL_CLIENT='rtorrent' if [[ -e "${HOME}/private/${FERAL_CLIENT}/.version" ]]; then FERAL_CLIENT_VERSION="$(cat "${HOME}/private/${FERAL_CLIENT}/.version" 2>&1 | tr -cd '[:alnum:]_.-')" else FERAL_CLIENT_VERSION="current" fi if [[ ! -d "/opt/${FERAL_CLIENT}/${FERAL_CLIENT_VERSION}" ]]; then # Not a valid version FERAL_CLIENT_VERSION="current" fi printf '%15s %14s \n' "${FERAL_CLIENT} is versioni:" "${FERAL_CLIENT_VERSION}" unset FERAL_APP_NAME FERAL_APP_LOCATION FERAL_CLIENT_VERSION FERAL_CLIENT } function feral_server_info(){ FERAL_ARGS="${1}" FERAL_LOAD_1="$(cat /proc/loadavg | awk '{print $1}')" FERAL_LOAD_5="$(cat /proc/loadavg | awk '{print $2}')" FERAL_LOAD_15="$(cat /proc/loadavg | awk '{print $3}')" FERAL_NOPROCS="$(nproc)" printf '%25s %14s \n' "Hostname:" "$(hostname -s)" printf '%25s %14s \n' "Uptime:" "$(uptime -p)" printf '%25s %14s \n' "Home:" "$(echo ${HOME})" printf '%25s %14s \n' "Memory:" "$(free -th | grep Total | awk '{print $2}')" printf '%25s %14s \n' "Total CPU cores:" "${FERAL_NOPROCS}" if [[ "${FERAL_ARGS}" == "all" ]]; then FERAL_NOSOCKETS="$(cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l)" FERAL_NOCORES="$(cat /proc/cpuinfo | grep "cpu cores" | sort -u | cut -d\: -f 2-)" if [[ -z "$(echo ${FERAL_NOSOCKETS}*2 | bc | grep ${FERAL_NOPROCS})" ]]; then FERAL_HT="Enabled" else FERAL_HT="Disabled" fi printf '%25s %14s \n' "Number of sockets:" "${FERAL_NOSOCKETS}" printf '%25s %14s \n' "Number of cores per CPU:" "${FERAL_NOCORES}" printf '%25s %14s \n' "Hyperthreading:" "${FERAL_HT}" printf '%25s %14s \n' "CPU Model:" "$(cat /proc/cpuinfo | grep "model name" | sort -u | cut -d\: -f 2-)" printf '%25s %14s \n' "PATH:" "$(echo ${PATH})" unset FERAL_NOSOCKETS FERAL_NOCORES FERAL_HT fi echo printf '%25s \n' "Disk usages (non-radons share user drives" printf '%25s %14s \n' "Amount free (OS drive):" "$(df -h --si / | awk '{print $4}' | grep -v 'Avail')" printf '%25s %14s \n' "Amount free (your drive):" "$(df -h --si ~/ | awk '{print $4}' | grep -v 'Avail')" if [[ "${FERAL_ARGS}" == "all" ]]; then echo printf '%25s \n' "Load averages:" printf '%25s %14s \n' "Load 1 minute average:" "${FERAL_LOAD_1}" printf '%25s %14s \n' "Load 5 minute average:" "${FERAL_LOAD_5}" printf '%25s %14s \n' "Load 15 minute average:" "${FERAL_LOAD_15}" echo echo "Load on Linux may be misleading, it is a number that" echo "represents how many CPUs are needed to meet demand." echo "A load of ${FERAL_NOPROC} could mean 100% of all cpus are used" echo "however, load takes into account IO wait -- on servers" echo "with many disk drives (like Feral's), this number is inflated." echo "On Feral, load is more related to disk IO than actual calculations" fi echo echo echo "The following is issue specific debugging that may no longer be relevant" FERAL_CLIENT='rtorrent' if [[ -e "${HOME}/private/${FERAL_CLIENT}/.version" ]]; then FERAL_CLIENT_VERSION="$(cat "${HOME}/private/${FERAL_CLIENT}/.version" 2>&1 | tr -cd '[:alnum:]_.-')" else FERAL_CLIENT_VERSION="current" fi if [[ ! -d "/opt/${FERAL_CLIENT}/${FERAL_CLIENT_VERSION}" ]]; then # Not a valid version FERAL_CLIENT_VERSION="current" fi if [[ -x "/opt/${FERAL_CLIENT}/${FERAL_CLIENT_VERSION}/bin/${FERAL_CLIENT}" ]]; then printf '%25s \n' "${FERAL_CLIENT} is enabled" else printf '%25s \n' "${FERAL_CLIENT} is *NOT* enabled" fi unset FERAL_LOAD_1 FERAL_LOAD_5 FERAL_LOAD_15 FERAL_ARGS FERAL_NOPROCS FERAL_CLIENT_VERSION FERAL_CLIENT } function feral_deluge_info(){ printf "Hostname: $(hostname -f) Username: $(whoami) Port: $(sed -rn 's/(.*)"daemon_port": (.*),/\2/p' ~/.config/deluge/core.conf) Password: $(sed -rn "s/$(whoami):(.*):(.*)/\1/p" ~/.config/deluge/auth)\n" } function feral_env(){ echo "PATH is |${PATH}|" } ### # Aliases ### # # All aliases must start with FERAL_ to avoid issues with potentially existing variables. # alias feral_paste="curl -F 'sprunge=<-' http://sprunge.us" ### # Exit ### if [[ $- == *i* ]] then echo "Successfully loaded all feral_alias commands" fi