#!/bin/sh
# alpha-security - simple checks and guidance for YOUR OWN computer.
# Read-only: it changes nothing. Guidance is general, plain words.
echo "SECURITY - YOUR OWN COMPUTER"
echo
# Listening doors on THIS machine, if the tool exists.
if command -v ss >/dev/null 2>&1; then
  N=$(ss -tln 2>/dev/null | grep -c LISTEN)
  echo "Open doors here: $N listening service(s) on this machine."
  echo "That is normal for a working machine - what matters is that"
  echo "you recognise them. List them any time with:  ss -tln"
elif command -v netstat >/dev/null 2>&1; then
  echo "Open doors here: run  netstat -tln  to see this machine's"
  echo "listening services, and make sure you recognise each one."
else
  echo "Open doors here: this shell has no ss/netstat tool, so the"
  echo "listening services could not be listed. Nothing was hidden -"
  echo "the tool simply is not here."
fi
echo
# Disk pressure is a safety issue too (full disks break updates).
if command -v df >/dev/null 2>&1; then
  PCT=$(df -P "$HOME" 2>/dev/null | awk 'NR==2{gsub(/%/,"",$5); print $5}')
  if [ -n "$PCT" ] && [ "$PCT" -ge 90 ] 2>/dev/null; then
    echo "Disk warning: your home filesystem is $PCT% full. A full"
    echo "disk can silently block security updates - free space soon."
    echo
  fi
fi
echo "The basics that actually protect a machine:"
echo "  1. Keep the system and apps updated - most break-ins walk"
echo "     through doors that a free update already closed."
echo "  2. Use a password or key you do not reuse anywhere else."
echo "  3. Back up the files you would cry over, somewhere separate."
echo "  4. Be suspicious of surprise attachments and sign-in pages,"
echo "     even when they look familiar."
echo
if command -v apk >/dev/null 2>&1; then
  echo "On this system, see available updates with:  apk version -l '<'"
elif command -v apt >/dev/null 2>&1; then
  echo "On this system, see available updates with:  apt list --upgradable"
elif command -v dnf >/dev/null 2>&1; then
  echo "On this system, see available updates with:  dnf check-update"
elif command -v pacman >/dev/null 2>&1; then
  echo "On this system, see available updates with:  pacman -Qu"
fi
echo
echo "VERDICT: this check changed nothing and sent nothing anywhere."
