How to install apt-cacher-ng on synology NAS server

2012-06-06 at 23:14:26 | categories: tips, synology

Motivation

I have a few GNU/Linux machines running Debian testing. All of them are of the same arch (amd64) so they need the same packages. Upgrading them was always a bit painful - fetching the same packages several times, so I though about installing some proxy for deb packages. I tried standard squid, but somehow it did not work well for me - perhaps I could not configure it correctly, so I tried apt-cacher-ng and it works great!

I'd like to share here how to make this kind of proxy solution. I use it on Synology DS111 with DSM4.0.

Quick version

If you want it quick I precompiled apt-cacher-ng for DS111 and DSM 4.0 - it should work fine with DS110j, DS210j, DS410j, DS211j, DS411j, DS211, DS411, DS211+ as well.

Installation

  • Create user apt-cacher-ng using web interface and DON'T give him any permissions. The cacher will run as this user. The rest of this instruction assumes you did that and home directory of this user is /volume1/homes/apt-cacher-ng.
  • Get precompiled package, upload to your diskstation.
  • Then login as root and in /etc/passwd change apt-cacher-ng's shell to /bin/sh. It is needed for starting script to start program as this user.
  • Still being root do su - apt-cacher-ng - you should land in his home directory. Unpack the tgz from this location. It will create you few directories: bin - with executable and starting script; etc - with configuration; cache and log - both empty;
  • Create symbolic link to start script: exit back to root (just type exit) and: ln -s /volume1/homes/apt-cacher-ng/bin/start-script.sh /opt/etc/init.d/S86apt-cacher-ng
  • Check it: /opt/etc/init.d/S86apt-cacher-ng start - it should say Starting apt-cacher-ng server: done.. Enjoy!

Not so quick - compile it yourself

Well first of all you need a toolchain for your diskstation. Check on synology webpage what you should get and fetch that. In my case, for DS111 with DSM4.0, it was: gcc421_glibc25_88f6281-GPL.tgz. Unpack it somewhere and set some variables for compilation. I made a little script (env.sh) for that:

#!/bin/sh

TC=PATH_TO_YOUR/arm-none-linux-gnueabi

CC=$TC/bin/arm-none-linux-gnueabi-gcc
CXX=$TC/bin/arm-none-linux-gnueabi-g++
LD=$TC/bin/arm-none-linux-gnueabi-ld 
AR=$TC/bin/arm-none-linux-gnueabi-ar 
RANLIB=$TC/bin/arm-none-linux-gnueabi-ranlib

CFLAGS="-I$TC/include"
LDFLAGS="-L$TC/lib"

export CC CXX LD AR RANLIB CFLAGS LDFLAGS

Execute it like so: . ./env.sh

Time for compilation :-), so download all sources. I used those: apt-cacher-ng-0.7.5, bzip2-1.0.6, zlib-1.2.7. Unpack them somewhere.

zlib

Easy: ./configure (ignore warning and errors); make;

Now you should have libz.a and libz.so*. The other files zlib could complain about are not important here.

Remember this location: export ZLIB_ROOT=`pwd`

bzip2

In Makefile update lines like CC=... with: CC?=gcc AR?=ar RANLIB?=ranlib

After make you should have libbz2.a

Remember this location: export BZIP2_ROOT=`pwd`

apt-cacher-ng

Apply this patch. It will modify the CMakeLists.txt. I must confess here (feeling a bit ashamed ;-)): it is not the best way of doing it. What I did in this cmake file is pretty ugly - see for yourself. However I worked for me :-) and it was possible to compile the program with previously compiled zlib and bzip2 libraries (just type make and you will find binary in build directory). Finally strip the binary, for me it was: ../../../toolchain/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-strip build/apt-cacher-ng.

Now you can fetch the precompiled package from "Quick version", replace binary with your own and follow the rest of the instructions.

I hope this description can save you some time and make your diskstation even more useful. :-)