Wednesday 24 July 2013

Getting Apache Ant Working in Cygwin

I've just had some fun setting up Ant under Cygwin.  It all came down to getting the PATHs working correctly when the installed directories had spaces in their names.  The solution was to use cygpath to first shorten into dos format then unix-ify the paths.  e.g.

LONG_PATH=/cygdrive/c/Program\ Files/Java/jdk1.7.0_25/

DOS_PATH=`cygpath -d "$LONG_PATH"`




echo $DOS_PATH
C:\PROGRA~1\Java\JDK17~1.0_2\

UNIX_PATH=`cygpath -u $DOS_PATH`

echo $UNIX_PATH
/cygdrive/c/PROGRA~1/Java/JDK17~1.0_2/

So a one-liner to do the whole lot

UNIX_PATH=`cygpath -u $(cygpath -d "$LONG_PATH")`

Sunday 9 June 2013

SFTP Chroot Setup for Group ScriptCraft Session

For the next Madlab CoderDojo I'm going to try running a group session scripting Minecraft with Javascript using ScriptCraft.  One problem with this is that there will be a room full of kids with laptops that I've never seen before who will need access to the ScriptCraft server to edit Javascript files.  My plan is to use Notepad++ for Windows and TextWrangler for Mac machines, and SFTP over to the server.  In order to restrict any potential damage I'm going to use the SSH server to enforce an SFTP chroot jail.  This is the server side of the setup...
  1. sudo adduser coderdojo
  2. sudo vi /etc/ssh/sshd_config
  3. Add the following to the end of the config file:
    Match User coderdojo
        ChrootDirectory /home/coderdojo
        AllowTCPForwarding no
        X11Forwarding no
        ForceCommand internal-sftp
  4. sudo /etc/init.d/ssh restart
  5. Finally the user's directory needs to be owned by root so:  sudo chown root:root /home/coderdojo
  6. Create a folder on the scriptcraft server for the coderdojo files:  sudo mkdir /home/coderdojo/dojo
  7. sudo chown coderdojo:coderdojo /home/coderdojo/dojo
  8. Now set up a symbolic link from the ScriptCraft plugin directory back to the coderdojo user's directory: sudo ln -s  /home/coderdojo/dojo /home/scriptcraft/bukkit/js-plugins/dojo
  9. sudo chmod a+w /home/coderdojo/dojo

With this setup in place, users can use SFTP to edit files on the ScriptCraft server that are then picked up and run by the ScriptCraft Javascript module.

The instructions I followed for this setup are on the Debian Admin site.

ScriptCraft Server Updated for Latest "classroom" Module

