Tag Archives: ubuntu

emacs daemon for ElementaryOS

I’ve just switched whole hog to ElementaryOS. So now I’m exploring new improvements in some of my ancient setups. For example, emacs. I’ve been using emacs for probably 20+ years. I’ve been using the exact same emacs setup for 5-10 years. Needless to say, I think its likely there are some improvements that are possible. And this wil also apply to other GNOME and GTK environments, I’m sure.

Since I use it a lot, it is worth running it in “daemon” mode, which means that emacs is always running in the background, and running an emacs command really just means connecting to the daemon that is already running. I’ve never found a way to set that up to make it seamless or without silly shell script hacks. I don’t want to remember to type emacsclient with all sorts of various options. I want to just type emacs. And I want to launch emacs in the standard GUI ways and have that work also.

Here’s how I did it. First, setup up the .desktop files to autostart Emacs daemon and configure the GUI stuff to use emacsclient:

~/.config/autostart/emacs24-daemon.desktop

[Desktop Entry]
Version=1.0
Name=GNU Emacs 24 Daemon
GenericName=Text Editor
Comment=View and edit files
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=/usr/bin/env XLIB_SKIP_ARGB_VISUALS=1 emacs24 --daemon
TryExec=emacs24
Icon=/usr/share/icons/hicolor/scalable/apps/emacs24.svg
Type=Application
Terminal=false
Categories=Utility;Development;TextEditor;
StartupWMClass=Emacs24
X-GNOME-Autostart-enabled=true

~/.local/share/applications/emacs24.desktop

[Desktop Entry]
Version=1.0
Name=GNU Emacsclient 24
GenericName=Text Editor
Comment=View and edit files
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=/usr/bin/emacsclient --create-frame --alternate-editor "" %F
TryExec=emacs24
Icon=/usr/share/icons/hicolor/scalable/apps/emacs24.svg
Type=Application
Terminal=false
Categories=Utility;Development;TextEditor;
StartupWMClass=Emacs24

Next up, set up the emacs command in the terminal to also plug into this:

update-alternatives --install /usr/bin/editor editor /usr/bin/emacsclient 50
update-alternatives --install /usr/bin/emacs emacs /usr/bin/emacsclient 50

That’s pretty much it. You might want to set some vars in your .bashrc, but I think that’s optional:

export ALTERNATE_EDITOR=""

# $EDITOR should open in terminal
export EDITOR="emacsclient -t"

# $VISUAL opens in GUI with non-daemon as alternate
export VISUAL="emacsclient -c -a emacs"

simple automated backup to a USB disk on Debian/Ubuntu/Mint

I used to use Mac OS X as my main machine, indeed for 18 years since I started when it was called NeXTSTEP.  Now Apple has turned it into a paradise for mindless consumption, driving creators away.  Now I use Linux Mint as my daily system, but one thing I was missing was a really simple, automatic backup to an external USB disk.  Apple did a good job with Time Machine.  Its simple to setup, happens automatically and in the background, provides a directory structure that you can browse like any standard file system and see the complete snapshots of your computer at the time of a given backup.

So I looked at a lot of apps and tools for doing this on Mint.  I looked at Back In Time, simplebackup, pybackpack, obnam, BoxBackup, rsnapshot, and more.  Back In Time seemed promising, and I probably should have considered it more. Its totally GUI focused, and oriented towards backing up the home folder as a regular user. I want a full disk backup as root. Also, the UI hit me with a ton of options, and I didn’t want to think that much.  simplebackup just seemed like a simple way to make a single backup, with no snapshots. pybackpack is no longer developed.  obnam sounds very promising as a command line tool, but it does not represent the backups as transparent files on a filesystem, so that nixed it for me.  BoxBackup has a client/server architecture, so far too complicated.  I think its oriented towards backing up a fleet of servers to a single backup host.

rsnapshot ended up being quite simple to set up for a command line person like me, and also easy to automate.  And most importantly, it backs up easily to an external disk and writes out each snapshot as a full image of the system at the time of the snapshot.  Sold!  So I just needed to tweak it a little bit.

