9/29/2014

Using gcc48 to build ports on FreeBSD

cd /usr/ports/devel/binutils && make install
cd /usr/ports/lang/gcc48 && make install
Add this to /etc/make.conf:

.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc48)
.if empty(.CURDIR:M/usr/ports/net/openldap*) && empty(.CURDIR:M/usr/ports/xxx/yyy)
CC=gcc48
CXX=g++48
CPP=cpp48
CFLAGS+=-Ofast -fno-strict-aliasing -pipe  
CPUTYPE=corei7
.endif
.endif

Edit /etc/libmap.conf:
libgcc_s.so.1   gcc48/libgcc_s.so.1
libgomp.so.1    gcc48/libgomp.so.1
libobjc.so.3    gcc48/libobjc.so.2
libssp.so.0     gcc48/libssp.so.0
libstdc++.so.6  gcc48/libstdc++.so.6

References:
https://www.freebsd.org/doc/en/articles/custom-gcc/article.html

9/18/2014

Building and installing Apache Maven 3.0.5 from sources


cd ~/tools
wget http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.0.5/apache-maven-3.0.5-src.tar.gz
tar xvzf apache-maven-3.0.5-src.tar.gz
cd apache-maven-3.0.5
#for the next line to succeed, you need a binary maven version in the path
mvn clean install -DskipTests
cd ..
tar xvzf apache-maven-3.0.5/apache-maven/target/apache-maven-3.0.5-bin.tar.gz

9/10/2014

Regenerate hinting for all fonts

First you have to install TTF Autohinter.
sudo apt-get install libtool automake autoconf qt4-qmake automoc imagemagick inkscape pandoc help2man
cd ~/tools
git clone http://repo.or.cz/ttfautohint.git
cd ttfautohint/
./bootstrap
./configure --with-doc=no
make
make install
Under Ubuntu 12.04, you will need to download and compile harfbuzz:
wget http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-0.9.26.tar.bz2
tar xf harfbuzz-0.9.26.tar.bz2
cd harfbuzz-0.9.26
./configure && make && sudo make install
sudo ldconfig
Under later versions you may try sooner or later
sudo apt-get install harfbuzz
Then it's so simple:
mkdir -p ~/.fonts
for file in $(find /usr -name '*.ttf'); do ttfautohint -c -d -i --hinting-range-min=6 -i $file ~/.fonts/${file##*/}; done
fc-cache -fv

9/09/2014

Installing Nexus OSS from sources

After all it's not that tricky. Build fails with Maven 3.0.x, make sure to use a later version, 3.2.3 seems to be working fine. You'll also need the http.ssl hacks.

Pre-requisities

You'll need git. Using Ubuntu/Debian, a
sudo apt-get install git
will do, or on FreeBSD you can use
sudo portmaster devel/git
And now the fun part. On FreeBSD, the lines involving maven can be omitted if a version is already installed via ports via a "sudo portmaster devel/maven3"
cd ~/tools
wget http://apache.cu.be/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.tar.gz
tar xvzf apache-maven-3.2.3-bin.tar.gz
ln -s ~/tools/apache-maven-3.2.3 ~/tools/maven
export PATH=~/tools/maven/bin:$PATH

export MAVEN_OPTS="-XX:PermSize=1500m -XX:MaxPermSize=1800m -Xmx4g"
cd ~/dev
git clone https://github.com/sonatype/nexus-oss.git
cd nexus-oss

# if you don't need https just uncomment below 
cat >> etc/org.sonatype.nexus.cfg << FILE_SEPARATOR
application-port-ssl=8443
FILE_SEPARATOR

mvn -Dskip-testsuite -DskipTests -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
sudo unzip -d /opt assemblies/nexus-base-template/target/nexus-base-template-*.zip
sudo ln -s /opt/nexus-base-template-* /opt/nexus

Autostart on Ubuntu/Debian

As of today, the wrapper service we can use in Karaf to autostart things does not work. As a workaround to autostart, create a /etc/init.d/nexus file:
#!/bin/bash

NEXUS_HOME=/opt/nexus

case "$1" in
  start)
    log_begin_msg "Starting Nexus OSS..."
        $NEXUS_HOME/bin/start
    log_end_msg 0
    ;;
  stop)
    log_begin_msg "Shutting down Nexus OSS..."
        $NEXUS_HOME/bin/stop
    log_end_msg 0
    ;;
  *)
  ;;
esac
...and execute this statement:
sudo update-rc.d nexus defaults 98 02

Autostart on FreeBSD

Start by putting the following script to /etc/rc.d/nexus:
#!/bin/sh

. /etc/rc.subr

name="nexus"
start_cmd="\${name}_start"
stop_cmd="\${name}_stop"
export NEXUS_HOME=/opt/nexus
export JAVA_HOME=/usr/local/openjdk7

nexus_start() {
        \$NEXUS_HOME/bin/start
}

nexus_stop() {
        \$NEXUS_HOME/bin/stop
}

load_rc_config \${name}
run_rc_command "\$1"
...and adapt appropriately to your system of course. You'll need to make it executable:
chmod +x /etc/rc.d/nexus

To activate it, you need to add the following to your /etc/rc.conf:
nexus_enable="YES"

If you need this often

If you need to re-do the same thing from time to time in different environments for different projects, you prefer to simplify things. So here is the single-copy-paste-prepared version; the same as above, this time without the explanation, automated.

cat > /etc/rc.d/nexus << FILE_SEPARATOR
#!/bin/sh

. /etc/rc.subr

name="nexus"
start_cmd="\${name}_start"
stop_cmd="\${name}_stop"
export NEXUS_HOME=/opt/nexus
export JAVA_HOME=/usr/local/openjdk7

nexus_start() {
        \$NEXUS_HOME/bin/start
}

nexus_stop() {
        \$NEXUS_HOME/bin/stop
}

load_rc_config \${name}
run_rc_command "\$1"
FILE_SEPARATOR
chmod +x /etc/rc.d/nexus

cat >> /etc/rc.conf << FILE_SEPARATOR
nexus_enable="YES"
FILE_SEPARATOR

service nexus start

Usage

To deploy to the locally installed Nexus, you can
  • - change your pom.xmls to refer to this local nexus for deployment
  • - change your settings.xml use the local nexus for deployment
  • <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                              http://maven.apache.org/xsd/settings-1.0.0.xsd">
    
       <mirrors>
            <mirror>
                <id>nexus</id>
                <name>nexus</name>
                <mirrorOf>external:*</mirrorOf>
                <url>http://127.0.0.1:8081/content/groups/public/</url>
            </mirror>
        </mirrors>
    
        <servers>
            <server>
                <id>jnc</id>
                <username>tomcat</username>
                <privateKey>${user.home}/.ssh/id_rsa</privateKey>
            </server>
            <server>
                <id>nexus</id>
                <username>admin</username>
                <password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
            </server>
            <server>
                <id>snapshots</id>
                <username>admin</username>
                <password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
            </server>
            <server>
                <id>releases</id>
                <username>admin</username>
                <password>{Oen5wNM4lygHMZ9vf+6T5qmsePRcQbWtrc2AWkTrpKg=}</password>
            </server>
        </servers>
    
        <profiles>
            <profile>
                <id>local</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
        <nexus.url>http://127.0.0.1:8081</nexus.url>
                    <repos.public.url>${nexus.url}/content/groups/public</repos.public.url>
                    <repos.release.url>${nexus.url}/content/repositories/releases</repos.release.url>
                    <repos.snapshot.url>${nexus.url}/content/repositories/snapshots</repos.snapshot.url>
                </properties>
                <repositories>
                    <repository>
                        <id>nexus</id>
                        <name>public</name>
                        <url>${repos.public.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </repository>
                    <repository>
                        <id>snapshots</id>
                        <name>snapshots</name>
                        <url>${repos.snapshot.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                        <releases>
                            <enabled>false</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </repository>
                    <repository>
                        <id>releases</id>
                        <name>releases</name>
                        <url>${repos.release.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </repository>
                </repositories>
    
                <pluginRepositories>
                    <pluginRepository>
                        <id>nexus</id>
                        <name>public</name>
                        <url>${repos.public.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </pluginRepository>
                    <pluginRepository>
                        <id>snapshots</id>
                        <name>snapshots</name>
                        <url>${repos.snapshot.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>always</updatePolicy>
                        </snapshots>
                        <releases>
                            <enabled>false</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </pluginRepository>
                    <pluginRepository>
                        <id>releases</id>
                        <name>releases</name>
                        <url>${repos.release.url}</url>
                        <layout>default</layout>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                    </pluginRepository>
                </pluginRepositories>
            </profile>
        </profiles>
    </settings>
    
    
    ...and this goes to settings-security.xml, using the default password for authentication. If following this guide, on your local, firewalled server the default username/password combination might do. Otherwise change your password in nexus and update your settings.xml and settings-security.xml appropriately as described here.
    <settingsSecurity>
      <master>{KFp2s9kTyrcHsy+BT4dooaLri1eMcy+32raBPgydYvw=}</master>
    </settingsSecurity>
    
  • - use the following construct which overrides your default deployment directory:
    mvn clean deploy -DaltDeploymentRepository=nexus::default::http://127.0.0.1:8081/content/repositories/snapshots
    

Possible errors

Using Maven versions earlier than 3.2.3 may yield to the following error:
Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

Fix Java font smoothing on Ubuntu: re-building OpenJDK from sources with Infinality patches

OpenJDK7

First we need to install some pre-requisities:
sudo apt-get install libasound2-dev libcups2-dev libfreetype6-dev gawk g++ libxext-dev libxrender-dev libxtst-dev libfontconfig1-dev mercurial openjdk-6-jdk

export LANG=C ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk-amd64
Getting the sources:
cd ~/tools
mkdir jdk7u60
cd jdk7u60
hg clone http://hg.openjdk.java.net/jdk7u/jdk7u60 forest
cd forest
sh ./get_source.sh
Patching fonts with Infinality:
cd ~
git clone https://gist.github.com/2893461.git
mv 2893461/fontfix.patch ~/tools/jdk7u60/forest/jdk/
cd ~/tools/jdk7u60/forest/jdk/
patch -p1 < fontfix.patch
The actual build:
cd ~/tools/jdk7u60/forest
. jdk/make/jdk_generic_profile.sh
#make ALLOW_DOWNLOADS=true fastdebug_build
make all
Verifying:
build/linux-amd64-fastdebug/j2sdk-image/bin/java -version

In case you get java.lang.RuntimeException: time is more than 10 years from present: 1104530400000

Try this:

cd ~/tools/jdk7u60/forest/jdk/
wget http://hg.openjdk.java.net/jdk7u/jdk7u/jdk/raw-rev/74a70385c21d
patch -p1 < 74a70385c21d

OpenJDK6

sudo apt-get install libasound2-dev libcups2-dev libfreetype6-dev gawk g++ libxext-dev libxrender-dev libxtst-dev libfontconfig1-dev mercurial openjdk-6-jdk libmotif-dev
export LANG=C ALT_BOOTDIR=/usr/lib/jvm/java-6-openjdk-amd64
cd ~/tools
mkdir jdk6
cd jdk6
hg clone http://hg.openjdk.java.net/jdk6/jdk6 forest
cd forest
sh ./get_source.sh
cd ~
git clone https://gist.github.com/2893461.git
mv 2893461/fontfix.patch ~/tools/jdk6/forest/jdk/
rm -rf 2893461
cd ~/tools/jdk6/forest/jdk/
patch -p1 < fontfix.patch
cd ~/tools/jdk6/forest
. jdk/make/jdk_generic_profile.sh
make all

OpenJDK8

cd ~/tools
mkdir jdk8
cd jdk8
hg clone http://hg.openjdk.java.net/jdk8/jdk8 forest
cd forest
sh ./get_source.sh
cd ~
git clone https://gist.github.com/2893461.git
mv 2893461/fontfix.patch ~/tools/jdk8/forest/jdk/
rm -rf 2893461
cd ~/tools/jdk8/forest/jdk/
patch -p1 < fontfix.patch
cd ~/tools/jdk8/forest
chmod +x configure
./configure
make all

Reference:

http://mail-index.netbsd.org/pkgsrc-users/2014/12/30/msg020846.html

9/08/2014

Fix Java font smoothing on FreeBSD: re-building the port tree's OpenJDK from sources with Infinality patches

The current OpenJDK available in FreeBSD's port tree lacks some eye-candy regarding font-rendering capabilities. Since Freetype2 already includes subpixel-rendering support, we just have to patch the JDK. So first we make an "extract patch" (e.g. no compile, only acquiring sources, applying official FreeBSD patches), then we'll patch with the Infinality patches available in the git repo below.

OpenJDK7

cd /usr/ports/java/openjdk7
sudo make extract patch
cd ~
git clone https://gist.github.com/2893461.git
sudo mv 2893461/fontfix.patch /usr/ports/java/openjdk7/work/openjdk/jdk/
cd /usr/ports/java/openjdk7/work/openjdk/jdk/
sudo patch -p1 < fontfix.patch
cd /usr/ports/java/openjdk7/
sudo make install clean

OpenJDK6

cd /usr/ports/java/openjdk6
sudo make extract patch
cd ~
rm -rf 2893461
git clone https://gist.github.com/2893461.git
sudo mv 2893461/fontfix.patch /usr/ports/java/openjdk6/work/jdk/
cd /usr/ports/java/openjdk6/work/jdk/
sudo patch -p1 < fontfix.patch
cd /usr/ports/java/openjdk6/
sudo make install clean
If you already have openjdk7 installed, you'll need to reinstall instead. In this case replace the last line with
sudo make deinstall reinstall clean

9/05/2014

Installing JDK 1.6, JDK 1.7 and JDK 1.8 from binary

You never know which one you need. Obviously if you have the luxury of a package manager, that will be better, especially if the PM supports multiple versions. Here I didn't have root permissions on a PC still I needed all versions; the switch can be made by sim-linking the proper version to ~/tools/jdk. Don't forget to download the files first - can't do wget since we have to accept the license agreement. Here we go:

JDK1.6

mv ~/Downloads/jdk-6u45-linux-x64.bin .
chmod +x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin

JDK1.7

mv ~/Downloads/jdk-7u67-linux-x64.tar.gz ~/tools
tar xvzf jdk-7u67-linux-x64.tar.gz

JDK1.8

mv ~/Downloads/jdk-8u11-linux-x64.tar.gz .
tar xvzf jdk-8u11-linux-x64.tar.gz
If you add ~/tools/jdk/bin to your PATH (via ~/.profile?), here's how touse jdk 1.8 as default:
ln -s ~/tools/jdk1.8.0_11 ~/tools/jdk

Building and installing PostgreSQL 9.3.5 from sources (no sudo needed)

cd ~/dev
wget http://ftp.postgresql.org/pub/source/v9.3.5/postgresql-9.3.5.tar.gz
tar xvzf postgresql-9.3.5.tar.gz
ln -s postgresql-9.3.5 postgresql
cd postgresql-9.3.5/
./configure --without-readline --prefix=$HOME/tools/postgresql
make
make install
~/tools/postgresql/bin/initdb -D ~/tools/postgresql/data
~/tools/postgresql/bin/pg_ctl -D ~/tools/postgresql/data -l ~/tools/postgresql/postgresql.log start
~/tools/postgresql/bin/createdb mydatabasename
To autostart the server, add this to a startup script:
~/tools/postgresql/bin/pg_ctl -D ~/tools/postgresql/data -l ~/tools/postgresql/postgresql.log start

Building and installing Apache Tomcat 7.0 from sources (no sudo needed)

You will need ant though. If you have a package manager and the appropriate rights it's super easy, either "apt-get install ant" on Ubuntu or "portmaster devel/apache-ant" on FreeBSD - or download and put ant to ~/tools. You will also need to update your PATH so that ant can be found.
cd ~/tools
svn co http://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk ~/tools/apache-tomcat-7-sources
cd ~/tools/apache-tomcat-7-sources
ant -Dbase.path=~/tools/apache-tomcat-7-sources/base download-compile
ant -Dbase.path=~/tools/apache-tomcat-7-sources/base deploy
mkdir -p ~/tools/apache-tomcat-7
mv ~/tools/apache-tomcat-7-sources/output/build/* ~/tools/apache-tomcat-7/
ln -s ~/tools/apache-tomcat-7 ~/tools/tomcat
That concludes the installation. In case you need some JDBC drivers and alike (unfortunately Tomcat 7 does not manage our dependencies like Karaf), here is a sample:
cd ~/tools/tomcat/lib/
wget http://repo1.maven.org/maven2/org/hsqldb/hsqldb/2.3.2/hsqldb-2.3.2.jar
wget http://repo1.maven.org/maven2/org/postgresql/postgresql/9.3-1102-jdbc41/postgresql-9.3-1102-jdbc41.jar
wget http://repo1.maven.org/maven2/javax/activation/activation/1.1.1/activation-1.1.1.jar
wget http://repo1.maven.org/maven2/javax/mail/mail/1.5.0-b01/mail-1.5.0-b01.jar
You may need to add this to ~/.profile file:
export JAVA_HOME=$HOME/tools/jdk

Building and installing Apache Karaf from sources (no sudo needed)

Once upon a time I was working for a company where sudo rights weren't given to developers. So I had to spend a significant fraction of my time finding workarounds, how silly is that. The no-sudo-needed series is the result of all these efforts: I've saved the process, so next time it is needed, it's easy to get back to it.

The point here is to be able to install them just by copying and pasting the code below. Things change around us though, so whatever may build today might just stop working tomorrow. Thus I do my best to keep these code snippets up-to-date.

Like today I need Karaf again. Building from source feels very appropriate, so even though I have sudo on my computers since leaving that company, I still keep coming back here for the "easy builds". Today I updated with Karaf 2.3.11, it is currently building in another window. If succeeds, I'll create another snippet for it. If you need it, feel free to get it!

Building Apache Karaf 2.3.11 from sources

wget http://apache.belnet.be/karaf/2.3.11/apache-karaf-2.3.11-src.tar.gz
tar xvzf apache-karaf-2.3.11-src.tar.gz
cd apache-karaf-2.3.11/src
mvn clean install -DskipTests
mv assemblies/apache-karaf/target/apache-karaf-2.3.11.tar.gz ~/tools
cd ~/tools
tar xvzf apache-karaf-2.3.11.tar.gz
ln -s apache-karaf-2.3.11 karaf

Building Apache Karaf 2.3.6 from sources

wget http://apache.belnet.be/karaf/2.3.6/apache-karaf-2.3.6-src.tar.gz
tar xvzf apache-karaf-2.3.6-src.tar.gz
cd apache-karaf-2.3.6/src
mvn clean install -DskipTests
mv assemblies/apache-karaf/target/apache-karaf-2.3.6.tar.gz ~/tools
cd ~/tools
tar xvzf apache-karaf-2.3.6.tar.gz
ln -s apache-karaf-2.3.6 karaf

Building Apache Karaf 4.0 from sources

git clone https://git-wip-us.apache.org/repos/asf/karaf.git
cd karaf
git checkout karaf-4.0.0
# to avoid "Detected JDK Version: 1.6.0-65 is not in the allowed range [1.7,1.9)" on osx, can only build with 1.7
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
mvn clean install -DskipTests

Building Karaf 4.0.10 from sources, checking out given branch only, building with java 1.8 on OSX:

git clone -b karaf-4.0.10 --single-branch https://github.com/apache/karaf.git
cd karaf
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
mvn clean install -DskipTests -DskipITs

Building and installing Apache Karaf 2.2.5 or 2.3.11 from sources (no sudo needed)

In my ~/.m2/settings.xml, I have a separate profile which uses a local Nexus repository as a proxy to all the remotes. It is not active by default, only activated with the -P local switch. Thus please don't update your settings.xml like this if you don't have a local Nexus proxy (and you won't need the "-P local" switch later neither in this case). The relevant part of my settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>local</id>
            <!--<activation>-->
            <!--<activeByDefault>true</activeByDefault>-->
            <!--</activation>-->
            <properties>
                <repos.release.url>http://127.0.0.1:8081/content/groups/public</repos.release.url>
                <repos.snapshot.url>http://127.0.0.1:8081/content/groups/public</repos.snapshot.url>
            </properties>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <name>public</name>
                    <url>http://127.0.0.1:8081/content/groups/public</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <name>snapshots</name>
                    <url>http://127.0.0.1:8081/content/repositories/snapshots</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>false</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </repository>
                <repository>
                    <id>releases</id>
                    <name>releases</name>
                    <url>http://127.0.0.1:8081/content/repositories/releases</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </repository>
            </repositories>

            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <name>public</name>
                    <url>http://127.0.0.1:8081/content/groups/public</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </pluginRepository>
                <pluginRepository>
                    <id>snapshots</id>
                    <name>snapshots</name>
                    <url>http://127.0.0.1:8081/content/repositories/snapshots</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                    <releases>
                        <enabled>false</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </pluginRepository>
                <pluginRepository>
                    <id>releases</id>
                    <name>releases</name>
                    <url>http://127.0.0.1:8081/content/repositories/releases</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                    </releases>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

...and the script for the build for version 2.2.5:
mkdir -p ~/tools
cd ~/tools
wget http://archive.apache.org/dist/karaf/2.2.5/apache-karaf-2.2.5-src.tar.gz
tar xvzf apache-karaf-2.2.5-src.tar.gz
cd apache-karaf-2.2.5/src
mvn clean install -DskipTests -P local
sudo mkdir -p /opt
cd /opt
sudo tar xvzf ~/tools/apache-karaf-2.2.5/src/assemblies/apache-karaf/target/apache-karaf-2.2.5.tar.gz
sudo ln -s apache-karaf-2.2.5 karaf

For version 2.3.11

mkdir -p ~/tools
cd ~/tools
wget http://archive.apache.org/dist/karaf/2.3.11/apache-karaf-2.3.11-src.tar.gz
tar xvzf apache-karaf-2.3.11-src.tar.gz
cd apache-karaf-2.3.11/src
mvn clean install -DskipTests -P local
sudo mkdir -p /opt
cd /opt
sudo tar xvzf ~/tools/apache-karaf-2.3.11/src/assemblies/apache-karaf/target/apache-karaf-2.3.11.tar.gz
sudo ln -s apache-karaf-2.3.11 karaf

Autostart on Ubuntu: to wrap or not to wrap

If you try to install the wrapper to achieve autostart, everything seems to be fine, but the wrapper segfaults on subsequent reboots, at least that's the sad situation on Ubuntu 12.04.5. This used to work before.
Still it has to work, so the workaround is to create a /etc/init.d/karaf script with this content:
#!/bin/bash

KARAF_HOME=/home/neusoft/tools/karaf

case "$1" in
  start)
    log_begin_msg "Starting Karaf..."
        $KARAF_HOME/bin/start
    log_end_msg 0
    ;;
  stop)
    log_begin_msg "Shutting down Karaf..."
        $KARAF_HOME/bin/stop
    log_end_msg 0
    ;;
  *)
  ;;
esac
To register the file with the system
sudo update-rc.d karaf defaults 98 02

Autostart on FreeBSD

Using FreeBSD, autostarting the service is different:

echo 'karaf_enable="YES"' | sudo tee -a /etc/rc.conf > /dev/null

The rc.conf entry will start the script under /etc/rc.d. And the contents of the /etc/rc.d/karaf file:

#!/bin/sh
. /etc/rc.subr
export KARAF_OPTS="-Dkey=value"
start_cmd="karaf_start"
stop_cmd="karaf_stop"
karaf_start() {
        export JAVA_HOME=/usr/local/openjdk7
        /opt/karaf/bin/start
}
karaf_stop() {
        export JAVA_HOME=/usr/local/openjdk7
        /opt/karaf/bin/stop
}
load_rc_config $name
run_rc_command "$1"

Then you just have to make it executable:

sudo chmod +x /etc/rc.d/karaf

Or even make a symbolic link for the ones expect logs to be at standard places:

sudo ln -s /opt/karaf/data/log /var/log/karaf

Gotchas

Building on OSX Yosemite with Apple's JDK 1.6 succeeds, but logging on shows that we have a crippled container:

# features:addurl http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.ipojo.features/1.12.0/org.apache.felix.ipojo.features-1.12.0.xml
# Command not found: features:addurl

Investigating /opt/karaf/data/log/karaf.log shows us the cause of the error:

"Bundle org.apache.karaf.features.command is waiting for dependencies [(objectClass=org.apache.karaf.features.FeaturesService)]"

Installing Oracle JDK 1.7 & setting JAVA_HOME appropriately fixes the problem.

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
...
(rebuild the whole shebang)
...

Building and installing Apache Maven from sources (no sudo needed)

Maven 3.0.3

Maven 3.0.4 is known for it's incompatibilities connecting to self signed certificates, which can be solved by a small patch. If you don't depend on this version, it's even easier not to use the broken version at all. Here's how to build from sources:
mkdir -p ~/tools
cd ~/tools
wget http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.0.3/apache-maven-3.0.3-src.tar.gz
tar xvzf apache-maven-3.0.3-src.tar.gz
cd apache-maven-3.0.3
#for the next line to succeed, you need a binary maven version in the path
mvn clean install -DskipTests
cd ..
tar xvzf apache-maven-3.0.3/apache-maven/target/apache-maven-3.0.3-bin.tar.gz

Maven 3.2.3

mkdir -p ~/tools
cd ~/tools
wget http://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.2.2/apache-maven-3.2.2-src.tar.gz
tar xvzf apache-maven-3.2.2-src.tar.gz
cd apache-maven-3.2.2
#for the next line to succeed, you need a binary maven version in the path
mvn clean install -DskipTests
cd ..
tar xvzf apache-maven-3.2.2/apache-maven/target/apache-maven-3.2.2-bin.tar.gz