Walter Higgins from ScriptCraft has just added a "classroom" module to ScriptCraft. (Here's what changed on GitHub).  Here are the steps I followed to upgrade the Madlab Miners ScriptCraft server:

  1. Log on to the server as the scriptcraft user
  2. wget http://scriptcraftjs.org/download/2013-06-09/ScriptCraft.jar
  3. Re-attach to the scriptcraft screen session  (screen -r)
  4. Type "stop" at the server prompt, and wait for it to stop (takes several seconds to save the chunks from all the Multiverse worlds)
  5. mv ~/ScriptCraft.jar ~/bukkit/plugins
  6. Restart the server using the bash file: ./startserver.sh
  7. Once the server is up login and check that you can turn on the classroom with: /js classroom.allowScripting(true)
  8. Works like a charm!

Saturday 8 June 2013

Method for Archiving Gmail

My sister-in-law runs a fashion business and as a consequence sends and receives a  lot of big emails.  Even Google Apps for Business' 25GB mail box allowance is used up within a couple of years.  I needed a way to archive emails out of Gmail and on to local storage.  Here's how I do it:

  1. Install the getmail tool.  I'm running it under Cygwin on Windows, but it should run equally well on Linux.  Here are the Cygwin steps:
    1. Run the Cygwin installer and make sure that you have python installed
    2. Make a directory for the getmail install: mkdir getmail
    3. cd getmail
    4. Download the latest release: wget http://pyropus.ca/software/getmail/old-versions/getmail-4.43.0.tar.gz
    5. tar -zxvf getmail-4.43.0.tar.gz
    6.  cd getmail-4.43.0
    7.  python setup.py install
  2. Log into the Gmail web UI of the account you want to archive
  3. Search for the files that you want to archive.  E.g. to find all the files sent or received in 2011 search for:  "before: 2012/01/01 after: 2010/12/31"
  4. Now we need to give all the search results a unique label.  The trick here is that you need to label all the search results not just the first page, so:
    1. In the Gmail web UI click the select "all" check box
    2. When you do this, Gmail will ask "All 20 conversations on this page are selected. Select all conversations that match this search", click on the link to make sure you select all of them
    3. Click on the label icon
    4. Fill something unique in the "Label as:" box, e.g. "Mail2011"
    5. Click the "Create New" link
    6. The "New Label" dialogue box will pop up.  Click "Create"
    7. A warning box will explain that this will affect all conversations in the search.  Click "OK"
    8. Wait a few seconds until the "Loading..." box goes way to give Google time to make all its changes
  5. Next we need to set up a config file that will let you download all the selected emails
    1. First make a new directory for the archive
    2. mkdir emailarchive
    3. cd emailarchive
    4. Then edit a new config file
    5. vi getmail.conf
    6. Adapt my config to your use:
      [retriever]
      type = SimpleIMAPSSLRetriever
      server = imap.gmail.com
      username = user@gmailaccount.com
      password = topsecret
      mailboxes = ("Mail2011",)
      port = 993


      [destination]
      type = Mboxrd
      path = /home/dave/emailarchive/Mail2011.mbox


      [options]
      received = false
      delivered_to = false
      read_all = false
      verbose = 1

  6. The next step is a gotcha, the archive file has to exist before you try to run the getmail program, so do: touch Mail2011.mbox
  7. You are ready to run the program now with:
    getmail --getmaildir /home/dave/emailarchive --rcfile getmail.conf
  8. Some time later you will have all the emails downloaded to a local mbox format mail store
  9. Finally you can now go back into Gmail, select the label you created earlier and delete all the emails.  Note that Gmail won't free up your space until the emails are emptied from your trash folder

If you need instructions on how to read mbox format mail store files take a look at these instructions for several different mail reading clients.

Thanks to Matt Cutts for outlining the general approach to Gmail archiving that I have adapted here.



Monday 20 May 2013

Setting Up ScriptCraft

I've been looking at ScriptCraft as something for us to play with at the next MadLab CoderDojo.  Here are my notes on getting the server running...

(1) First I created a new "scriptcraft" user on the server
(2) I then installed Bukkit.  I'm running the "02110_1.5.2-R0.1" beta version of Bukkit so that the 1.5.2 Minecraft client works
(3) I set up a startserver.sh batch file to hold the commands to start things up
(4) I edited the server.properties file to bind Bukkit to port 25566.  There is the vanilla Minecraft server already running on the standard port 25565
(5) I changed to the plugins directory and pulled down the latest ScriptCraft.jar file


wget http://scriptcraftjs.org/download/2013-03-31/ScriptCraft.jar

(6) I then restarted the server and logged in with the Minecraft client, added my user to ops.txt,  typed

/js up().box('35:15', 4, 9, 1)

...and made myself a nice 2001: A Space Odyssey style monolith.


Saturday 18 May 2013

10 Functions of the Comma

Really useful post about how to use the English comma correctly from Daily Writing Tips.



aptitude Broken in Debian 7.0

Having updated to Debian 7.0, my normal cycle of keeping things up-to-date with aptitude suggested that I install linux-libc-dev.  When I tried to install, things broke saying:

" warning: 'ldconfig' not found in PATH or not executable"

Google initially sent me down the wrong path to a solution to a slightly different problem on the Ubuntu forums.

Taking a moment to actually read the error message, the fix was a simple addition of /sbin and /usr/sbin to my path.  Quite a nice write up of the issue is here.

What I can't explain is why Debian 7.0 removed the sbin directories from my PATH.  It seems to have done it on all the Debian servers I look after.  I can't find any reference to this on the internet.

Saturday 11 May 2013

Upgrading to Debian 7.0 Safety Tip

Note to self: if you are running aptitude to upgrade a Debian version remotely on an unreliable network link then use screen!!!

Saturday 4 May 2013

Friday 3 May 2013

Minecraft 1.5.2 is Out

...here's the change log.  I think I'll be updating the Madlab Miners server on Saturday.

Wednesday 1 May 2013

Minecraft and Minetest Update Permissions Without a Restart

Quick note to self about Minecraft and Minetest server admin tasks.

How to Update Minecraft White-List Without a Restart

This is especially needed to white-list players without shutting down the server:
  1. Make the edits to the server white-list.txt
  2. On the server as an op run "/whitelist reload"
More information can be found on the commands page on the Minecraft wiki.

How to Update the Minetest auth.txt Settings Without a Restart

Similar problem on Minetest: how to change the auth.txt setting on a running server without a restart:
  1. The Minetest wiki page on privileges states that you should NOT edit the auth.txt file while the server is running
  2. Instead us the "/grant <name> <privilege>" command to give a privilege to a player (you need the "privs" privilege to be able to do this
  3. The running server will write out the update to the auth.txt file

Monday 29 April 2013

Raspberry Pi External USB Drive

If you want to use an external USB drive with a Raspberry Pi you need to have a powered USB hub to provide power to the USB drive.  Sounds obvious when you say it out loud!


Friday 19 April 2013

Upgrading to the Latest getmail on Cygwin

I've been trying to get a backup of GMail working on my Windows PC using getmail on Cygwin.  I've run across a couple of problems so I decided to upgrade to the latest version of getmail.  The default install of getmail on cygwin was  4.36.0.  Latest version from the developer was 4.39.1.

Installed a new version like this:

  1. mkdir newgetmail
  2. cd newgetmail
  3. wget http://pyropus.ca/software/getmail/old-versions/getmail-4.39.1.tar.gz
  4.  tar xvf getmail-4.39.1.tar.gz
  5. cd getmail-4.39.1
  6. python setup.py install

Wednesday 17 April 2013

Upgrading Debian Server to Minetest Version 0.4.6

I've just upgraded the Minetest server to version 0.4.6.  This was just a case of following the details in the README file.


For future reference, here are the steps I followed:

  1. wget https://github.com/minetest/minetest/archive/0.4.6.zip
  2. unzip 0.4.6.zip
  3. cd minetest-0.4.6
  4. cd games/
  5. wget https://github.com/minetest/common/archive/0.4.6.zip -O common.zip
  6. unzip common.zip
  7. rm common.zip
  8. mv common-0.4.6 common
  9. wget https://github.com/minetest/minetest_game/archive/0.4.6.zip -O game.zip
  10. unzip game.zip
  11. mv  minetest_game-0.4.6 minetest_game
  12. cd ..
  13. cmake . -DRUN_IN_PLACE=1
  14. make -j2
  15. cd bin
  16. ./minetestserver
 I left all that running in a screen session that I then detached from.  It is working great so far.

Tuesday 16 April 2013

Starting Moving to PowerShell

I've just decided that I should move to using Windows PowerShell rather than batch scripts.  It turns out that it is quite cryptic just to get a script to run.  Here's the web page that I used to figure out how to make PowerShell scripts run from the command line.

Wednesday 10 April 2013

Minetest Super-Flat World Howto

Here's some quick notes on how to create a super-flat world in Minetest.  This works on version 0.4.6 running on Windows.

  1. Download Minetest and unpack the zip file somewhere
  2. From the folder that you've unpacked rename the "minetest.conf.example" file to "minetest.conf"
  3. Edit the minetest.conf file with your favorite text edit (or Notepad)
  4. Find the line that starts "# Mapgen stuff" and create a new line beneath it
  5. Add the following
    mg_flags = flat
  6. Save the edited minetest.conf file
  7. From the unpacked folder go into the "bin" folder and double click "minetest.exe" to start the program
  8. Press "new" to create a new world
  9. Give the world a new name
  10. Choose the type of world you want -- perhaps "build" is the best choice here
  11. Click "Create"
  12. You almost certainly want to tick the "Creative Mode" box so that you have lots of stuff to build with
  13. Choose your new world and click "Play"
  14. You should now be in your super-flat world

Friday 22 March 2013

Getting rdiff-backup to work with Window 7 and Cygwin

I think that rdiff-backup has great potential to fulfil my backup needs.  Its only draw back was that I couldn't get it to work.   More specifically, running under Cygwin on Windows 7, the first backup would work just fine, but then the second backup would fail with directory permission errors.  I posted to the rdiff-backup mailing list asking for help and a guy called Dominic Raferd suggested that the problem might be with the Cygwin permissions.  I decided that a needed to run a test to see if he was correct.

First of all I set up my test case.  I made a new "backup-test" directory and populated it with a single file "test.txt".  I then backed up the folder with:

rdiff-backup -v5 /cygdrive/c/backup-test rdiff@localserver::bu/backup-test

Which as expected worked just fine. Without changing anything I repeated the command:

rdiff-backup -v5 /cygdrive/c/backup-test rdiff@localserver::bu/backup-test

This one failed, as expected, with a python stack-trace complaining about file level permissions.

Dominic Raferd suggested that to fix the issue I needed to change the group in Cygwin of the directory I was backing up.  Here's what I applied:

First I checked in /etc/group to find that the id of the Users group was 545. Next I edited /etc/passwd to set my "primary group" to 545. I then started a new Cygwin shell. I ssh'ed onto the backup server and deleted the backup-test directory. I also deleted and recreated the local backup test directory.

With that all in place, I reran the backup line twice. It failed. Same permissions error on the remote files.

Checking the local directory, I noticed that the backup folder had no access permissions set. I made a brand new folder and sure enough it also had no permissions set.

$ ls -ld /cygdrive/c/test
d---------+ 1 dave None 0 Mar 22 22:11 /cygdrive/c/test

With a bit of Googling, stackoverflow gave me my next lead. As they suggest, I edited /etc/fstab and added this at the end:

none /cygdrive cygdrive binary,noacl,posix=0,user 0 0

I restarted Cygwin, cleaned the folders local and remote, and tried the double backup again.  It worked like a charm!




Saturday 16 March 2013

Using netcat to Test if Minetest Server Network is Okay

I'm busy setting up a demo Minetest server for the Madlab Miners session tomorrow.  The server accepts incoming requests over UDP on port 30000.  I wanted to test my DNS and port-forwarding set up.  I found a really simple example on how to do this using netcat on wikipedia.

On the Minetest server, behind my home router, I  ran the server end:

nc -ul -p 3000

I then logged on to my virtual server on the public internet and connected with:

nc -u minetest.mydomain.com 30000


With both terminals open, whatever I typed into the client end appeared in my server window. The networking is sorted!

Minecraft Server Update Time

It's time to update the minecraft server to version 1.5.  Here are the steps.

  1. Log on to the server and stop the running minecraft
  2. Rename the old server file:
    mv minecraft_server.jar minecraft_server.jar.old
  3. Download the latest jar file:
    wget https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar
  4. Restart the server
  5. Once you are happy it is working you can remove the backed up server jar file

Wednesday 13 March 2013

Minetest

Minetest looks very interesting as a Minecraft alternative.  Here's a very quick comparison.

I'm going to try and get a server up and running for the Madlab Miners session at the Coder Dojo this weekend.

Blogs and Education

#1 son and I went to the Raspberry Pi Jamboree last weekend.  It was collocated with the Education Innovation conference.  We listened to a very inspiring talk about children having their own blogs.  #1 son was sufficiently inspired and now has his own Minecraft related blog.

Wednesday 20 February 2013

Minecraft Wire Tapping

#1 son and I had a great time at the latest Manchester RaspberryPi Jam this weekend. We cracked on with our project to wire tap the network interface in Minecraft. After some fiddling about with the Python socket library we manged to be the man-in-the-middle and see all the traffic going between the Minecraft client and the server. The slightly disappointing fact was that although we could see the first two packets of the protocols handshake, after that all the traffic was encrypted :(.

Anyhow it was interesting to have the RaspberryPi running as a man-in-the-middle without any significant interruptions to the game play. As a next step I think we are going to try and find a third party library to help with the wire tapping. Perhaps MC3P will be worth a look.

Saturday 5 January 2013

Remote Access to Home Router Using SSH Port Forwarding

Here's the problem: I'm going to be at MadLab for the Coder Dojo today and I want to be able to remotely set up new Minecraft servers running on my machine at home. I can SSH in just fine, but to set up a new server I'll need to set up a new port-forwarding rule on my home router. The router is only accessible from within my home LAN.

SSH port-forwarding to the rescue:

At first I thought I could set up a simple local forwarding rule on the server with

ssh dave@myhost.com -L 8080:192.168.1.254:80

It connected fine, and then I tried in the local browser,

http://localhost:8080/

The page returned, but wouldn't let me access the router. It responded with HTTP error of 403 forbidden. Presumably this is because chrome is sending my laptop IP as the source IP.

In order to get round this I tried dynamic SSH forwarding as a SOCKS server:

ssh -C -D 1080 dave@myhost.com

I set up the SOCKS settings in Firefox to proxy port 1080 on local host and...

Bingo! http://192.168.1.254/ in firefox now gave me access to the router's configuration page.


Wednesday 2 January 2013

Rimu Hosting DNS API

Here's the shell script that I'm using on my linux boxes to keep the DNS hosted by Rimu Hosting up to date with any changes to my dynamically allocated IP address from BT.


#!/bin/bash
wget -q -O -  -i rimu-dns-urls.txt  > /dev/null


The idea is to have a text file of URLs each of which updates the DNS for one address.  The list currently looks like this:

https://rimuhosting.com/dns/dyndns.jsp?host=lego.goopot.co.uk&api_key=MY-SECRET-NUMBER&ttl=300
https://rimuhosting.com/dns/dyndns.jsp?host=lego-wiki.goopot.co.uk&api_key=MY-SECRET-NUMBER&ttl=300


I then set up a one-line crontab entry to run this every five minutes:

*/5 * * * * cd ~dave/code/dynadns; ./dns-rimu.sh