How can I programmatically determine if a system is a desktop or a server?

Is there any way to distinguish between Ubuntu Server and Ubuntu Desktop?

I have a Bash script (shameless plug) that I use to set up lightweight web servers, and I've noticed that when I run this script on my own computer, my Ubuntu (Desktop) install gets all messed up - I'm pretty sure the culprit are the following lines of code:

echo -e "\e[1;32mDave, I'm removing the bloatware.\e[0m"

for halBox_package in apache2 bind9 nscd php portmap rsyslog samba sendmail; do
    if [[ -f /etc/init.d/$halBox_package ]]; then
        ( service $halBox_package stop ) > /dev/null
    fi

    ( apt-get -qq -y remove --purge "$halBox_package*" ) > /dev/null 2>&1
done

What I would like to do, is to detect whether the script is being ran in a Server flavour or not, so I can decide whether to purge those packages or not. If it's not possible to tell the flavors apart, can you tell me which package is necessary for Ubuntu Desktop to work properly?


Solution 1:

Command

dpkg -l ubuntu-desktop 

Result:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
ii  ubuntu-desktop 1.287        i386         The Ubuntu desktop system

 - List item

Cave-at

It will not work if someone installs the desktop without using ubuntu-desktop. But who does that?

Documentation

  • Before 12.04, Ubuntu server installs a server-optimized kernel by default. Since 12.04, there is no difference in kernel between Ubuntu Desktop and Ubuntu Server since linux-image-server is merged into linux-image-generic.