Own Updater for Repetier-Server

Normally you want the server to update from the original sources and you have nothing to do. But if you decided to modify the server server to match your printer
or corporal design rules or just do modify the content shown you have to make sure, that only updates happen that are compatible with your modifications. This essentially means
that for every release we publish you have to decide, if you want to give it to your clients. If you want to publish it, you need to test it with your modifications and
eventually modify your modifications and then deliver your modifications along with the new version. In this help page we teach you, how to make your own updater and control what your clients get and what not.

How updating works

As described in our manual, we support up to 3 xml configurations that define the most basic settings of the server. One is reserved for the server installer and gets overwritten on every install. In the other 2 places you can override settings with your options. These will override the original values. In this example we assume a Linux system that has been modified only by adding alternative files in a shadow directory. Therefore we have added a file “/var/lib/Repetier-Server/database/RepetierServer.xml” with the following content:

<server>
    <update-info-url>http://download.repetier-server.com/files/server/MyPrinter/updateinfo.txt</update-info-url>
    <branding>
        <shadow-www-directory>/usr/local/MyPrinter/www/</shadow-www-directory>
        <branded-name>MyCompany</branded-name>
    </branding>
</server>

Here you see 3 things:

  1. The server will not use the normal name, but shows MyCompany instead of Repetier-Server.
  2. It uses a shadow directory at “/usr/local/MyPrinter/www/“.
  3. It queries “http://download.repetier-server.com/files/server/MyPrinter/updateinfo.txt” for updates.

So the custom updater starts with telling the server to use a different location to query for updates. This will query for a simple text file named updateinfo.txt that is stored on your web server. This file needs to follow a strict content guide and looks like this:

0.90.5
http://www.MyCompany.com/download/
http://download1.repetier-server.com/files/server/felix/FelixServer.sh
3
be9c63fa8c9ec0d676a19d4d463b9ea853359318

## New Features

Version 0.92.7
* Added cool function

Line 1 is the version number you can download. ALWAYS use the official version. If the version is higher then the official version you will always see that an update is available.

Line 2 is the URL the user gets send to for manual installation.

Line 3 is the URL of the updater.

Line 4 is the type of updater. 3 means a shell script/executeable to run.

Line 5 is the sha1 checksum of the updater. Only if it matches, the updater gets run.

Line 6-8 are empty and reserved for future uses.

Line 9-xxx Markup of the update message the user will see in the server.

Now if the user sees an update and hits the button for automatic update, the server will start the updater with your config. That will download your update file and verify the checksum. If the checksum matches, it runs the downloaded installer. That’s it.

Sample installer

Now let’s get more concrete and write a working example of an installer. To make it easy to adjust and understand, we show a linux example using a simple bash script. First let me show you the content of it:

#!/bin/bash
DIRECTORY=`dirname ${BASH_SOURCE[0]}`
INSTALLER="$0"
SERVER_FILE=Repetier-Server-0.90.4-Linux.deb
EXTRA_TAR=MyPrinterUpdate.tgz
cd "$DIRECTORY"
DIRECTORY="$( pwd )"
echo "Directory $DIRECTORY"

# Prevent wget from renaming download file by deleting existing files
rm -f ${SERVER_FILE} ${EXTRA_TAR}

# Download compatible version
wget -q http://download.repetier-server.com/files/server/debian-armhf/Repetier-Server-0.90.4-Linux.deb
# Verify that download files are there and correct, otherwise do not start update
if [ ! -e "${SERVER_FILE}" ]; then
    echo "Server image not downloaded."
    exit 1
fi
SERVER_CHECK=$(sha1sum "$SERVER_FILE" |  awk '$1=="f6d25191ee09b4eac7a12f96545d6c1a82eb8a92"{print"good"}')
if [ "${SERVER_CHECK}" != "good" ]; then
		echo "Checksum of server image does not match."
		exit 1
fi
wget -q http://download1.repetier-server.com/files/server/MyPrinter/$EXTRA_TAR
if [ ! -e "${EXTRA_TAR}" ]; then
    echo "$EXTRA_TAR not downloaded."
    exit 1
fi
EXTRA_CHECK=$(sha1sum "$EXTRA_TAR" |  awk '$1=="e012b5184569f5d67e7ffd469f3d2a6b3d6365dc"{print"good"}')
if [ "${EXTRA_CHECK}" != "good" ]; then
		echo "Checksum of $EXTRA_TAR does not match."
		exit 1
fi

# Stop running server
service RepetierServer stop

# Install your own files before updating server
tar -xzf "$DIRECTORY/$EXTRA_TAR" -C /
chown -R repetierserver.dialout /usr/local/Felix
chown -R root.staff /usr/local/Repetier-Setup
chmod a+x /usr/local/Repetier-Setup/bin/*
# Install server
dpkg -i "$SERVER_FILE"
# Cleanup
rm -f ${SERVER_FILE} ${EXTRA_TAR}
rm -f "$INSTALLER"

The idea behind this script is to split the installation into 2 parts. We created a compressed tar file that we can unpack at the root directory. It will automatically put the modified content into the proper places. In addition we also download the official server installer and install this in addition. That way our simple updater just always combines the two parts required to keep the modified version running perfectly.

The sample is made to be safe and easy to edit. All you need to do is change the filenames and the 2 checksums. To make sure only the correct files get updated, we verify the files after download and only run the installation if both files were downloaded without an error.

Notes

  • Provide all files from your server, even the server installer. Our server might be unreachable or we might delete the installer you refer, because we only want to provide updated versions. So better be safe and have your own download for all.
  • Always test the updater before providing it to the general. It is very easy to make a mistake, e.g. wrong checksum somewhere or misspelled download file.
  • If you want to not only provide a latest version, use version numbers also for your update files.
  • Limit output. It seems like updater with much output can hang. Therefore we use the quiet flag in wget.