I had to make a couple edits to /etc/rsnapshot.conf.  One annoying detail to note in this config file is that you have to use tabs between the config items in a line, spaces won’t work. So first I pointed it to a folder on my external USB backup disk:

snapshot_root /media/ext4backup/palatschinken/

Then I told it not to create the root folder on the backup disk. If the backup disk is not present, it should not try to backup at all:

no_create_root 1

Then I enabled one fs mode (i.e. -x in rsync speak), which means that rsnapshot won’t cross the boundaries of a disk. So if you tell it to backup /, and you have /home on a separate partition or disk, it won’t backup /home. You could then add /home specifically, then it would be backed up. Here’s the option:

one_fs 1

Then I specified what I want backed up. These are each separate partitions on my system:

backup / root/
backup /media/share share/

Now the rsnapshot should happily backup. You can test it by running rsnapshot hourly.So the next step is to cron it so it runs automatically in the back ground. I made a script like this for each of the cron folders (/etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly):

#!/bin/sh

# See ionice(1)
if [ -x /usr/bin/ionice ] &&
    /usr/bin/ionice -c3 true 2>/dev/null; then
    IONICE="/usr/bin/ionice -c3"
fi

test -d /media/ext4backup/palatschinken && \
	nice $IONICE /usr/bin/rsnapshot hourly

Be sure to change the hourly in each script to match the folder its in. Adding in nice and ionice makes it run at very low CPU and disk priority, so you don’t notice that its running really. Lastly, if you are using this on a machine that is shutodwn or goes to sleep often, then you probably want to install anacron to make sure the daily, weekly, monthy jobs run (apt-get install anacron, it usually configures itself to do the right thing once its installed).


Setting up a chroot for Raspbian

I want to be able to build packages for Raspbian but on a regular machine.  Luckily, there is the very handy qemu-debootstrap which will let you setup a normal debootstrap chroot that runs via qemu.  Here’s how I did it (this is on Squeeze, for newer releases, you won’t need the backports.  You need qemu-user-static v1.1.2 or newer):

sudo apt-get -t squeeze-backports install qemu-user-static
sudo apt-get install dchroot schroot debootstrap wget
wget https://archive.raspbian.org/raspbian/pool/main/r/raspbian-archive-keyring/raspbian-archive-keyring_20120528.2_all.deb
sudo dpkg -i raspbian-archive-keyring_20120528.2_all.deb
sudo mkdir /var/chroot/raspbian-armhf/
sudo qemu-debootstrap --keyring /usr/share/keyrings/raspbian-archive-keyring.gpg \
 --arch armhf wheezy /var/chroot/raspbian-armhf http://archive.raspbian.org/raspbian
echo raspbian-armhf | sudo tee /var/chroot/raspbian-armhf/etc/debian_chroot
sudo ln -s ../proc/mounts /var/chroot/raspbian-armhf/etc/mtab
sudo cp /etc/passwd /etc/group /etc/shadow /var/chroot/raspbian-armhf/etc

Then I edited my /etc/fstab to add the mount points:

#
# raspbian-armhf chroot
#
/home           /var/chroot/raspbian-armhf/home        none    bind            0       0
/tmp            /var/chroot/raspbian-armhf/tmp         none    bind            0       0
/dev            /var/chroot/raspbian-armhf/dev         none    bind            0       0
proc-chroot     /var/chroot/raspbian-armhf/proc        proc    defaults        0       0
devpts-chroot   /var/chroot/raspbian-armhf/dev/pts     devpts  defaults        0       0

I edited /etc/dchroot.conf to add the new chroot:

raspbian-armhf /var/chroot/raspbian-armhf

And then /etc/schroot/schroot.conf to add the new chroot there:

[raspbian-armhf]
description=raspbian wheezy armhf
location=/var/chroot/raspbian-armhf
users=pd
groups=sbuild-security
root-groups=root
personality=linux32

Now I’m ready for the last steps, then I can use my chroot:

sudo mount -a
dchroot -d -c raspbian-armhf

If it was successful, you should see your prompt change to:

(raspbian-armhf)pd@pdlab3:~$ 

automatically delete old things from the Downloads folder

Lots of OSs have a handy ~/Downloads folder where all downloaded files automatically go to. This is much cleaner than say, piling them up on the Desktop or elsewhere. I generally move something out of ~/Downloads if I need it, leaving the rest to pile up. Thanks to the very helpful tmpreaper, I have it automatically deleting any file older than 5 days from ~/Downloads. Now it manages itself. You can do this easily with Debian-based OSs (sudo apt-get install tmpreaper) or Mac OS X (fink install tmpreaper). You can cron it using a little script in the right folder:

/etc/cron.daily/tmpreaper_downloads (Debian)

#!/bin/sh
/usr/sbin/tmpreaper --all --protect .localized 5d /home/hans/Downloads

/etc/periodic/daily/900.tmpreaper_downloads (Mac OS X + Fink)

#!/bin/sh
/sw/sbin/tmpreaper --all --protect .localized 5d /Users/hans/Downloads

svn vs. HFS+ on GNU/Linux

I run Ubuntu and Mac OS X on a MacBook Pro as my main machine. I do most development work on Ubuntu and most emailing, calendaring, etc. on Mac OS X. But sometimes I want access to my source code in Mac OS X to do quick little fixes and the like. So I made a case-sensitive HFS+ partition that is mounted read/write in both Ubuntu and Mac OS X. Ubuntu can’t handle the HFS+ journalling yet, and HFS+ without journaling seems to explode every once in a while, so I didn’t want to mount my Mac OS X system read/write on Ubuntu, hence the separate partition.

It works quite well, especially when working with git, since the folder is the repo. With svn, its a bit of a different story. It mostly works, but there are some cases where SVN freaks out. If I do svn update in a folder, it all works fine. If I do svn update Makefile, i.e. only directly updating a file, I get:


hans@palatschinken externals $ svn up Makefile
svn: Can't open file 'Makefile/.svn/entries': Permission denied

Apparently this is a known issue to the SVN devs, but they don’t want to fix it: Re: svn diff issue: svn confuses files with dirs on hfsplus?


libtool error dumps

So GNU libtool and the whole autotools suite does seem to help a lot with complicated builds that need auto-detection of all sorts of things, but they can also be an exercise in totally obtuse errors, bizarre scripting, and frustration. I suppose all build systems really share those qualities in some respect. One thing that I’ve run into with puredata/pd-extended is this strange error dump from libtool that seems to be unfindable via search engines. Here’s a snippet:

../libtool: line 844: X--tag=CC: command not found
../libtool: line 844: X--tag=CC: command not found
../libtool: line 844: X--tag=CC: command not found
../libtool: line 844: X--tag=CC: command not found
../libtool: line 877: libtool: ignoring unknown tag : command not found
../libtool: line 877: libtool: ignoring unknown tag : command not found
../libtool: line 844: X--mode=compile: command not found
../libtool: line 844: X--mode=compile: command not found
../libtool: line 877: libtool: ignoring unknown tag : command not found
../libtool: line 877: libtool: ignoring unknown tag : command not found
../libtool: line 844: X--mode=compile: command not found
../libtool: line 844: X--mode=compile: command not found
../libtool: line 1011: *** Warning: inferring the mode of operation is deprecated.: command not found

Why on earth did libtool prepend that ‘X’ to the command line options and try to run them as commands? WTF? This has baffled me to no end… until I realized its because a one version of libtool does not like files generated by a different version of libtool! Arg. I solved this by deleting the m4 folder in my project, then restoring what files are needed in that folder by doing git reset --hard


sharing /home across Ubuntu and Mac OS X

