↓ Twitter is updated more often, so read it! ↓

Archive for the ‘howto’ Category.

HOWTO Write a script to update Twitter from Linux

I just signed up for Twitter as colindean. I don’t know what use I’ll have for it, as I’m not one who is much for microblogging or partying.

Anyway, the API caught my eye, and after having read Wayne’s post at Fsckin w/ Linux regarding Twitter clients for Linux, I decided to roll my own rather than use what’s out there. I wanted something simple and bashful.


#!/bin/bash
EMAIL=youremail@yourdomain.com
PASSWORD=yourpassword

WHAT="What are you doing? "
SORRY="Sorry, that was too long."
UPDATED="Tweet submitted:"

function getinput {
  if [ ${TERM} = "xterm" ]; then echo -n "${WHAT}"; read TWEET
    else TWEET=$(zenity --entry --text="${WHAT}" --entry-text="${1}")
  fi
}

function check_length {
  TWEETLENGTH=$(echo -n "${TWEET}" | wc -m)
  if [ ${TWEETLENGTH} -gt 140 ]; then
    warn_user
    getinput ${TWEET}
    check_length
  fi
}

function warn_user {
  if [ ${TERM} = "xterm" ]; then echo "${SORRY}"
    else zenity --warning --text="${SORRY}"
  fi
}
function submit_tweet {
  curl -u ${EMAIL}:${PASSWORD} \
       -d status="${TWEET}" \
       http://twitter.com/statuses/update.xml \
  > /dev/null
}

TWEET=$@ #see if it was supplied on the command line
if [ -z "${TWEET}" ]; then getinput; fi #if it wasn't, prompt for it
check_length #make sure it's less than 140 characters
submit_tweet #submit it since we got past the check

if [ ${TERM} = "xterm" ]; then echo "${UPDATED} ${TWEET}"
  else
    exec 3> >(zenity --notification --listen --window-icon=/usr/share/pixmaps/gnome-irc.png)
    echo "message: ${UPDATED}\n\n${TWEET}" >&3
    sleep 10
    exec 3>&-
fi

Just replace the EMAIL and PASSWORD variables and drop it into a directory in your $PATH. You can add it to the panel, too—it will detect if it’s been executed at a terminal or from the panel or other GUI element. It could also very easily be internationalized.

Let me know what you think of this script—it’s 4:00 am and I’m about to pass out.

Sorry, that one line might overflow the box on slim resolutions. I’ll get that fixed one of these days. Update: That was an easy fix. Added overflow: auto; to the codeblock CSS.

HOWTO Run a game or other program on another display

For some reason probably related to Compiz-Fusion, I could not get Warsow working just now. When I started it, my mouse would be locked in the center of the screen. I had four virtual desktops going within Compiz, so I figured that it was somewhat related.

Rather than figure out the bug or close everything I had open, I decided to simply start another X server to handle Warsow.

I did this with startx ./warsow -- :1. I had to modify /etc/X11/Xwrapper.config and change where it says “console” to “anyone” before it would work, though.

This can be done for any program or game, but it’s best suited for those that occupy the whole screen.

In order to switch back to the regular desktop, hit CTRL+ALT+F7. To go back to your game, hit CTRL+ALT+F8. This is useful for switching between a game and work when it’s not your turn or you’re waiting for a long respawn. In fact, I wrote this post switching between Firefox on :0 (F7) and Warsow on :1 (F8).

Oh how I love the things I can do on Ubuntu that I could never do on Windows.

HOWTO Encode a video for an LG VX-8300 phone using FFmpeg

This script might work for other phones, as well. I only have access to an LG VX-8300. Presumably, this would work on all phones newer than it.

#!/bin/bash
echo "Encoding ${1}..."
ffmpeg -i "${1}" -acodec aac -ab 64K -ac 1 -ar 22050 \
                 -vcodec mpeg4 -s qcif -r 15 \
                 "${1}.3gp"

This works perfectly for me, reducing certain YouTube videos to something portable ;-)

