More Fun with Screen and SSH with Byobu: Automatic Reattaching

A while ago I wrote about screen, which makes your SSH experience more satisfying. There are some enhancements you can make to screen with .screenrc, but Byobu does more by default than I ever could be bothered to figure out. It seems to come pre-installed on Ubuntu, while aptitude install byubo suffices for Debian.

I thought it’d be even better if screen automatically attached itself when logging in through SSH, and clearly I wasn’t alone in that thought. I made a slight adjustment to the code I found so that Byobu is utilized when available and otherwise regular screen will load. Screen is often installed by default, unlike Byobu, so that way I won’t have to install or compile Byobu to reap the benefits of my custom .bashrc.

# From http://tlug.dnho.net/node/239
# "The following code when added to your .bashrc file will, after logging in via ssh, look for any unattached screen sessions and automatically attach to the first one found. If only attached sessions are found then a list of these will be outputted to std out. Finally, If there are no screen sessions running at all then a new screen session will be created."
if [ $SSH_TTY ] && [ ! $WINDOW ]; then
	SCREENLIST=`screen -ls | grep 'Attached'`
	if [ $? -eq "0" ]; then
		echo -e "Screen is already running and attached:\n ${SCREENLIST}"
	else
		type -P byobu &>/dev/null && byobu -U -R || screen -U -R
	fi
fi
# Optionally adding the following will alter your prompt to let you easily know which window within a screen session you are currently in.
if [ $TERM = "screen" ]; then
	PS1='window ${WINDOW} '$PS1
fi

Comments

Time Synchronization: NTP

Today I noticed that my computer clock was running fast, meaning that Debian doesn’t come with some kind of time synchronization enabled by default. Ubuntu doesn’t exactly either, but setting your location seems to take care of it in Ubuntu.

There’s really nothing much to tell here. Debian Wiki has all the instructions lined up already.

  • Type date to see current date and time
    date
  • Install NTP
    aptitude install ntp
  • Done.
  • Type ntpq -p to see servers you are syncing with.
  • Type date again to see if the time changed. You time should be synced in a next minute.
  • Done.

There’s nothing more to do, though I often like to take a peek at the configuration files and the man pages — the latter is typically a bit too dense unless you already know what you’re looking for. In this case, that would mean man ntpd, man ntp.conf, and, most important, nano /etc/ntp.conf (or whatever your favorite text editor is). It doesn’t look like there’s anything of particular interest, but you might want to replace some of those default Debian server pools with ones geographically closer to you. The easiest way is to check on www.pool.ntp.org, but if e.g. your ISP offers such a service it might be a good idea to use it.

In my case, Belgium didn’t have too many servers, so I made up my own mix of Belgium, the Netherlands, and Europe.

#server 0.debian.pool.ntp.org iburst
#server 1.debian.pool.ntp.org iburst
#server 2.debian.pool.ntp.org iburst
#server 3.debian.pool.ntp.org iburst

server 0.be.pool.ntp.org
server 1.nl.pool.ntp.org
server 2.nl.pool.ntp.org
server 3.europe.pool.ntp.org

Also see how to disable the daemon on battery power. I don’t know how much of a difference that would actually make, but as the Dutch idiom goes, all small bits help.

Comments

Unmount Flash Drives & Memory Cards

It seems that Gnome’s safely remove drive feature works just like the equivalent in Windows: not at all. It even displays the exact same useless error message, almost word for word: this device cannot be stopped. Not the slightest hint about why this might be the case.

Following this scenario, on Windows you’d pretty much be stuck shutting down your computer to be sure that no data loss will occur (although workarounds like Unlocker exist, or you can use Process Explorer to figure out the culprit manually). Luckily, on Linux the workaround is a lot easier. Use mount to display information about all currently mounted file systems and umount to, you guessed it, unmount the file system of your choice.

$ mount
[…]
/dev/sde1 on /media/888E-E0E0 type vfat (rw,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush)
$ umount /dev/sde1

PS I just found out that I’m mistaken, but I already wrote the post and besides, the point that you’re able to do things like this if you want, whereas you’d be stuck in Windows, still stands. It seems that the way Gnome devs envisioned unmounting is not while you’re viewing it in Nautilus by right-clicking, but by right-clicking on the icon on the desktop.

Comments

Remote Desktop: Remmina

A quick tip for Ubuntu users: install Remmina instead of (or alongside) the default Vinagre with sudo apt-get install remmina. It’s much better. Not only does it perform better (that is, it doesn’t hog CPU), but it has all the options Vinagre lacks.

Comments

Using Wine to Ease Migration from Windows

According to its about page, “Wine lets you run Windows software on other operating systems. With Wine, you can install and run these applications just like you would in Windows.” That sounds like a good enough description to me.

I have some applications that depend on a specific drive letter configuration, so to be truly able to share applications between Wine and Windows I’ll have to set up my drives in Wine just the way they are on Windows. I may write a post later about how to auto-mount Windows partitions.

