Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
@Rinzwind: DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.10 DISTRIB_CODENAME=quantal DISTRIB_DESCRIPTION="Ubuntu 12.10". Nothing that I can use to tell if it's either Server or Desktop. –  Alix Axel Apr 14 '13 at 18:06
    
Fundamentally speaking, there's little difference between Ubuntu Server and Ubuntu. The difference is primarily the fact that Desktop version comes with a GUI, but you can install a GUI onto the CLI ubuntu server. Also, you can install server packages onto the GUI version of Ubuntu Desktop. I'm not sure there is a sure-fire, clean-cut way to determine Desktop vs. Server installation media. –  Thomas W. Apr 14 '13 at 18:10
    
@Rinzwind: This is a server install. I also have 3 other VPS in 2 different providers with server editions and none of them shows the "server" string. I guess reading lsb_release just isn't reliable enough. –  Alix Axel Apr 14 '13 at 18:10
    
@TheLordofTime: Yes, I know they are pretty much the same. But I thought that maybe there was at least a crucial package that would differentiate between the two. –  Alix Axel Apr 14 '13 at 18:12
    
As a follow up note, the issue was the package regular expression, changing it to ( apt-get -qq -y remove --purge "^$halBox_package*" ) worked on both Server and Desktop flavors. –  Alix Axel May 18 '13 at 15:30

1 Answer 1

up vote 9 down vote accepted

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.
share|improve this answer
    
BTW, $? will be 1 if dpkg -l fails to list anything, 0 otherwise. Regarding grep desktop it will always match, either the package or the message saying it hasn't been found. –  Alix Axel Apr 14 '13 at 18:20
1  
Ok this is my last edit I hope! Can you clean up comments too? >:D –  Rinzwind Apr 14 '13 at 18:22
    
I'm just reading the dpkg man page, but apparently this seems to work. If someone installs desktop without ubuntu-desktop, they should be savvy enought to fix the problems my script will cause, so it's all good! :P –  Alix Axel Apr 14 '13 at 18:24
    
( dpkg -s "ubuntu-desktop" && Ubuntu_Flavor="desktop" ) > /dev/null 2>&1 works great, thanks! –  Alix Axel Apr 14 '13 at 19:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.