Posts Tagged: Linux


13
May 10

Telling Students Linux != Windows with pyinotify and pynotify

While doing pro bono Ubuntu system administration for a local private school, something that has always annoyed me is that students frequently download installer files for Windows programs (games, iTunes etc). The computers obviously don’t look like they run Windows, and they’ve been told on many occasions that Linux != Windows. So today, I decided to automate this explanation:

#!/usr/bin/python
 
import pyinotify, pynotify
from subprocess import Popen
from os.path import expanduser
 
pynotify.init('Windows program notifier') # Not sure what this does
 
PATH = expanduser('~')
NAUGHTY_EXTENSIONS = ['exe','bat', 'com', 'dll', 'msi', 'ocx', 'reg', 'scr']
MESSAGE = "You just tried to download a Windows program. This is Linux. Bugger off!"
 
def notifyAndDelete(path, showNotification):
    """Delete any file with the forbben extensions."""
    if path.split('.')[-1].lower() in NAUGHTY_EXTENSIONS:
        print 'Deleting ' + path
        Popen(['rm', path])
        if showNotification == True:
            n = pynotify.Notification("Windows Program Fail", MESSAGE)
            n.show()
 
class HandleEvents(pyinotify.ProcessEvent):
    def process_IN_CREATE(self, event):
        notifyAndDelete(event.pathname, True)
    def process_IN_MOVED_TO(self, event):
        notifyAndDelete(event.pathname, False)
 
if __name__ == '__main__':
    wm = pyinotify.WatchManager()  # Watch Manager
    mask = pyinotify.IN_CREATE | pyinotify.IN_MOVED_TO  # watched events
 
    p = HandleEvents()
    notifier = pyinotify.Notifier(wm, p)
    wdd = wm.add_watch(PATH, mask, rec=True)
 
    notifier.loop()

When a user tries to download a program with an extension found in NAUGHTY_EXTENSIONS, They will get a Notify OSD popup informing them that they are not using Windows, and Windows programs won’t work on school computers. Of course, when I go to deploy this code, MESSAGE will be a little more appropriately worded.

This program is a combination of code I found from this pyinotify tutorial and a Notify OSD snippet I found in Acire.

Edit June 8 2010

Thanks to the anonymous commenter that pointed out the bug that allowed arbitrary code execution, and to Michael Hall for explaining it in more detail. The problem has been fixed.


24
Apr 10

Changing Plymouth Themes In Ubuntu 10.04

One of the major changes in Ubuntu 10.04 is that Plymouth is now managing the fancy boot graphics, instead of xsplash. While the default Plymouth theme is decent, I wanted something different. Fortunately, changing the Plymouth theme only takes a few lines on the CLI.

If you run apt-cache search plymouth-theme, you’ll see which themes are available in the default repositories. This Youtube search has some videos of what is available. I chose the plymouth-theme-solar package, which has a nice solar flare animation. Next, run the following code, which I found here. Keep in mind that you need to change it to point to the plymouth theme you want to use.

sudo update-alternatives --install \
/lib/plymouth/themes/default.plymouth default.plymouth \
/lib/plymouth/themes/solar/solar.plymouth 100

(note: Line warping was only used to make it look pretty on a blog post.)

Next run sudo update-alternatives –config default.plymouth. You’ll see a numbered menu of the themes currently installed. Type the number for the one you want and hit enter. Finally, use sudo update-initramfs -u to apply your changes.

Here is the result:

There are not many themes available currently. However, once 10.04 is released and has been out for a little while, I think there will be many more options.


12
Jul 09

Android Screenshots

I just got done taking some screenshots of my snazzy Android phone. I ran into a bit of difficulty getting the DDMS (Dalvik Debug Monitor Service) tool running in Ubuntu 9.04 64 bit, but post #2 on this thread helped. To summarize:

  1. Use the package manager of your choice to install ia32-sun-java6-bin.
  2. Download the Android SDK for Linux, then extract the zip file.
  3. In the SDK tools folder, open up the ddms file in your favorite text editor.
  4. Modify line #72 to the following: java_cmd=”/usr/lib/jvm/ia32-java-6-sun/bin/java”

Here are the screenshots I took:

As you can see, I’m running a clone of the theme on HTC’s Hero Android phone. This theme can be downloaded here. All the install took was downloading the theme, putting it on my phone’s SD card as update.zip, booting into recovery mode and flashing the update. Of course, you’ll need a rooted G1 for this to work. I’m running JesusFreke’s wonderful 1.5 build. Read this guide for instructions for rooting your G1.


10
May 09

Does High Price Attract Mac Users?