Setting up drives is incredibly simple: you start the Wine configuration program and go to the drives tab. There you can set up certain directories or mount points to correspond to certain drives for Windows programs, but you don’t even have to use the GUI. The reason this is useful is because you can run your programs like you were on Windows and they wouldn’t know the difference. As far as the programs are concerned they’re reading data from the same location as always. This greatly simplifies my process of switching to Linux. Rather than having to set up replacement programs and configurations I can simply let Wine pretend to my programs that they’re running in the same (drive) configuration as they would on Windows. This way I can switch more completely to Debian without having to exert a lot of effort at once. I can move away from certain programs more slowly, or perhaps not at all.

I found a Gnome to Wine Color Scraper to improve the look of my Wine applications, but the registry file it generated didn’t work for my version of Wine. I enabled the debugging option and had to edit the parts where it speaks of HKEY_USERS\S-1-5-4\. For me the number was different. Check in regedit for specifics.

There are many more things you can do with Wine, including playing a fair amount of Windows-based games. Check the website for more information on compatibility.

Comments

Kiwis These Days

Wil Wheaton is always posting conversations he’s had with his wife, so why shouldn’t I?


“You want kiwi?” I asked.

“There is cold?” Mel replied. She doesn’t like fruit that hasn’t been refrigerated, which I take into account unless I happen to forget about it.

“Yes! There’s alway cold kiwi. It’s like a disease. They just jump in the fridge these days. I was walking through the fridge this afternoon—”

“You were walking through the fridge eh?”

“BY!!! By the fridge! And this kiwi suddenly jumped up against me, and I was like, ‘dude wtf are you doing.’ The kiwi was really rude. It said: ‘fuck off, you ass, you’re blocking the road to the fridge.’ So I said ‘chill, kiwi.’ It replied, ‘yeah, that’s what I want to do, Einstein, but you’re keeping me from it.’ I wasn’t going to put up with that, so I said, ‘first apologize for your rudeness or I’ll just let you rot.’ Then it just kind of rolled over like it were one big, giant eye, shrugged — honestly, it did that! — and said, ‘sorry that I bumped into you but I really need to get into the fridge now.’ I opened up the fridge and said ‘alright, but no more shenanigans or I’ll drag you out of there if it’s the last thing I do.’ It jumped right in and let out a big sigh: ‘aaaaaaaaaaaaaaaaaaahhh.’ Then it pulled the fridge closed while muttering something about privacy. So yeah, that’s how kiwis are these days. No respect.”

She didn’t reply verbally, but she pulled… the face.

Comments

Lossless Rotation with jhead and jpegtrans

I like my pictures rotated in such a way that I don’t have to depend on application support for them to be displayed correctly. jpegtran (pre-installed on most distros) is a wonderful application with many features, including lossless rotation, but it’s too laborious for my purposes. That’s where jhead comes in.

You can simply go into a directory, run a command like the following, and everything will be done automatically for you.

jhead -autorot *.JPG

Of course I wouldn’t run it if you don’t have a backup available. I always keep the pictures around on my camera until I’ve confirmed that all processing was successful and then I still don’t delete them until the adjusted files were also copied to my external HDD in my semi-regular backup regime.

Another utility that can perform the same task is exiftran, but despite being more or less dedicated to this very purpose it’s not even easier to use: I’d expect exiftran *.JPG to default to the equivalent of the jhead -autorot *.JPG command I posted above, but instead you have to use exiftran -ai *.JPG. All other things being equal for my purposes, I decided to go with jhead because it has many more features — although last year I decided that exiv2 is superior to jhead in ease of use for most of those features.

If you’re just looking for the occasional lossless rotation, you could also try the Geeqie image viewer and manager. It integrates calls to exiftran, but beware that you explicitly have to choose the lossless option, as there are also lossy rotate options.

Comments

Dolby Digital 5.1 Over S/PDIF With PulseAudio

This post describes how I got Dolby Digital 5.1 output working over S/PDIF on my onboard Realtek chip with other audio sources mixed in. Previously I was only able to achieve either 5.1 output by sending the data stream straight to my receiver, or 2.0 output with everything mixed in. The experiences detailed in this post originate in Debian Squeeze, but if what I wrote is specific to anything, it should be my hardware — not Debian and its derivatives. Before you read on, you might want to check out this forum post instead, which describes a method that didn’t work out for me.

PulseAudio 0.9.22 is required; it won’t work on older versions of PulseAudio. Debian Squeeze comes with ALSA 1.0.23; presumably that’s much less significant. On Debian getting this most recent PulseAudio can be done through the experimental repository.

If you’re on Debian ALSA is already setup, including the required libasound2-plugins, but to get the most recent version of PulseAudio you’ll want to add deb http://ftp.debian.org/debian experimental main to /etc/apt/sources.list, and then type apt-get update && apt-get -t experimental install pulseaudio in a superuser terminal (see the Debian Wiki for more information on the experimental repository). On many other distributions PulseAudio is already setup by default, but just like on Debian Squeeze that’s typically still PulseAudio 0.9.21 at present.

