Skip to content

Instantly share code, notes, and snippets.

@bretsko
Created October 31, 2016 23:33
Show Gist options
  • Save bretsko/7121d3641891973b0d70f76f63f06858 to your computer and use it in GitHub Desktop.
Save bretsko/7121d3641891973b0d70f76f63f06858 to your computer and use it in GitHub Desktop.
#!/bin/bash
declare -a releases=("debian" "ubuntu" "centos")
shopt -s nullglob
shopt -s nocasematch
# Case 1
#dmesg | grep debian, ubuntu etc.
#uname -a | grep
#lsb_release -a | grep
for i in "${releases[@]}"
do
dmesg | grep "$i"
#if previous command succeeded
if [ $? -eq 0 ]; then
echo "$i" "- found in dmesg"
fi
uname -a | grep "$i"
if [ $? -eq 0 ]; then
echo "$i" "- found in uname -a"
fi
cat /etc/issue | grep "$i" # same as lsb_release -a
if [ $? -eq 0 ]; then
echo "$i" "- found in /etc/issue"
fi
done
# Case 2
arr=(/etc/*release)
for i in "${arr[@]}"
do
release=$(grep ID_LIKE $i | cut -d'=' -f2)
if [ -n "$release" ]; then
echo "Found ID_LIKE in" "$i"
case "$release" in
"debian" | "ubuntu")
echo "apt-get"; #check if vm-tools installed
;;
"centos")
echo "yum";
;;
*)
echo $release
;;
esac
fi #if [ $? -eq 0 ]
done #for i in "${arr[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment