Debian Packaging: From Source to Repository

Introducing Syspeek: Our Go Project

Build the foundation of Syspeek, a small Go command-line application that displays useful Linux system information.

Introducing Syspeek: Our Go Project

So far, we have explored Debian packages, installed our development tools, and prepared an isolated build environment.

Now it is time to build something.

Throughout this course, we will develop a small command-line application called Syspeek.

Syspeek will display useful information about a Linux system. Once the application is ready, we will package it as a Debian binary package and eventually publish it through our own APT repository.

The application itself will remain intentionally small. Our main objective is not to build a complex system-monitoring tool, but to learn how a real Go application becomes a properly packaged Debian application.

Learning Objectives

By the end of this lesson, you will be able to:

  • Understand the scope of the Syspeek project.
  • Create a new Go module.
  • Organize a minimal Go command-line application.
  • Read basic Linux system information.
  • Build and run the application.
  • Understand how the application will evolve throughout the course.

1. What Are We Building?

Syspeek is a command-line tool that provides a quick overview of a Linux machine.

The final application will support the following information:

Feature Description
Operating system Distribution name and version
Architecture System architecture
CPU Number of available logical CPUs
Memory Total and available memory
Disk Filesystem capacity and available space
JSON output Machine-readable system information
Version Application version

We will implement these features incrementally.

Our first version will only display:

  • Operating system name.
  • System architecture.
  • Number of logical CPUs.
  • Application version.

This gives us a small but functional application to work with.

2. Why Go?

Go is a good choice for this project for several reasons.

Simple compilation

Go produces standalone executable binaries, making it convenient to distribute command-line applications.

Cross-platform support

Go supports several operating systems and architectures. We can build for different targets when needed.

Standard library

We can implement the first version without third-party dependencies.

Straightforward packaging

A compiled Go application can be installed as a regular executable under /usr/bin.

There is also an important packaging consideration: Go applications should generally be built from source using the system’s Go toolchain and properly declared build dependencies.

We will address that when we start writing the Debian packaging metadata.

3. Create the Project Directory

We created a workspace in the previous lessons.

Move into it:

1
2
mkdir -p ~/packaging-lab/syspeek
cd ~/packaging-lab/syspeek

Initialize a new Go module:

1
go mod init example.com/syspeek

This creates a go.mod file.

The module path identifies the Go module. We are using an example domain because this project does not need to be published as a Go module.

Our initial project structure will be:

1
2
3
syspeek/
├── go.mod
└── main.go

4. Write the First Version

Create main.go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main

import (
	"flag"
	"fmt"
	"os"
	"runtime"
	"strings"
)

const version = "0.1.0"

type SystemInfo struct {
	OS           string
	Architecture string
	CPUs         int
}

func readOSName() string {
	data, err := os.ReadFile("/etc/os-release")
	if err != nil {
		return runtime.GOOS
	}

	for _, line := range strings.Split(string(data), "\n") {
		if strings.HasPrefix(line, "PRETTY_NAME=") {
			value := strings.TrimPrefix(line, "PRETTY_NAME=")
			return strings.Trim(value, `"`)
		}
	}

	return runtime.GOOS
}

func getSystemInfo() SystemInfo {
	return SystemInfo{
		OS:           readOSName(),
		Architecture: runtime.GOARCH,
		CPUs:         runtime.NumCPU(),
	}
}

func main() {
	showVersion := flag.Bool(
		"version",
		false,
		"Print application version",
	)

	flag.Parse()

	if *showVersion {
		fmt.Printf("syspeek %s\n", version)
		return
	}

	info := getSystemInfo()

	fmt.Println("Syspeek - System Overview")
	fmt.Println("-------------------------")
	fmt.Printf("Operating System: %s\n", info.OS)
	fmt.Printf("Architecture:     %s\n", info.Architecture)
	fmt.Printf("Logical CPUs:     %d\n", info.CPUs)
}

Let’s examine what we have written.

Reading operating system information

Linux distributions normally provide operating system identification information in:

1
/etc/os-release

This file contains fields such as:

1
2
3
4
NAME="Debian GNU/Linux"
VERSION="13 (trixie)"
PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
ID=debian

Our readOSName function reads this file and looks for PRETTY_NAME.

If the file cannot be read, it falls back to Go’s operating system identifier.

Detecting the architecture

The Go runtime provides:

1
runtime.GOARCH

On a typical 64-bit x86 Linux system, this returns:

1
amd64

Counting logical CPUs

We use:

1
runtime.NumCPU()

This returns the number of logical CPUs available to the Go runtime.

It is a convenient way to obtain basic CPU information without depending on external commands.

Handling command-line flags

The standard flag package allows us to support options without introducing an external dependency.

For now, we have implemented:

1
syspeek --version

We will add more options as the project grows.

5. Build the Application

We can now compile the application:

1
go build -o syspeek .

This creates an executable named syspeek in the current directory.

Check the result:

1
file syspeek

You should see information identifying it as an executable binary.

6. Run Syspeek

Run the application:

1
./syspeek

Example output:

1
2
3
4
5
Syspeek - System Overview
-------------------------
Operating System: Debian GNU/Linux 13 (trixie)
Architecture:     amd64
Logical CPUs:     8

Your actual output will depend on the machine where you run the application.

Now check the version:

1
./syspeek --version

Expected output:

1
syspeek 0.1.0

Congratulations! We now have a working Go command-line application.

7. Inspect the Project

Our project currently contains only two source files and one generated executable.

Inspect the directory:

1
ls -lah

The structure should look similar to:

1
2
3
4
syspeek/
├── go.mod
├── main.go
└── syspeek

The executable is a build artifact. We will not include it as the source of truth for our Debian package.

Instead, the Debian package will be built from the source code.

This distinction is important because Debian packaging should be able to reproduce the application binary using its declared build dependencies.

8. Why We Are Not Using External Dependencies

For this first version, Syspeek uses only the Go standard library.

This is intentional.

A small dependency tree makes the first packaging exercise easier to understand.

Later, we will discuss how Go dependencies are handled in Debian packaging and why downloading arbitrary dependencies during a package build is generally undesirable.

For now, the application has no external Go modules to manage.

9. What We Learned

In this lesson, we introduced Syspeek and created its first working version.

We:

  • Initialized a Go module.
  • Created a command-line application.
  • Read Linux distribution information.
  • Detected the system architecture.
  • Counted logical CPUs.
  • Implemented a version flag.
  • Compiled and executed the application.

We now have a real software project that we can gradually turn into a Debian package.

Exercises

Before moving on, try these exercises:

  1. Run Syspeek on a different Linux distribution and compare the operating system output.
  2. Change the application version to 0.1.1.
  3. Add a field that displays the Go runtime version using runtime.Version().
  4. Run go build again and inspect the resulting executable.
  5. Check whether the application runs without any additional Go dependencies.

What’s Next?

Our first version works, but the project is still very small.

In the next lesson, we will improve its structure and introduce the debian/ directory, which contains the files and instructions required to turn an ordinary software project into a Debian source package.

Next: The Debian Packaging Directory