On Ubuntu you’d have to recompile libasound2-plugins yourself because it doesn’t include the a52 ALSA plugin by default. The link in the opening paragraph should describe that process sufficiently.

In the System Log Viewer you can keep an eye on syslog for (error) messages from ALSA as well as PulseAudio.

What follows is my /etc/asound.conf, heavily condensed from Johannes Bauer’s Dolby Digital with Linux and ALSA guide. It works quite nicely (with some minor adjustments), but it will only allow one application to utilize audio at a time. One could utilize PulseAudio for stereo while suspending it (with pasuspender) when you want to play a movie or some such with 5.1 audio, but I’d rather mix everything together in PulseAudio so I don’t have to think about it after the initial setup, just like in Windows.

# Encode AC3 -> Directly on hardware
pcm.Filter_A52Encode {
	type a52
	bitrate 448
	channels 6
}
# Rate Converter to 48kHz, needed for some applications
pcm.a52 {
	type rate
	slave {
        	pcm "Filter_A52Encode"
        	rate 48000
	}
}
# Make last filter the default device
pcm.!default {
	type plug
	slave.pcm "a52"
}

Now that you’ve got the ALSA configuration in order it’s time to make some slight adjustments to /etc/pulse/default.pa or PA won’t detect the possibility for Digital Surround 5.1. According to various sources they had some kind of Digital Surround show up automatically, but I had to explicitly tell PulseAudio about its existence. Adjusted from a comment on Ubuntu bug 348353 (which incidentally is why you need PulseAudio 0.9.22).

load-module module-alsa-sink device=a52 rate=48000 channels=6 tsched=0 sink_properties=device.description=SPDIF sink_name=SPDIF channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe

I initially added this line without the channel_map, but then PulseAudio thought I had something like front-left,front-left-of-center,front-center,front-right-of-center,front-right,lfe, which would be a strange setup indeed.

I’m not quite sure whether the channel map might be more appropriate in /etc/pulse/daemon.conf, where I uncommented default-sample-rate = 48000. I also added the appropriate settings for default-sample-channels = 6 and changed enable-lfe-remixing to yes.

pavucontrol is instrumental in quickly seeing what’s going on and for application-specific volume settings. Not utilizing it would be a disservice for yourself if you’ve chosen to use PulseAudio.

Now that we’ve got all the configuration set up you could reboot the computer, but one of the great things about Linux is that you rarely have to do that other than to load a different kernel.

As user: pulseaudio --kill
As superuser/sudo: /etc/init.d/alsa-utils restart
(As user: pulseaudio -D, but that shouldn’t be necessary)

I utilized the surround test ac3 file from Lynne Music (straight to directory). I played it with mplayer -channels 6 to make sure everything was working correctly and to adjust the channel map. At this point everything was finally working fine for me, but most applications still will not cooperating because they default to ALSA. Again, in Ubuntu this shouldn’t be an issue.

Various adjustments are still required in most applications. For instance, in Totem you have to explicitly set audio output to 5.1 in Edit > Preferences > Audio.
For MPlayer put channels=6 in ~/.mplayer/config (note that if you can’t get PulseAudio to work you could add the equivalents of mplayer -ao alsa:device=spdif -srate 48000 -ac hwac3 file.avi if you so desire).
VLC works fine if Dolby Surround is set to Auto in Tools > Preferences > Audio.

To get the 6 channel output to work in applications that use SDL (Gnash, quite a few games) you’ll need libsdl1.2debian-pulseaudio. This will replace libsdl1.2debian-alsa. Of course this won’t be necessary if your distro is set up with PA by default.

On a separate note, I set PulseAudio up so it can play audio from all kinds of sources (most notably my laptop).

Comments (1)

Mouse Jail

One of the applications I like to use on Windows is Mousenitor, which enables advanced mouse control for users with more than one monitor. It was written by a friend. I haven’t yet figured out the best way to trap my mouse on one monitor in Linux, but a little application named Jail offers a rudimentary implementation. It was originally written by Sebastian Marion, but I picked up a slightly modified version from the Ubuntu forums.

If you want to compile it yourself you need to grab apt-get install build-essential libx11-dev libxtst-dev in Debian (and presumably the same for derivatives like Ubuntu). For good order I also uploaded the source, including my compiled x64 binary, to my own server lest the original source code might be deleted. Download jail.tar.xz if you want to test it. Edit .JailSwitch.sh to correspond to your system.

The Gentoo Wiki possibly describes more elegant, but more involved methods to obtain a similar effect. I’ll report back if I can get one of those methods to work successfully, and if they do indeed work more elegantly.

Comments

SVN

Just a quick reminder to myself: SVN is short for subversion, so to install it you need apt-get install subversion.

Comments

« Newer EntriesOlder Entries »