I was on the #ubuntu-us-fl IRC channel recently, when one of my fellow geeks put forward an interesting theory: People are attracted to Apple products by a high price. The theory assumes that in our society people usually equate price with quality, and not always accurately. Today I decided to do a little price comparison. I gladly admit that I have a bias towards the Linux operating system, specifically the Ubuntu distribution. However, in this post I will try to let hopefully unbiased numbers speak for themselves, with the exception of my summary at the end.

Below I have the configurations and prices for four machines: an Apple Mac Pro, a Dell XPS 630, The Wild Dog performance desktop from System76, and finally a custom built machine with parts from Newegg (thanks to excid3 for the build specs). Though the machines are from four different OEMs (aka companies that build computers), I configured each to be as close as possible in specifications and performance.

Apple Mac Pro, $2,849.00

  • Processor: One 2.66GHz Quad-Core Intel Xeon
  • RAM: 8GB (4x2GB)
  • Hard drive: 1TB 7200-rpm Serial ATA 3Gb
  • Graphics card: NVIDIA GeForce GT 120 512MB
  • DVD burner: One 18x SuperDrive

Dell XPS 630, $1,679

  • Processor: Intel® Core™2 Q9550 (12MB,2.83GHz, 1333FSB) (Also a quad core)
  • RAM: 8GB Dual Channel DDR2 SDRAM at 800MHz (4 DIMM)
  • Hard drive: 1TB Performance RAID 0 (2 x 500GB SATA 3Gb/s 7200 RPM HDDs)
  • Graphics card: SLi, Dual nVidia GeForce 9800GT 512MB
  • DVD burner: 16X CD/DVD burner (DVD+/-RW) w/double layer write capability

System76 Wild Dog Performance Desktop, $1,089.00

  • Processor: Quad Core Q6600 2.40 GHz FSB 1066 MHz L2 8 MB
  • RAM: 8 GB – 4 x 2 GB – DDR3 – 1333 MHz
  • Hard Drive:  1 TB SATA II 300Mbps – 7200 rpm 32 MB Buffer
  • Graphics card: 512 MB ATI Radeon 4550 PCI-Express x16 GDDR3 (DVI, VGA, S-Video, DVI to HDMI, DVI to VGA)
  • DVD burner: CD-RW / DVD-RW

Custom built machine, $608.90

Note: If you wanted Windows Vista on this machine (not recommended), just add $179.99 to the price. Also, the links to all the parts are listed below, seeing as there is a lot more customization that goes into a custom build.

Biased Summary

I’ll start off with the most obvious and least controversial conclusion: you’d be crazy not to get a custom built machine. Due to the geeky tendencies of this blog, most people reading this are likely to be fellow geeks. Any geek worth their weight in old CRT monitors can put that machine together. If however you are not a geek, surely you know someone who is. For $200 and a few hours to play with all the shiny parts, any geek would be glad to put this machine together for you, and you’d still be saving a huge amount of money.

Now for the slightly more controversial conclusions. I believe that a higher price does play a role in a person’s decision to buy a Mac. It is certainly not the only factor, since as far as OEM equipment goes, Apple is fairly nice. I agree that Apple has some very high quality hardware. However, the hardware in each of these machines is very similar, and all high quality, and yet the Apple machine is $1,170 more expensive than the second most expensive and yet very similar machine. You could even get any one of these machines and put OSX on it yourself if Apple would let you (or you felt like using The Pirate Bay).

Given the fact that all four machines are very similar, lets assume for a moment that the custom built machine represents the price each manufacturer pays to build their computer (not quite accurate, as the OEM’s save money by buying parts in bulk). This would mean that what you are really buying from an OEM is the convenience of having someone else put a computer together for you. That convenience costs you $2,240 if Apple builds it and $1,070 if Dell builds it. The lowest OEM service price is from System76, at $480, which is just over twice my recommended build price from the friendly neighborhood geek.

My numbers are certianly not perfect, especially since it is impossible to get an exactly identical machine from two OEMs. However, even after doing tweaking for any innacuracies in my calculations or configurations, I think your findings will be the same: all OEMs are expensive, but Apple is by far the most expensive.


25
Mar 09

Boot Performance In Ubuntu 9.04

Inspired by a meme making it’s rounds on Planet Ubuntu and elsewhere on the interwebs, I decided to profile my boot. For several weeks now I have been running the development version of Ubuntu 9.04, and reporting the occasional bug. So far everything has been very stable.

I have 9.04 installed on my Inspiron 1420, using the ext4 filesystem (also quite stable in my experience), with noatime set in /etc/fstab. My CPU is an Intel Core 2 Duo clocked at 1.5 GHz, 4GB of ram and a very average 80GB SATA hard drive.

Profiling a boot with bootchart was as simple as “sudo apt-get install bootchart”. With that done, I just rebooted my machine. Once I was back up, there was a .png file in /var/log/bootchart containing the details of my boot process.

Boot time == 20.27 seconds!

And now for the gory details…

bootchart


AWSOM Powered