Installing a package from the AUR in Arch Linux

Today I wanted to try out Bibble, a photo editing and RAW conversion tool. Unfortunately, it is not available by simply running pacman -S bibble or something on the console. It is, however, included in the Arch Linux AUR repository, which means you can download some scripts that basically download all dependencies for the program, and then build the program itself from source files (which are also downloaded by the scripts).
Although this is much easier to do than really executing a source build (where you call configuration scripts, make, etc yourself), there are some challenges. So this is a quick recap of what I did. Hope this helps someone who is yet struggling with the AUR.

So the first thing you do is to find your package in the AUR. In my case, this was Bibble. Go to aur.archlinux.org, and search for your program.
Once you found it, there will be two files you need to put on your computer: The tarball (there is a link called Tarball, which downloads a tar.gz file (mine was bibblepro.tar.gz).
The second file is called PKGBUILD.
Put these two files in a directory on your machine. Then, in that directory, type
tar -xvzf bibblepro.tar.gz (my archive was called bibblepro, yours will differ).
This will generate a new directory. Change into that directory.
Inside the directory, type
makepkg -s
This will execute the PKBUILD script. So before you do that, you should look at that file in a text editor, to make sure there are no nasty surprises. You really want to know what is going on in there, and it’s usually not all that much.
This is where the fun starts, because even though the -s option makes pacman install any required dependencies, the nature of the AUR repository has it that dependencies on these programs are also often not in the standard pacman repository. If this happens, the script will fail with a message saying that pacman cannot locate some dependency. So you have to install these in the same way you install your main program, too.
Basically, you do this the same way you are trying to install the main program: Go to the AUR, locate the file the failed install complained about, download the two files (tarball and PKBUILD), and hope for the best. After this completes, restart your original install with makepkg -s.
Once you reslolved all those missing dependencies in that way, and the main run of makepkg is through, there will be a new archive file (called bibblepro-5.2.3-1-x86_64.pkg.tar.xz or something). You can now use this to to actually install the main program for real with pacman. To do that, type
sudo pacman -U bibblepro-5.2.3-1-x86_64.pkg.tar.xz

Posted in Linux | Leave a comment

How to disable the annoying speaker beep in Arch Linux

This has been driving me crazy for a while, but I never did anything about it: Whenever I use the keyboard to delete a file in the file manager using the DEL key, or go back a directory using BACKSPACE, or some everyday task like that, the computer beeps really loud, and almost makes me jump out of my chair. Disabling the speaker in ALSA Mixer does not work, and setting the volume to zero also does not help. So here is how to get rid of that beep:

In a terminal, write

xset -b

You can of course also put this in your startup script (.bashrc or something) to make it permanent.

Posted in Linux | Leave a comment

Java dependencies in Grails – a bad joke?

Today I tried to do a really simple thing with Grails (or so I thought): I merely wanted to include a jar file in a Grails project. So what did I do? Well, I took the jar file (myjarfile.jar) and put it into the lib folder inside my Grails project. Then I used some of the classes in that jar file in my editor, and everything worked. But then I trired to compile the project, and big surprise: The compiler could not resolve the java files from the jar.
Well, I was stunned at first that this would not work, because everything in Grails is supposed to be all automagical and all. So importing a simple jar file should not stump Grails!
It did, apparently, and my development environment (SpringSource Tool Suite) didn’t help me either. So I googled for about half an hour, only to find that you have to manually (!) include the jar file dependency in a file called BuildConfig.groovy, and in a very weird way too:

In that file, there is a section for dependencies like jars, and you are supposed to enter your dependency like this:

runtime 'mysql:mysql-connector-java:5.1.16'

Well, I supposed that the first part (mysql) was the package name you want to use, and the second is the jar’s name, and the third is the version. I tried without the version first… no luck. So I actually had to give that jar file a bogus version to be acceptable for this configuration. Well…
So my final entry in that file looks like this now:

compile'com.myproject.mypackage:myjarfile:1.0'

It works now, but I have to say I’m not impressed by this. This is so counter-intuitive and weird. With Grails building on Java and everything, why can it not just accept the libs folder on its own for dependencies? Maybe I am missing something here, but whatever. Anyway, hope this helps someone.

Posted in Technology | Leave a comment

Deploying 3rd party jars to your local maven repository

Let’s say you have some home made project that you want to use in one of your projects, and you want to include this project as a dependency in one of your other projects. Your other project is using maven. So how do you get the first project as a dependency into your other project?
Simple, deploy it as a jar file to your local maven repository. Maven already provides a goal for that:


mvn install:install-file -Dfile= -DgroupId= \
-DartifactId= -Dversion= -Dpackaging=

So say your file is called 'MyCustomProject.jar', and you want it to be in the group 'com.myprojects', and the artifact should be called 'coolproject', and the version should be '1.0'. Then you would type

mvn install:install-file -Dfile=MyCustomProject.jar -DgroupId=com.myprojects \
-DartifactId=coolproject -Dversion=1.0 -Dpackaging=jar

This will install the jar file in the repository, and also already create the pom.xml file for you. Then, when you include this as a dependency in your other project, just add this to the other project’s pom.xml file:

<dependency>
<groupId>com.myprojects</groupId>
<artifactId>coolproject</artifactId>
<version>1.0</version>
</dependency>

Maven should now pick the project up, and it is ready for use.

Posted in Uncategorized | Leave a comment

My browser can’t find my favorite sites

I am recently having lots of problems visiting my favorite sites, like Google and facebook. The problem seems to be that the DNS server I’m using is not doing its work. So I tried to change it. Running on Arch Linux, and using DHCP, not a static setup, that’s not so easy however. You can always change the DNS server by modifying /etc/resolv.conf. But this gets overwritten every time the network starts. And disabling this is also not quite straight forward.

So I ended up just typing my desired DNS server adress into resolv.conf anyway (I’m using one from Google now), and then making the file immutable, meaning no one can change it any more:

In /etc/resolv.conf:

nameserver 8.8.8.8

And then on the console:

chattr +i /etc/resolv.conf

Now I can access all sites again really quickly.

Posted in Linux | Leave a comment

Setting up Tomcat for remote debugging

If you want to remote-debug a tomcat web application, just add the following to the startup.sh file in the tomcat’s /bin directory

Somewhere near the top of the file, add this:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

At the end of the file, replace the line starting with ‘exec’ by this:
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"

(For windows, the syntax is slightly different, for example ‘set’ instead of ‘export’):

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

Posted in Linux | Leave a comment

Learning from evolving code

Today I discovered a piece of software source code that really inspired me. The structure was beautiful, the relations between objects were well thought out, and the implementation was subtle and very flexible. Wow, I thought, that was a master at work.
Luckily, I had the code repository in front of me, so I peeked at the revision history to find out who made that software. And that’s were the learning began. This guy not only produced nice code, he also had a great revision history, with neat comments for every change he had made over time. And those comments really got me interested. As far as I could see, there were a lot of design decisions along the revisions. Looking at the first revision, I saw a completely different setup from what it like now. And to be honest, the original looked quite crude! So I started to drill down through the evolution process of the code, and boy was that worth it. I plowed through about two dozen iterations of changes, each of which made the design a little more subtle, a little better. Changes were made and then discarted again. Relations were made and remade. It was like a tour in software design. It was like a novel that you can’t put down until you know how it’s going to turn out. Here was a guy who really dove in again and again, aiming to make the code better. Very cool stuff!
So in the end, the complete process that led to the beautiful solution I had initially admired so much was layed out before me. What I learned (or what was once again reaffirmed this way) is that while the end result is often humbling, the process to get there is seldomly straight, and it takes a lot of effort to make a thing great. For me, that’s great motivation whenever I think something is really hard. If you keep at it, it just might turn out to be worth it in the end.

By the way, I later found out that that great programmer was actually a girl. So there you go…

Posted in Technology | Leave a comment

How to drop all tables in a MS-SQL database

Just to remind myself, the following will do a quick job of deleting all tables in the current database. Just open a query window, and execute

exec sp_MSforeachtable "DROP TABLE ? PRINT '? dropped' "

For oracle, execute this:

select 'drop table '||table_name||' cascade constraints;' from user_tables;

and then just execute the output.

Posted in Technology | Leave a comment

Bash programming

Today I got into quite some extensive bash programming for the first time. The reason was that I wanted to automate a task that has been bothering me for some days now: I had set up a new branch for a software project in SVN, and the project structure in the branch is quite different from the one in the trunk.
I want to keep the branch up to date with the trunk, but merging is not really an option, since I have all these tree conflicts now, and I can’t simply resolve them since people are still using the trunk. I expect the trunk to die soon anyway and the new structure to become the trunk. So I am doing something that is not really pretty: I am manually copying the changed trunk files to my branch (which means losing the svn commit messages from the original trunk commits, but I don’t intend to keep this up for more than a few days. I also make nice commit messages including the revision numbers and major changes in the trunk).
Needless to say, this is a dull task, and this was a great opportunity to get into some scripting. So what I ended up with is two scripts, one to pull the svn changes and log them, and another to copy the changed files to my beautiful new branch.

The first script is quite small, and looks like this:


#!/bin/bash

#do an svn up, delete the first line from the output (Revision xxx), cut the start of the lines (D, M...), sort the svn changes, and save the result
svn up | sed -e '/Revision/Id' | sort -k2 > changedfiles.txt
if [[ -s changedfiles.txt ]] ; then
copychanges.sh changedfiles.txt #call the actual copy script with the changes file
mv changedfiles.txt changedfiles.bak
else
echo "Everything is up to date."
fi

This does the “svn up” to get the new files, and pipes the output to sed. Sed deletes the line which says “updated to revision xyz”. After that, it sorts the lines by the filepaths ( using the sort parameter -k2 to sort only by the file paths in column 2, and not by the SVN flags “D,U,A”). Finally, the result is saved to file.
If the file is empty, nothing changed, and I am done. Otherwise, I call the other script (copychanges.sh), which will put the changed files into the corresponding folders in my branch. That script looks like this:


#!/bin/bash
#User provides a file that contains a list of filenames, one per line

#save current stdin
exec 6<&0

# make stdin the file that the user provided, and then read each line in the
# file into an array
exec < $1
numLines=`wc -l < $1`
for i in `seq 1 "$numLines"`
do
read filename
files["$i"]="$filename"
done

#Now that we're done loading the data into the array, restore stdin
exec 0<&6 6<&-

#iterate through the array, asking a question about each file
echo "Processing the following files:"
for file in "${files[@]}"
do
echo $file
done
echo

echo "What is the target directory?"
read targetProject #../datahub-maven

#ask for sourceRoot every time a file has a new prefix
sourceRoot=""

for file in "${files[@]}"
do
echo
status=${file:0:1} #'D' for deleted, 'U' for updated, 'A' for added
file=${file:5}
sourceRootLength=${#sourceRoot}
if [ $sourceRootLength -eq 0 ] || [ "${file:0:$sourceRootLength}" != "$sourceRoot" ]; then
sourceRoot=""
#let the source file be 'src/com/icon/db/util/Bla.java'
until [ -d "$sourceRoot" ]; do # ask until an existing directory has been specified
echo "What is the root for source file $file?"
read sourceRoot #src
if [ ${#sourceRoot} -eq 0 ]; then
break # file is in the root of the hierarchy
fi
done
sourceRootLength=${#sourceRoot}
echo "What is the corresponding target root for $sourceRoot?"
read targetRoot
until [ -d "${targetProject}/${targetRoot}" ]; do # ask until an existing directory has been specified
echo "What is the corresponding target root for $sourceRoot?"
read targetRoot #src/main/java
done
fi

#getting the extension part
fileLength=${#file}
extension=${file:$sourceRootLength:$fileLength} #/com/icon/db/util/Bla.java
echo "Extension: $extension"
targetLocation=${targetProject}/${targetRoot}${extension} #../datahub-maven/src/main/java/com/icon/db/util/Bla.java
#TODO take over the flags from svn, and warn if a modified file does not exist in target, or if an added file already exists
tdir=`exec dirname $targetLocation` # directory name without file
if [ $status == "U" ]; then
read -p "Copy $file to $targetLocation?" -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
cp $file $targetLocation
else echo "Skipped $file"
fi
elif [ $status == "A" ]; then
read -p "Copy $file to $targetLocation?" -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ ! -d "`exec dirname $tdir`" ]; then
echo "Creating new directory $tdir"
mkdir -p "$tdir"
fi
cp $file $targetLocation
else echo "Skipped $file"
fi
elif [ $status == "D" ]; then
read -p "Delete $targetLocation?" -n 1
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm $targetLocation
else echo "Skipped deletion of $targetLocation"
fi
fi
done

Quite a bit longer, but I really learned a lot here.
The problem I have is that I don’t know which files to put where in the new structure. For example, the old project might have a layout like src/java/dbutils/MyDbClass.java
The new project might need this class to be under src/main/java/dbutils/MyDbClass.java
So for each file path, the script asks me what the base path for the file is, and what the corresponding base path is in the branch. For example, the base path in the trunk here would be src, and the corresponding path in the branch is src/main/java. After that, the paths are the same. So the script prompts me once for every different path that appears in the svn log file (that’s why I sorted the output from svn in the other script), and copies the files to their new destination.
So basically you tell the script what the parent directory is in the old and new branch, and the script does the rest. I built in some verifications, like that the parent paths you specify must exist. Additionally, there is some fiddling around with the file names; I need to take them apart and put them back together a bit. But that’s basically it.
What I found out, being more of a java guy, is that it is really hard to remember when to use quotations and the like when comparing variables.
When comparing numbers, you use -eq. If you want to compare strings, you use == . Also, the syntax for finding out things about stings is not really intuitive. It’s short though, I have to admit that.
But all in all, it is not so hard to write some really nifty tools in bash.

Posted in Linux | Leave a comment

Nexus, jenkins, maven and eclipse

In my quest for the perfect build process, I now switched from Artifactory to Nexus as my maven repository. The reason was that I felt artifactory was generating too much overhead. For example, there is an artifactory plugin for jenkins that you don’t really need if you use maven correctly. Also, nexus integrates better with eclipse, since both nexus and maven are sonatype products.
The thing I actually didn’t like the first time I looked at nexus was that now, everything regarding the artifactory has to be in the POM of every project. You have to specify the artifactory urls to deploy to as well as where to get the dependencies — and you have to do this for every single project. This seems like unneeded duplication, since with the jenkins artifactory plugin, I could tell jenkins where to get the repository dependencies, and it would do that for every project. But then again, the projects’ POM files are really the place to store all this stuff, and then everything is definitely in one place, which I guess is better in the long run. Never mind duplication.
Anyway, what confused me in the beginning was how to reference the artifact locations for the different tasks (deployment and dependency resolution). I didn’t get where to put what at first, so here it is after I figured it out:

1. If you have security enabled in nexus, you have to define a server in your .m2/settings.xml to allow maven to get into nexus. Do this like so:

<servers>
<server>
<id>my-nexus</id>
<username>deployment</username>
<password>my-password</password>
</server>
</servers>

Then, in your projects, you add the repositories like this:

<repositories>
<repository>
<id>my-nexus</id>
<name>My Nexus repository</name>
<url>http://localhost:8080/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

And to tell maven where to deploy the projects artifacts to, add this to the POM:

<distributionManagement>
<!-- Publish releases here -->
<repository>
<id>my-nexus</id>
<name>My Nexus repository</name>
<url>http://localhost:8080/nexus/content/repositories/releases</url>
</repository>
<!-- Publish snapshots here -->
<snapshotRepository>
<id>my-nexus</id>
<name>My Nexus repository</name>
<url>http://localhost:8080/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

So the id of the POM repository elements must match the id of the server in your settings.xml file. That’s all really.

Posted in Technology | Leave a comment