Skip to content

Instantly share code, notes, and snippets.

@nullmastermind
Last active December 11, 2024 03:09
Show Gist options
  • Select an option

  • Save nullmastermind/1ae3f59f4528dea8e0926406e25818cc to your computer and use it in GitHub Desktop.

Select an option

Save nullmastermind/1ae3f59f4528dea8e0926406e25818cc to your computer and use it in GitHub Desktop.
#!/bin/bash
# Function to determine architecture
get_architecture() {
local arch=$(uname -m)
case "$arch" in
x86_64|amd64)
echo "64-bit"
;;
i386|i686)
echo "32-bit"
;;
aarch64|arm64)
echo "64-bit (ARM)"
;;
armv7l|armv6l)
echo "32-bit (ARM)"
;;
*)
echo "Unknown architecture: $arch"
;;
esac
}
# Get architecture
ARCH_INFO=$(get_architecture)
# Check OS and version
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu)
echo "Operating System: Ubuntu"
echo "Version: $VERSION_ID"
echo "Architecture: $ARCH_INFO"
echo "Full Details: $PRETTY_NAME ($ARCH_INFO)"
;;
amzn)
echo "Operating System: Amazon Linux"
echo "Version: $VERSION_ID"
echo "Architecture: $ARCH_INFO"
echo "Full Details: $PRETTY_NAME ($ARCH_INFO)"
;;
*)
echo "Operating System: Neither Ubuntu nor Amazon Linux"
echo "Detected OS: $ID"
echo "Architecture: $ARCH_INFO"
echo "Full Details: $PRETTY_NAME ($ARCH_INFO)"
;;
esac
else
# Fallback method
if command -v lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
if [ "$OS" = "Ubuntu" ]; then
echo "Operating System: Ubuntu"
echo "Version: $(lsb_release -sr)"
echo "Architecture: $ARCH_INFO"
echo "Full Details: $(lsb_release -sd) ($ARCH_INFO)"
fi
elif grep -q "Amazon Linux" /etc/system-release 2>/dev/null; then
echo "Operating System: Amazon Linux"
echo "Version: $(cat /etc/system-release)"
echo "Architecture: $ARCH_INFO"
echo "Full Details: $(cat /etc/system-release) ($ARCH_INFO)"
else
echo "Could not determine if this is Ubuntu or Amazon Linux"
echo "Architecture: $ARCH_INFO"
fi
fi
# Additional system information
echo -e "\nDetailed System Information:"
echo "Kernel: $(uname -r)"
echo "Machine Hardware: $(uname -m)"
if command -v lscpu >/dev/null 2>&1; then
echo "CPU Architecture: $(lscpu | grep "Architecture" | awk '{print $2}')"
fi
curl -s https://gist.githubusercontent.com/nullmastermind/1ae3f59f4528dea8e0926406e25818cc/raw/cd7fb975ab87ffa7d61dfa48fc169b14d9cb635d/check_os.sh | bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment