Archive for the 'Linux' Category

Poor Man’s Cron Trigger

This is a handy trick I use when I want to execute something as root when some event triggers, but without any interaction between the event and the start of the action. It’s quite unsafe and dirty, but it gets the job done.

When the event happens, make it create a file:

touch /tmp/this-event-happened

Now add the following cronjob as root (or whatever user you want):

* * * * * /bin/rm /tmp/this-event-happened 2>/dev/null && /bin/bash\
/execute/this.sh

First come the stars, which tell cronjob to execute this command every minute. Then we try to remove the /tmp/this-event-happened file. rm will exit with an error-code when the file doesn’t exist, and in that case the script won’t be executed, because we’re chaining it using “&&”, the AND operator. In a shell, and most modern programming languages, if the first parameter of an AND operator is false, it won’t even evaluate the second parameter, because the total result will definetly be false anyway.

If the file does exist, the shell will evaluate the second parameter as well, and thus execute the script. Meanwhile the file will be removed, so everything is set up for the next trigger.

As you can see, very simple. It has some problems though. For example, any user can create files in /tmp, so it’s not very safe. You could create a directory somewhere that’s only accessible to the user that is allowed to generate the event, and put the trigger-file there. Another disadvantage: if the script takes longer than a minute to run, and the event is triggered again, the script will run twice at the same time. So take care when using this!

Could not create rewrite_log_lock

If you’ve rolled your own kernel and you’re getting this error when starting Apache:

[crit] (38)Function not implemented: mod_rewrite:
 could not create rewrite_log_lock
Configuration Failed

It’s probably because you’ve cut a vital library - System V IPC. Enable it under General Setup - System V IPC, and recompile.

Ubuntu Tip: Hostnames

Ubuntu Hostname
Since Ubuntu runs Avahi by default, every regular Ubuntu PC broadcasts its hostname. As a result you can use “host.local” as the hostname to connect to, where host is the name of the box running Ubuntu. It will automagically find it, even if you don’t know the IP address.

Handy for SSH, webservers, shared disks, or even just a simple ping.

How-To: Passwordless Sudo

This one is as much for you as it is for me. Every time I install a new system, I forget how to set the /etc/sudoers file so that I can execute certain applications as root using sudo without having to enter my password. This is very useful for scripts, or for harmless commands that you need te execute a lot — like vpnc — but still require root permissions.

Start by opening the editor of the sudoers-file:

$> sudo visudo

This will open the file in vim, which you might not be familiar with. No problem, just type i which puts it in insert-mode and it’ll work as any other editor.

Append a line in the following format at the end:

username ALL=NOPASSWD:command1, command2, ...

For example, mine:

david ALL=NOPASSWD:/usr/sbin/vpnc, /usr/sbin/vpnc-disconnect

As you can see, you need to use the full path for every binary. If you don’t know them by heart, find out using the whereis command:

$> whereis -b vpnc
vpnc: /usr/sbin/vpnc /etc/vpnc.conf /etc/vpnc /usr/share/vpnc

Usually the first result is the correct one.

Save the sudoers file by pressing ESC and typing :wq return. Now you can use sudo on the commands you entered without having to type your password. Have fun!

PS: There’s also a way to allow passwordless sudo for all commands, but I’m not telling how since that really isn’t safe. You’ve run away from Windows for a reason, remember? This is one of them ;) .

How-To: Photoshop CS2 on Ubuntu Gutsy

Since Wine 0.9.54 got released yesterday, I’m giving a step-by-step to get Photoshop CS2.0 to work on Ubuntu Gutsy, using Wine 0.9.54. Although Photoshop CS2.0 should work now, installing it still requires a tad of magic, as I discovered when trying to get it installed.

Photoshop CS2 On Ubuntu

There are probably multiple ways to install Photoshop CS2 but this is the path I took, after finding out it crashes while trying to install it the normal way. This How-To requires a Windows XP installation.

Step 1

Install and activate Adobe Photoshop CS2.0 on a Windows machine.

Step 2

Still in Windows, go to Start->Run and type in “regedit“. Now browse to HKEY_LOCAL_MACHINE/Software/Adobe, and export it to adobe.reg.

Next browse to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\
Uninstall\{236BB7C4-4419-42FD-0409-1E257A25E34D}
and export that to adobe_uninstall.reg. (Apparantly you only need the keys EPIC_ORG, EPIC_SERIAL, and EPIC_NAME, but I was already getting fed up with switching between OS’s that I just imported all the keys in that directory, just for good measure.)

Step 3

You can go back to Ubuntu now. Copy the directory C:\Program Files\Adobe to ~/.wine/drive_c/Program Files/. If you installed Photoshop CS2.0 in another directory, copy that one instead.

Meanwhile, install recode and recode the .reg-files you created in Step 2:

$> sudo apt-get install recode
$> recode utf16..utf8 adobe.reg
$> recode utf16..utf8 adobe_uninstall.reg

Install them using regedit in wine:

$> wine regedit adobe.reg
$> wine regedit adobe_uninstall.reg

You’ll also need to install the font Times32:

$> cd /tmp
$> wget http://heanet.dl.sourceforge.net/sourceforge/corefonts/\
times32.exe
$> wine times32.exe

Trying to get the normal way to work, I also did the following. I don’t know if this is required, but if these steps don’t work, you might want to try running it as well:

$> cd /tmp
$> wget kegel.com/wine/winetricks
$> sh winetricks vcrun6

Everything should be in place now. Try running it:

$> wine ~/.wine/drive_c/Program Files/Adobe/\
Adobe\ Photoshop\ CS2/Photoshop.exe

If it asks you to Activate, and then gives an error saying there’s not enough disk space to activate, then you need to temporarily allow read+write access for all to your primary drive device — that’s /dev/sda or /dev/hda or something like that. E.g. mine is /dev/sda (and I have partitions /dev/sda1, /dev/sda2, …), so I do the following:

$> sudo chmod a+wr /dev/sda

Now restart Photoshop, the activation process should work smoothly now. Don’t worry, it won’t actually write anything. After you’re done, change the permissions back:

$> sudo chmod a-wr /dev/sda

This last tidbit I got from here.

Enjoy Photoshop CS2 goodness on Ubuntu!

Photoshop on Linux, finally

The new release of wine, 0.9.54, finally has support for Photoshop CS and Photoshop CS2 (no word on CS3 yet). This was one of my only complaints about linux - it didn’t have a decent Image editor. Sure, Gimp can handle a lot. It’s also unintuitive and has many, many quirks I don’t like.

Now if only more games would be playable on Linux…