I dual-boot between Ubuntu and Mac OS X on my MacBook Pro, and I like to have the setups parallel each other as much as possible. This means I can do things like share git repos and Android AVDs across OSes. One annoying detail is that the root of the home directories is different in each OS. In GNU/Linux, its /home. In Mac OS X, its /Users. That can be easily solved by using a symlink, i.e. ln -s /Users /home. But arg, Mac OS X’s NFS automounter gets in the way! It mounts /home and then if you use a networked home folder, it’ll mount it in /home. But who uses that on a laptop?


$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local)
fdesc on /dev (fdesc, union)
map -hosts on /net (autofs, automounted)
map auto_home on /home (autofs, automounted)
/dev/disk0s3 on /Volumes/Ubuntu (fusefs_ext2, local, read-only, synchronous)
/dev/disk0s4 on /Volumes/Untitled (fusefs_ext2, local, read-only, synchronous)
/dev/disk0s5 on /Volumes/64-bit (fusefs_ext2, local, read-only, synchronous)
/dev/disk0s6 on /Volumes/share (hfs, local)

I say get rid of it! Luckily Apple hasn’t killed all the UNIXiness of Mac OS X, and you can still do useful things by editing simple text files. The NFS automounter is a good example, its settings are in /etc/auto_master and /etc/auto_home. So I edited /etc/auto_master as root and just commented out the line about automounting /home, then told the automounter to re-check its config, and voila! No more annoying /home mount! So in summary:


$ cd /
$ sudo emacs /etc/auto_master
$ sudo automount -vc
$ sudo umount /home
$ sudo rmdir /home
$ sudo ln -s /Users /home

Ubuntu Lucid upgrade nuked my window frames!

So I recently upgraded my Ubuntu/Karmic install on my laptop to Ubuntu/Lucid. As part of working on and attending DebConf10, I starting using Ubuntu a lot more than Mac OS X, so I thought that some newer versions of the software would make things run smoother. For the most part, it did, except for one major annoyance: upon logging in, none of my windows had frames and they all would stack up in the upper left corner and act funny. Often my keyboard would stop working all together. So my windows were sans “decorations”, the term I learned in the process of lots of searching. Turns out there are many Ubuntu bug reports related to missing window decorations, but none of them seemed to apply to my situation.

There is one thing that would make my window decorations reappear: compiz --replace. But I’d have to run that manually every time. Ug, what a pain. I tried deleting things like ~/.metacity and ~/.compiz and still no luck. I tried setting the Visual Effects to None in the Appearance System Preferences. Still no luck. Then my MacBook croaked so I copied my home folder to a little HP Mini 210 netbook, and voila, it had the same problem. Only this time this machine didn’t have the GPU to handle compiz, so I was only using metacity.

Finally after even more searching around, I found the answer to my problem: the GNOME saved-session! I grepped in ~/.config/gnome-session/saved-session/*.desktop for “compiz” and found there was something in there that was starting compiz in a particular way. I removed that and presto! I now have window decorations when I login. Aaahhhhhh….


watch out with those mount point names!

So I am using Ubuntu Hardy more and more, and am quite impressed at how integrated things are. For a long time, Debian has been very well integrated on the command line for servers and things like that, but Ubuntu is really tackling giving all of the myriad apps a standard GUI. GNOME is helping a lot too, of course.

So I just set up a firewire drive to use for development work, and I saw in the Properties panel for the disk, under the Volume tab, I could set the mountpoint name. So I typed out a whole path in the Mount Point: field, /home/hans/code/openembedded, as I usually would when mounting on the command line. Then hit Close, and unmounted and remounted the disk.

When I plugged it back it, I got this obtuse message:

Cannot mount volume.
Unable to mount the volume.
Details
mount_point cannot contain the following characters: newline, G_DIR_SEPARATOR (usually /)

Hmm, WTF? Now what, the disk won’t mount, so I can’t bring up that Properties panel again… arg… hmm…. think, think. Let’s try running gconf-editor from the command line, for any (former?) Windows users, that’s like the Registry Editor. I try Edit -> Find…, type in openembedded, and check the boxes to search both key names and key values. That gives me the setting, where I change /home/hans/code/openembedded to openembedded, and it works! Phew…