Howto – Install a Git integrated TFTP server

Abstract:

In a lot of technical environments there is the need for a Trivial File Transfer Protocol, or in short, TFTP server. TFTP is a simpel file transfer protocol that is readily used to boot systems over a network, or to upload or download configuration files from systems as routers, switches, firewalls, and so on …

The installation procedure of the below tftp server was performed on a Debian Stretch system with tftp-hpa as the daemon. The daemon would allow read and write operations. Subsequently, a Git script is installed as a systemd service to auto commit changes to a Git repository for history purposes. An instance of Gitlab was used as the Git server to store the Git repository.

TFTP Daemon Configuration

$ apt-get install -y tftpd-hpa
$ vi /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftproot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--create --secure --blocksize 1468"

Install gitwatch and initialize git repository:

Gitwatch will make use of the inotify-tools package, which will notify the Gitwatch script when there is any file change.

$ sudo apt install -y git
$ sudo apt install -y inotify-tools
$ git clone https://github.com/nevik/gitwatch.git
$ cd gitwatch/
$ sudo install -b gitwatch.sh /usr/local/bin/gitwatch
$ cd /srv/tftproot

First create a git repository in Gitlab, and note the url from your repository. Thereafter, create a Gitlab personal access token, this is required to access the repository later on.

$ git clone https://mygitlab.myhome.com/mysmartproject.git /srv/tftproot
$ git config --global credential.helper store /root/.git-credentials
# -- enter 'git' as username, and your token as the password
$ git pull

Install gitwatch as a service:

$ sudo vi /etc/systemd/system/gitwatch.service
[Unit]
Description=Watch file or directory and git commit all changes
After=network.target

[Service]
User=root
ExecStart=/usr/local/bin/gitwatch -r origin -b master /srv/tftproot
ExecStop=/bin/true

[Install]
WantedBy=multi-user.target
$ sudo chmod 755 /etc/systemd/system/gitwatch.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable gitwatch.service
$ sudo systemctl start gitwatch service
Advertisement

Published by

Ronny Van den Broeck

I'm a network and system engineer for more than 20 years now. During this period I became a pro in hunting down one's and zero's, with an eager mindset to help people accomplish the same or abstract them away from the matrix.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s