Daniel 'MaTachi' Jonsson

Category Archives: Ubuntu

bash bad interpreter with Robocode

The other day I downloaded Robocode, ran the unpacker and tried to execute the shell scripts within the Robocode folder. However, on Ubuntu I got the following error when I did that:

matachi:robocode$ ./robocode.sh
bash: ./robocode.sh: /bin/sh^M: bad interpreter: No such file or directory

To fix this install dos2unix by running:

sudo apt-get install dos2unix

Then run:

dos2unix robocode.sh

And now the script is runnable on Linux.

How To Live Stream Your Ubuntu Desktop

In this post I will show how I managed to set up a live stream of my Ubuntu 12.04 desktop to Justin.tv. Since Justin.tv is tightly connected to Twitch.tv, you can probably with very small modifications make this work with Twitch too.

Step 1.

Create a new file called stream.sh and paste the following text into the file:

#!/bin/bash
INRES="1680x1050" # input resolution
OUTRES="640x360"
OFFSET="1680,0"
FPS="15" # target FPS
QUAL="fast"  # one of the many FFMPEG preset
STREAM_KEY="your_stream_key"
URL="rtmp://live.justin.tv/app/$STREAM_KEY"

avconv -f x11grab -s "$INRES" -r "$FPS" -i :0.0+$OFFSET -ab 192k \
-f alsa -ac 2 -i pulse -vcodec libx264 -crf 30 -preset "$QUAL" -s "1280x720" \
-vol 11200 -acodec libmp3lame -ar 44100 -threads 0 \
-f flv "$URL"

You can get your stream key from this page:

Note that you probably want to change the OFFSET variable to 0,0. I have it because I only wanted to stream my second monitor, which is to the right.

More options to x11grab can be found here, such as draw_mouse and follow_mouse:

The script is based on the one found in this thread:

Step 2.

Update the script’s permissions from the terminal:

chmod u+x stream.sh

Step 3.

The video codec (-vcodec libx264) requires that you have this package installed:

sudo apt-get install libavcodec-extra-53

This did I find out in this Stack Overflow answer:

Step 4.

Start streaming by running:

./stream.sh

Audio

I’m not completely satisfied with the audio quality on the stream. I changed the bitrate argument in the script from 96k to 192k, and I added “-vol 11200″ to increase the audio volume since it was incredibly low. The quality is still not very good, so if you have a solution, please leave a comment.

The package pavucontrol in Ubuntu’s repository is an audio manager that has some more options than the pre-installed. However, I didn’t find anything that I had use of there, but maybe you have.

How to Set Up a Virtual Host on Ubuntu

Add a new site:

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite.local

Then configure the site to fit your needs:

sudo vim /etc/apache2/sites-available/mysite.local

Don’t forget to add this line to the VirtualHost element:

ServerName mysite.local

Enable the site:

sudo a2ensite mysite.local

Reload Apache:

sudo service apache2 reload

Update your hosts file:

sudo vim /etc/hosts

Add the following line to the file:

127.0.0.1 mysite.local

Open a browser and visit mysite.local. Make sure that you don’t precede the URL with www..

If the browser doesn’t show what you are expecting, start with checking Apache’s error log:

cat /var/log/apache2/error.log | tail

How to Install Pygame to Python 3 on Ubuntu

Installation

Start by installing all necessary dependencies, and mercurial and checkinstall for the installation:

sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev checkinstall mercurial

Then download the latest version of the Pygame source code with the following command (this uses mercurial):

hg clone https://bitbucket.org/pygame/pygame

Go into the downloaded Pygame directory:

cd pygame

Compile the source code by typing this command into the terminal:

python3 setup.py build

Finally install Pygame by doing this:

sudo checkinstall python3 setup.py install

Extra stuff

Click here to read why you should use checkinstall.

Use this command to see information about your pygame installation:

apt-get cache show pygame

And this command to uninstall Pygame:

dpkg -r pygame

or:

sudo apt-get remove pygame

Notes

The most recent stable pygame version when writing this is 1.9.1 (which is from August 2009). I did this installation on Ubuntu 12.04 and this was needed since there isn’t a python3-pygame available in the repository.

How to Fix Ugly Japanese Fonts in Firefox

The other day I took and reinstalled Ubuntu on my computer. So now I’m running 12.04, and I have to say that it’s a really nice OS.

Anyway, in Firefox I encountered an ugly Japanese font on some pages. It looked like an old/jagged serif font. However, on some other pages it looked much better and modern.

After looking around I finally managed to fix that ugly font problem by doing these steps:

  1. Open Firefox’s Preferences window.
  2. Select the Content tab.
  3. Click on the “Advanced…” button under “Fonts & Colors”.
  4. A new window appears with the title Fonts.
  5. Select Japanese in the “Fonts for:” drop-down list.
  6. Select “sans-serif” in the “Serif:” drop-down list.
  7. Finally close the window by clicking the OK button and you are done.

How to Fix Power/Battery Problem with Linux Kernel 3.x on Ubuntu 11.10

I have installed Ubuntu 11.10 on my laptop but I noticed that it drained a lot more of the battery than it should do. Apparently there are a couple of fixes to this:

To add pcie_aspm=force, i915.i915_enable_rc6=1, i915.i915_enable_fbc=1 and i915.lvds_downclock=1 to GRUB, do the following steps:

  1. Open the terminal and run: sudo gedit /etc/default/grub
  2. Add:
    pcie_aspm=force i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1
    to
    GRUB_CMDLINE_LINUX_DEFAULT=”",
    so it should look somewhat like:
    GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash pcie_aspm=force i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1″
  3. Close gedit and save the document.
  4. Now run the following line in the terminal to update GRUB:
    sudo grub-mkconfig -o /boot/grub/grub.cfg
  5. After a restart of your computer the new settings should get activated.

Why Aptitude Is Superior To Apt-Get

Yesterday I was messing around in the terminal and googeling for cool and useful commands. I had seen the command aptitude being mentioned a few times before in forum threads and such, but I had never tried to use it myself. However, yesterday I did try use it didn’t take long time until I realised how superior it’s to apt-get.

Instead of ranting about what it does better than the other myself, I will link to an article from 2007 that describes everything very well:

Ubunchu! – The Very Best Manga

Ubunchu!The other day I found a really great manga when I was searching for an anime character on Google. It’s called Ubunchu! and it’s about, as the name suggest, Ubuntu! :)

The story is about the SysAdmin club on a Japanese school, and it starts out with the club’s three only members deciding what operating system to install on their computer. They agree to try out Ubuntu, and the following chapters are about different Ubuntu and Linux stuff. Like one chapters is about the terminal and how you use commands, and another one is about how you use the forums to get help.

Check it out, it’s really great I must say!

Black Screen After Installing FGLRX In Linux Mint

I have finally bought a new graphics card to my computer, a Asus Radeon HD 6870 DirectCU. It was a bit longer than my old card, a PowerColor 4870, so it was tough to fit in the computer chassis. But I made it at last. :) The reason why I purchased a new card, was because my old one was half broken and wasn’t able to run with the default clock speeds without getting artifacts everywhere on my monitors.

When I first started Linux Mint with my new card plugged in, I was welcomed by a black screen, which wasn’t very fun. So I booted up Linux Mint in Recovery Mode and tried to install working graphics driver. The driver I had from earlier was ATI/AMD proprietary FGLRX graphics driver from the Additional Drivers window in Linux Mint (and Ubuntu). This graphics driver didn’t work after a clean install of Linux Mint either.

I also found these two guides: https://help.ubuntu.com/community/BinaryDriverHowto/ATI and http://wiki.cchtml.com/index.php/Ubuntu_Maverick_Installation_Guide, which describes how to install ATI driver. But the terminal command aticonfig never worked for me, so I didn’t manage to complete the installation.

However, if you simply download the proper driver from AMD’s website, and then run it like a normal program, it works just as it should. So I can’t really see the reason why you would build the graphics driver into packages and install them and so on in 20+ steps. Maybe it’s easier to uninstall the driver in the future. But how often do you change video card or update your graphics driver on Linux?

Anyway, it works great now and I’m happy.