#!/bin/bash

if [[ "$(whoami)" != "root" ]]; then
  echo "This script must be run by root or with sudo"
  exit 1
fi

if [ $(uname -a | grep -ci Darwin) != 1 ]; then
  echo "Sorry, this script only works on macOS"
  exit 1
fi

# Assumes root!
sshStatus=$(sudo systemsetup -getremotelogin | awk '{print $3}')
if [ "$sshStatus" == "On" ]; then
  systemsetup -f -setremotelogin off
  printf "%s" "Disabled SSH!"
elif [ "$sshStatus" == "Off" ]; then
  systemsetup -f -setremotelogin on
  printf "%s" "Enabled SSH!"
else
  printf "Error, SSH Status was: $sshStatus"
fi
