Something I don't understand although I've been browsing the typical bash scripting web sites. The following script simply tells me which computer it is being run on. There are 4 possibilities, the server, the phenom box, the centos box or the laptop. It works as expected. In the script there are two methods for achieving the desired result. I do believe that there are better ways to accomplish the task in a script but I don't know what these methods are referred to, arrays, loops, brace expansion, what? Seems that my code could be considered a bit redundant and could be shorter.
PHP Code:
#!/bin/bash
# Test if desktop or laptop
# Text strings
phenom="This is the Phenom Box"
server="This is the server"
centos="This is the CentOS Box"
laptop="This is the laptop"
if [[ $EUID -ne 0 ]] ; then # Need root permissions
echo "Please execute this script with root permissions."
exit 1
fi
function get_chassis() # Determine if system is desktop or laptop
{
chassis_type=$(dmidecode -s system-product-name)
if [[ $chassis_type == "N61PC-M2S" ]] ; then
echo $chassis_type $phenom
else
if [[ $chassis_type == "Satellite A205" ]] ; then
echo $chassis_type $laptop
else
if [[ $chassis_type == "P4i65G" ]] ; then
echo $chassis_type $centos
else
if [[ $chassis_type == "P4V8X-MX" ]] ; then
echo $chassis_type $server
fi
fi
fi
fi
}
get_chassis
test_type=$(dmidecode -s system-product-name)
case $test_type in
"N61PC-M2S")
echo $test_type $phenom
;;
"Satellite A205")
echo $test_type $laptop
;;
"P4i65G")
echo $test_type $centos
;;
"P4V8X-MX")
echo $test_type $server
;;
esac
So you can see that I've used if-then-else excessivly and I've also tried a case statement. I think it can be done with less code and in a way that makes more sense. Can anyone offer some help or a rewrite of this code?
Disclaimer:

This is not a homework project. It's been almost 40 years since I've had to do homework
Edit: As an afterthought, I don't really want someone to rewrite the code for me. I just need to be pointed in the right diretion. "Glenn, you need to use <what?>"
[[ "N61PC-M2S", "Satellite A205", "P4i65G", "P4V8X-MX" ]]