3/24/2015

FreeBSD: Consult installed ports' package message to see their requirements after installation

At installation time, ports display their pkg message to warn the user of further configuration. If for any reason you missed it (or just want to be sure you've done all the changes required for your system), you can display the messages for all ports:
pkg info -D -x `pkg query %n` | less
Excerpt of the results:
...
baobab-3.14.1:
bash-4.3.33:
======================================================================

bash requires fdescfs(5) mounted on /dev/fd

If you have not done it yet, please do the following:

        mount -t fdescfs fdesc /dev/fd

To make it permanent, you need the following lines in /etc/fstab:

        fdesc   /dev/fd         fdescfs         rw      0       0

======================================================================
bdftopcf-1.0.4:
bigreqsproto-1.1.2:
binutils-2.25:
bison-2.7.1,1:
...
Here's how to see how many ports you have installed:
pkg info | wc -l
Enjoy!

3/09/2015

IntelliJ Idea live templates: code for singletons

Say you have this class:

public class TerminalTitlebar {
    public void set(String title) {
        System.out.println("\033]0;" + title + "\007");
    }
}

...and you want to introduce code to change this into a singleton easily.

File -> Settings -> Live Templates -> Click + to create a new entry.

Enter i for abbreviation, "singleton instance" or something similar for description, and the code in the "Template text" field:

private static $CLASS_NAME$ instance;
public static $CLASS_NAME$ getInstance() {
    return instance == null ? instance = new $CLASS_NAME$() : instance;
}

Now click "Edit Variables", and change the Expression for CLASS_NAME to "className()", press OK

To tell IntelliJ to use the generated snippet in Java code, click "Change" in the "Applicable in" line, and select Java.

Now type the letter i (this was the abbreviation we used earlier) and press TAB and the magic happens:

public class TerminalTitlebar {
    private static TerminalTitlebar instance;

    public static TerminalTitlebar getInstance() {
        return instance == null ? instance = new TerminalTitlebar() : instance;
    }

    public void set(String title) {
        System.out.println("\033]0;" + title + "\007");
    }
}

Voila, you can use it in any class. Enjoy!


1/19/2015

Automatic logger generation using IntelliJ Idea's Live Templates (use it with log4j, slf4j, commons-logging, etc by changing the template line accordingly)

In IntelliJ Idea, go to File -> Settings -> Live Templates, and click the + sign. Fill in the details: Abbreviation: log Description: log Check "Reformat according to style" will indent the generated line appropriately. Checking "Shorten FQ names" will remove "org.apache.log4j." and replace it with an import. "Template text" is
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger($CLASS_NAME$.class);
Now click "Edit Variables", and in the CLASS_NAME row, enter className() in the Expression column. Open any of your classes, and into a newline under "public class Blah", type "log" and press tab - and the logger line will be created appropriately:
    private static final Logger LOGGER = Logger.getLogger(HSQLSequenceGenerator.class);

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:
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=1900m -Xmx1512m"

cd ~/dev
git clone https://github.com/sonatype/nexus-oss.git
cd nexus-oss
mvn -Dskip-testsuite -DskipTests -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
unzip -d ~/tools/nexus assemblies/nexus-base-template/target/nexus-base-template-*.zip

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=/home/neusoft/tools/nexus/nexus-base-template-3.0.0-SNAPSHOT

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"

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