Tuesday, 30 September 2014

Add new lines to end of files with missing line ends

A Sonar rule: Files should contain an empty new line at the end convention
Some tools such as Git work better when files end with an empty line.

To add a new line to all files without one place the following in a file called newlines

FILES="$@"
for f in $FILES
do
c=tail -c 1 $f
if [ "$c" != "" ];
then
echo "$f No new line"
echo "" >> $f
continue
fi
done

Then invoke:

$ chmod +x newlines
$ find * -name *.java |xargs ./newlines

Monday, 1 September 2014

Setting up a mac

Plugin, turn on, update, allow an hour!

Ensure you do not accept the default user details or your admin user will be timpizey not timp.

Install homebrew from http://brew.sh/. Ruby is installed already. This process will install devtools.

Install chrome, font size is under Web Content.

The System Font cannot be altered! The System Font is used by all native Apple applications such as iPhoto and iStore. This is a little annoying (EN_US tr: infuriating and probably illegal). For more general, well written, unix applications the fonts can be altered one by one.

Wednesday, 30 July 2014

How to mount the Nexus 4 storage SD card on Linux systems

Taken from How to mount the Nexus 4 storage SD card on Linux systems and comments there.

Reproduced here so that I can find it again!

Enable Developer Mode

Settings >>‘about phone’ menu and after that you should tap seven times on ‘Build Number’.

Now, from the Developer Options menu enable USB Debugging.

sudo apt-get install mtp-tools mtpfs
sudo gedit /etc/udev/rules.d/51-android.rules

Note not smart quotes as in the article

#LG – Nexus 4
SUBSYSTEM=="usb", ATTR{idVendor}=="1004?, MODE="0666?
sudo chmod +x /etc/udev/rules.d/51-android.rules 
sudo service udev restart
sudo mkdir /media/nexus4
sudo chmod 755 /media/nexus4

Next, connect your Google Nexus 4 to your Ubuntu computer using the USB cable. The MTP option has to be enabled.

sudo mtpfs -o allow_other /media/nexus4

To unmount:

sudo umount /media/nexus4

Friday, 20 June 2014

Rename Selected Jenkins Jobs

Using jenkinsapi it is easy to rename some jobs:

from jenkinsapi.jenkins import Jenkins
J = Jenkins('http://localhost:8080')

for j in J.keys():
  if (j.startswith('bad-prefix')):
    n = j.replace('bad-prefix', 'good-prefix')
    J.rename_job(j, n)

Thursday, 5 June 2014

Multiple git identities

You may wish to keep your work and personal git identities separate but use them both on the same machine.

One way to do this is to use aliases in your ssh and git configs.

Generate a second key and upload it to github.

In ~/.ssh/config

# Opensource github user
Host githubAlias
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_opensource

In the non-default case, Melati in this example, we now use the alias within the project configuration and override user.name and user.email in .git/config:

[core]
 repositoryformatversion = 0
 filemode = true
 bare = false
 logallrefupdates = true

[user]
 email = timp@paneris.org
 name = Tim Pizey

# NOTE use of remote alias defined in ~/.ssh/config
[remote "origin"]
 fetch = +refs/heads/*:refs/remotes/origin/*
 url = git@githubAlias:Melati/Melati.git
[branch "master"]
 remote = origin
 merge = refs/heads/master

Swapping

At some point you will forget or slip up in some other way.

#!/bin/sh
 
git filter-branch --env-filter '
 
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
 
if [ "$GIT_COMMITTER_EMAIL" = "timp@paneris.org" ]
then
    cn="Tim Pizey"
    cm="timp21337@paneris.org"
fi
if [ "$GIT_AUTHOR_EMAIL" = "timp@paneris.org" ]
then
    an="Tim Pizey"
    am="timp21337@paneris.org"
fi
 
export GIT_AUTHOR_NAME="$an"
export GIT_AUTHOR_EMAIL="$am"
export GIT_COMMITTER_NAME="$cn"
export GIT_COMMITTER_EMAIL="$cm"
'
Then git push -f origin master

Friday, 16 May 2014

Using your SSD for caches

You have an SSD mounted on /scratch. Your home directory however is still on the spinning disk.

mv .cache /scratch/home/timp/

In your ~/.xsessionrc:

XDG_CACHE_HOME=/scratch/home/timp/.cache
export XDG_CACHE_HOME

Wednesday, 12 March 2014

Installing and initialising Jenkins JNLP slaves using runit

Run all jobs on slaves

A possible configuration for Jenkins is to run all jobs through JNLP slaves. These can be housed upon the same machine as the master or different machines. The benefit is that the slaves can be run as different users and so cannot overwrite configuration files.

Creating a jnlp slave
mkdir /srv/jenkins-slaves
adduser  --home /srv/jenkins-slaves/jslave jslave
Download http://localhost:21337/jnlpJars/slave.jar to /srv/jenkins-slaves Then as shown on the slave start page:
cd /srv/jenkins-slaves/jslave

java -jar slave.jar -jnlpUrl http://localhost:21337/computer/jnlp/slave-agent.jnlp \
   -secret 96742108603d1c4f19a7fe52133f7410d75a7287f9686d9e97276e3c1eae10d7

This can then be run under runit.

Add the following to /etc/sv/jslave/run

#!/bin/sh
set -e
exec 2>&1
export LANG=en_GB.UTF8
export LANGUAGE=en_GB:en
export LC_ALL=en_GB.UTF8
export HOME=/srv/jenkins-slaves/jslave

cd /srv/jenkins-slaves/jslave
# Secret and url copied from http://localhost:8081/computer/Runner/
chpst -u jslave \
 java -jar slave.jar -jnlpUrl http://localhost:8081/computer/Runner/slave-agent.jnlp \
  -secret 96742108603d1c4f19a7fe52133f7410d75a7287f9686d9e97276e3c1eae10d7

Add the following to /etc/sv/jslave/log/run

#!/bin/bash
set -e
exec svlogd /var/log/jslave

Then add a symlink into /etc/services and start the service:

ln -s /etc/sv/jslave /etc/service/
/usr/bin/sv start /etc/service/jslave

Now jobs can be configured through the Jenkins interface to run only on the slave runner.

You can extend this to many different slaves, each running a different class of job.