You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
#!/usr/bin/env sh |
|
|
|
# Detects what OS you are running and outputs a short string to identify that OS. |
|
# Also saves the result in the $DISTRO environment variable. |
|
# -v for more verbose output |
|
|
|
source colors |
|
source say |
|
|
|
# Read arguments |
|
while getopts v flag |
|
do |
|
case "${flag}" in |
|
v) VERBOSE=true |
|
;; |
|
esac |
|
done |
|
|
|
# Output welcome message |
|
if [ $VERBOSE ]; then say "Detecting which Linux distribution or other operating system you are using..."; fi |
|
|
|
# Check for each known operating system one-by-one |
|
if [ -f "/etc/debian_version" ]; then |
|
DISTRO="debian" |
|
if [ $VERBOSE ]; then say "${GREEN}Debian${RESET}, Ubuntu, or Raspbian OS detected."; fi |
|
elif [ -f "/etc/arch-release" ]; then |
|
DISTRO="arch" |
|
if [ $VERBOSE ]; then say "${GREEN}Arch or Manjaro-based${RESET} OS detected."; fi |
|
elif [ -f "/etc/fedora-release" ]; then |
|
DISTRO="fedora" |
|
if [ $VERBOSE ]; then say "${GREEN}Fedora${RESET} detected as the Operating System"; fi |
|
elif [ $(uname | grep -c "Darwin") -eq 1 ]; then |
|
DISTRO="mac" |
|
if [ $VERBOSE ]; then say "${GREEN}MacOS${RESET} detected."; fi |
|
else |
|
# Failed to detect OS, so complain and exit |
|
say unknown |
|
exit 1 |
|
fi |
|
|
|
# Output the short string for the detected OS |
|
if [ ! $VERBOSE ]; then |
|
say $DISTRO; |
|
fi |