HOWTO: Astronomy Picture of the Day for GNOME

Astronomy Picture of the Day is a really neat page which is generated daily by NASA. It shows a single picture captured by some NASA-affiliated person and some text to describe it.

These pictures are perfect for desktop backgrounds. There’s a program to automatically set it as the background for Windows, but we Linux, or more specifically, GNOME, users can do it in a simple script.

Drop this script somewhere on your system and create a cron schedule with crontab -e for it. The cron lines are in the script. I’d recommend the four hour intervals if you don’t keep your computer on all the time, or the twelve or once-a-day intervals if you do.

Oh, and you might need to install cron. Gutsy doesn’t have it by default, so you can do it through Synaptic or using sudo apt-get install cron at a command line.


#!/bin/bash
#Filename: apodwallpaper
#Location: ${HOME}/.bin
#Purposes: Downloads NASA Astronomy Picture of the Day and displays it as the
#          GNOME background 
#Author(s): acvwJosh of Ubuntu Forums, modified by Colin Dean <http://cad.cx>

#add the following line to your crontab if you want to run this hourly
#10   *  *   *   *     apodwallpaper

#add this line if you want to run it every four hours
#10 0,4,8,12,16,20 * * * apodwallpaper

#add this line if you want to run it every twelve hours
#10 0,12 * * * apodwallpaper

#add this line if you want to run it daily 
#10 0 * * * apodwallpaper

#don't forget to put this script in your $PATH.
#I usually add ${HOME}/.bin to my path in .bash_profile and put my scripts there

#change this if you want the image to be in a different directory
FILENAME=apodwallpaper
APODWALLPAPER=${HOME}/.${FILENAME}

mkdir -p ${APODWALLPAPER} && cd ${APODWALLPAPER}

# download image from apod site
wget -A.jpg -R.txt -r -l1 --no-parent -nH http://antwrp.gsfc.nasa.gov/apod/astropix.html

# move image from obscure folder to main folder, rename image
find ./apod -name "*.jpg" | while read line ; do
mv "$line" "${FILENAME}.jpg"
done

# set image to wallpaper
gconftool-2 -t string -s /desktop/gnome/background/picture_filename "blank.jpg"
gconftool-2 -t string -s /desktop/gnome/background/picture_filename \
                         "${APODWALLPAPER}/${FILENAME}.jpg"
gconftool-2 -t string -s /desktop/gnome/background/picture_options "zoom"

#get rid of cruft
rm -rf apod robots.txt

There’s a thread about this functionality at Ubuntu Forums entitled, APOD? anyone.

HOWTO: Creative X-Fi sound card on Ubuntu Gutsy

I know Hardy is due out in less than a month’s time, but I got a Creative Sound Blaster X-fi XtremeGamer on super rebate a few weeks ago and, dammit, I want sound on Linux!

Unfortunately, Creative only recently released specifications to OSS and ALSA. OSS has a driver already in its newest release, but OSS and Ubuntu have never played well together. Most of Ubuntu’s applications prefer ALSA or ESD. Creative did release an ALSA driver a while ago, but only for 64-bit distros.

Fortunately, I’m running Ubuntu Gutsy amd64, so I can use the driver. Fear not, though, one user on Ubuntu Forums has tried it on 32-bit and reported success. He’s refining the process, though, and figuring out how exactly he did it.

NullHead, wolfc, and some others on Ubuntu Forums refined a process by which folks can install the Creative X-fi driver. Unfortunately for Gutsy-using folks, the process requires a kernel recompile because the Gutsy kernel uses SLUB instead of SLAB.

However, the process does work. After compiling the kernel, there’s a a few simple steps and a single patch which customizes the source for Ubuntu users.

Read the thread at Ubuntu Forums entitled [HOW-TO] X-fi beta driver.

It’s really nice to have sound in Ubuntu after not having it for approximately two weeks. I’ve been hopping onto another computer when I need it and using that other computer as my jukebox.

PulseAudio is the new default sound server in Ubuntu Hardy (8.04 for those readers who are out-of-the-loop), but it retains its compatibility with ALSA, OSS, ESD, and various other sound servers in Linux. Hopefully, ALSA will have a driver out soon.

Apparently, a company called Auzentech is working on higher-quality drivers for Windows for its licensing of Creative’s X-Fi technology. It’s also working on Linux drivers, but the ETA isn’t until Q4 2008. If Auzentech can pull it off, you bet your sweet bippie I’ll trade my XtremeGamer for one of its cards. I like to support those who support Linux :-)

HOWTO: Fixing gnome-vfs ssh support in Firefox

In theory, the package firefox-gnome-support handles GNOME’s Virtual File System URLs. However, out-of-the-box, it lacks support for the ssh handler used when connecting to something via ssh.

To fix this, go to about:config and find the key called network.gnomevfs.supported-protocols. Append ;ssh:, thus changing it to smb:,sftp:,ssh:. It will magically work!

HOWTO: Great Windows theme for Wine on Ubuntu

I found today a fantastic Windows theme to use with Wine on Ubuntu. It’s called Human for Windows.

  1. Download the zip file and extract it somewhere. I put it into ~/.wine so that it’s out of sight.
  2. Fire up winecfg at a terminal, or go to Applications > Wine > Configure Wine from the menu.
  3. Go to the Desktop Integration tab.
  4. Click Install Theme… and find where you put the extracted folder.
  5. Go inside it and open Human.msstyles.
  6. Change the drop down to Human.
  7. Hit OK.

Combine this with the mIRC on Linux tutorial from a few weeks ago, and the result is an mIRC that looks like it belongs in Ubuntu.

mIRC on Ubuntu using Wine and the “Human for Windows” Windows theme

HOWTO Become a Republican in order to vote for Ron Paul in the PA Primaries

Update, 2011-12-10: PA no longer has this neat online form. You have a few options, but the easiest is to just to fill out another registration form and tick the “change of party” box.

Pennsylvania, as well as other states, conducts closed primary elections. I believe this to be illegal, but that’s a topic for another day, perhaps closer to May 2008. For those unfamiliar with the concept of closed primary elections, an explanation is due. American political parties generally must offer only one set of candidates for an office, so all of the competition within the party is resolved in the primaries. However, members of a party can only vote on candidates within their party—the hope is to keep saboteurs from voting a weak candidate into the spot for that party. It’s a lousy explanation, but it will suffice.

Herein lays the problem: I’m a registered Democrat. I want to vote for Ron Paul in the primaries because I want my vote to matter and you should want the same for your vote, too! In order to vote for Ron Paul in the primaries, I must do something I thought I’d never do: become a Republican.

Fortunately, this change of parties is merely for paperwork—it’s not like my ideals change overnight. Can you already see the flaws in the system?

Anyway, here’s how I changed my PA voter registration…somewhat on-line. These instructions can also be followed to register if you haven’t already done so. However, there may be a point where things diverge, so be warned: I’m only showing currently registered voters how to change their party affiliation.

  1. Go to www.votespa.com.
  2. Click on Voter Registration on the sidebar.
  3. Click on Voter Registration Application Forms.
  4. Click on Onscreen Voter Registration Application.
  5. Login with your PAPowerPort ID, or create one and login with it.
  6. Once you’re entirely into the system, click Modify Voter Registration on the sidebar.
  7. Leave the information in question #1 alone. It should be correct.
  8. For question #2, check the box beside Change of Party. If you’re a new registrant, check the obvious box.
  9. Inspect the information for questions #3 to #8. I had to fill in my driver’s license number.
  10. Question #9 is the biggie: Change the drop down to REPUBLICAN.
  11. Click the Continue button at the bottom of the page. You may be redirected back to the page and asked to fill in a captcha.
  12. Click Download and Print Form. Print it out and send it in as marked—the elections office still needs your signature to actually change the information.
  13. Click Finish.

Send in that print-out ASAP, as your change isn’t permanent until the office receives your signature.

HOWTO: Run mIRC on Ubuntu Linux

mIRC logo

Back in the day, before I saw the light of Linux, I was an mIRC user. I’d grown quite fond of mIRC, and even registered it to support Khaled Mardam-Bey.

However, now that I’m slowly attempting to move the majority of my major activities to Linux, I’ve found that I don’t really like the majority of the graphical IRC clients available for Linux. Xchat is nice, and Konversation is probably my favorite of them, but I yearned for mIRC. Pidgin and Kopete use too much of an IM-style window for it, especially the latter.

Somewhat unsurprisingly, mIRC works out of the box using Wine.

Download the installer from mirc.com to your home directory or Desktop. Fire up a terminal and do wine mircSetup.exe. Be sure to replace mircSetup.exe with the actual name of the executable. For me, it was mirc63.exe. Also, make sure that you have Wine installed (sudo apt-get install wine) and configured (winecfg).

Once it’s installed, you can execute it with wine C:\\Program\ Files\\mIRC\\mirc.exe. I’d recommend creating an application launcher for it on Gnome-panel or KDE Kicker. You can use the post icon as the icon for the launcher.

If the fonts look odd, you can install msttcorefonts with sudo apt-get install msttcorefonts and it should look better. Additionally, find a nice Windows theme somewhere and use it to make the Wine windows look more like the Human theme of Ubuntu. If you find such a theme, comment below so I can get it, too ;-)

HOWTO Set up an encrypted filesystem on Ubuntu Feisty

I set up an encrypted filesystem image on one of my Ubuntu boxen recently. I won’t tell what is going on mine, but one might use it for personal documents of financial nature or anything that you really don’t want someone to read without having gone through hell trying to decrypt the image or torturing you to get the password.

It was really quite simple.

dd if=/dev/urandom of=/path/to/image bs=1M count=50

This command creates a 50 MB file filled with random bytes. It’s ready to be looped and formatted. Lock it down with sudo chmod 600 /path/to/image.

sudo modprobe cryptoloop;sudo modprobe aes;sudo modprobe loop;

This command inserts the required kernel modules.

sudo losetup -e aes /dev/loop0 /path/to/image

This command puts the image onto a loopback device. You’ll be asked for a password. Be as complex as you can remember.

sudo mkfs.ext3 /dev/loop0

This command formats the image with an ext3 filesystem. You could also use ext2.

mkdir /path/to/encrypted/mountpoint

This command creates the mountpoint so you can have it mount with mount. Lock it down with sudo chmod 700 /path/to/encrypted/mountpoint

sudo vi /etc/fstab

Once in vi or your text editor of choice (pico, emacs, gedit, etc.), add this to /etc/fstab:

/path/to/image /path/to/encrypted/mountpoint ext3 defaults,noauto,loop=/dev/loop0,encryption=aes 0 0
sudo losetup -d /dev/loop0

This command will disconnect the image from the loop device so it can be mounted with mount.

sudo mount /path/to/encrypted/mountpoint

This command will mount the image and you’ll be able to cd into it. You might be asked for a password twice. The first one is your sudo password, the second, the the only one if only once, is your image password. You might want to sudo something else before you mount the image just to make sure that you’re entering the correct password.

sudo umount /path/to/encrypted/mountpoint

This command will unmount the image.

OK, let’s put all this together.

dd if=/dev/urandom of=/path/to/image bs=1M count=50
sudo chmod 600 /path/to/image
sudo modprobe cryptoloop;sudo modprobe aes;sudo modprobe loop;
sudo losetup -e aes /dev/loop0 /path/to/image
sudo mkfs.ext3 /dev/loop0
mkdir /path/to/encrypted/mountpoint
sudo chmod 700 /path/to/encrypted/mountpoint
sudo vi /etc/fstab
echo "Don't forget to stuff to your fstab!"
sudo losetup -d /dev/loop0
sudo mount /path/to/encrypted/mountpoint

If you get stuck, a quick Google search for encrypted loopback will shed some light and further explain things I didn’t.