Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

This repository contains my own implementation of a coding exercise inspired by a public assignment. Canonical is not affiliated with this repository.

Ubuntu Fetcher

Ubuntu Fetcher is a cross-platform C++17 CLI utility that queries Canonical's Simplestreams JSON feed to retrieve Ubuntu cloud image information.

It extracts and displays:

  • All available Ubuntu releases
  • The current Ubuntu LTS version
  • The SHA256 hash of the disk1.img for a given release

✨ Features

  • Written in C++17
  • Uses libcurl for HTTP downloads
  • Uses nlohmann::json for JSON parsing (header-only)
  • Implements local caching (via cache.json) valid for 1 hour
  • Download is performed asynchronously in the background using std::async
  • Fully portable: builds on Linux, macOS, and Windows (via CMake)

🔧 Build Instructions

📦 Dependencies

  • C++17 compiler (e.g. g++ >= 9, clang >= 10, or MSVC >= 2019)
  • CMake ≥ 3.14
  • libcurl development package
  • Note: nlohmann::json is already vendored in libs/json/json.hpp.

No additional installations are required for the JSON library.

On Ubuntu/Debian-based systems:

sudo apt update
sudo apt install build-essential cmake libcurl4-openssl-dev

On Windows:

  • Use Visual Studio 2019 (or later) which supports C++17.

  • CMake can be downloaded and installed.

  • libcurl can be installed via vcpkg or downloaded precompiled.

    For example, with vcpkg:

    vcpkg install curl

🛠️ Build

Clone the repository (or use your local copy) and then:

git clone https://github.com/kenhero/ubuntu-fetcher.git
cd ubuntu-fetcher
mkdir build && cd build
cmake ..
make

The binary will be located in ./build/bin/ubuntu_fetcher.


🚀 Usage

Run the executable from the terminal with one of the following options:

./ubuntu_fetcher --list             # List all supported Ubuntu releases
./ubuntu_fetcher --lts              # Display the current Ubuntu LTS version
./ubuntu_fetcher --sha256 22.04     # Get the SHA256 of disk1.img for a given release

**Examples**

```bash
$ ./ubuntu_fetcher --lts
22.04 LTS (Jammy Jellyfish)

$ ./ubuntu_fetcher --sha256 22.04
SHA256(disk1.img) = 4f3a...9bd2
  • The first run downloads metadata from:
    https://cloud-images.ubuntu.com/releases/streams/v1/com.ubuntu.cloud:released:download.json
    
  • The metadata is cached to ./cache.json for 1 hour.
  • A background task updates the cache after startup.

📁 Project Structure

.
├── include/
│   ├── UbuntuImageFetcher.h              # Abstract interface
│   └── SimplestreamsUbuntuFetcher.h      # Main implementation
├── src/
│   ├── main.cpp                          # CLI entry point
│   └── SimplestreamsUbuntuFetcher.cpp    # Implementation with async download and caching
├── libs/
│   └── json/
│       └── json.hpp                      # nlohmann::json (header-only)
├── CMakeLists.txt
├── README.md
├── LICENSE
└── cache.json                            # (generated; ignored via .gitignore)

🔃 Helper Scripts

This project includes convenience scripts for building, running, and testing:

▶️ build.sh

Builds the entire project from scratch:

./build.sh

🚀 run.sh

Runs the executable with custom CLI arguments:

./run.sh --list
./run.sh --sha256 22.04

🧪 test.sh

Executes a basic smoke test suite:

./test.sh

Each script performs checks to ensure the executable exists and prints relevant output to the console. The three scripts are optional and require that libcurl be installed on your system.

✅ Notes

  • Only the amd64 architecture is supported in this implementation, according to the assignment requirements.
  • The CLI is minimal, using argc/argv for option parsing.
  • The program uses asynchronous background updating and local caching to provide a responsive UX.
  • This project is intended for submission as part of the Multipass C++ Engineer Technical Assessment at Canonical.
  • If the download fails, the tool automatically uses the local cache if present and not expired (≤ 1 hour).

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


Additional Notes for Windows/macOS Developers

  • Windows: Ensure that CMake generates a Visual Studio solution. You may need to configure vcpkg integration to link against libcurl.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages