Metadata-Version: 2.1
Name: asu
Version: 0.3.0
Summary: Create images for OpenWrt on demand
Home-page: https://github.com/aparcar/asu
Maintainer: Paul Spooren
Maintainer-email: mail@aparcar.org
License: UNKNOWN
Platform: UNKNOWN
Description-Content-Type: text/markdown
Requires-Dist: Click (==7.0)
Requires-Dist: Flask-Cors (==3.0.8)
Requires-Dist: Flask (==1.1.1)
Requires-Dist: Jinja2 (==2.11.1)
Requires-Dist: MarkupSafe (==1.1.1)
Requires-Dist: PyNaCl (==1.3.0)
Requires-Dist: Werkzeug (==1.0.0)
Requires-Dist: cffi (==1.14.0)
Requires-Dist: itsdangerous (==1.1.0)
Requires-Dist: pycparser (==2.19)
Requires-Dist: redis (==3.4.1)
Requires-Dist: rq (==1.2.2)
Requires-Dist: six (==1.14.0)

# Attendedsysupgrade Server for OpenWrt (GSoC 2017)

This project intends to simplify the sysupgrade process of devices running
OpenWrt or distributions based on the former like LibreMesh. The provided tools
here offer an easy way to reflash the router with a new version or package
upgrades, without the need of `opkg` installed.

Additionally it offers an API (covered below) to request custom images with any
selection of packages pre-installed, allowing to create firmware images without the need
of setting up a build environment, even from mobile devices.

## Clients

![yafs](misc/yafs.png)

## Server

The server listens to image requests and automatically generate them if the
request was valid. This is done by automatically setting up OpenWrt
ImageBuilders and cache images in a Redis database. This allows to quickly
respond to requests without rebuilding existing images again.

### Active server

-   [chef.libremesh.org](https://chef.libremesh.org)

## Run your own server

Redis is required to store image requests:

    sudo apt install redis-server tar

Create a Python virtual environment and install the dependencies:

    python3 -m venv .
    source bin/activate
    pip install -r requirements.txt

Start the server via the following commands:

    export FLASK_APP=asu  # set Flask app to asu
    flask janitor init    # download upstream profiles/packages
    flask run             # run development server

Start the worker via the following comand:

    rq worker

Be sure that in both cases the virtual envorinment is active.

## API

### Upgrade check `/api/versions`

The server does no longer offer complex upgrade but only serves static JSON
files including available versions. For now the client must evaluate if the
responded JSON contains a newer version.

### Build request `/api/build`

| key        | value                 | information                              |
| ---------- | --------------------- | ---------------------------------------- |
| `version`  | `SNAPSHOT`            | installed version                        |
| `profile`  | `netgear_wndr4300-v2` | `board_name` of `ubus call system board` |
| `packages` | `["luci", "vim"]`     | Extra packages for the new image         |

### Response `status 200`

```
{
  "bin_dir": "SNAPSHOT/ramips/mt7620/alfa-network_tube-e4g/689292a5569f",
  "build_at": "Mon, 24 Feb 2020 00:00:02 GMT",
  "buildlog": true,
  "enqueued_at": "Sun, 23 Feb 2020 23:59:13 GMT",
  "id": "alfa-network_tube-e4g",
  "image_prefix": "openwrt-689292a5569f-ramips-mt7620-alfa-network_tube-e4g",
  "images": [
    {
      "name": "openwrt-689292a5569f-ramips-mt7620-alfa-network_tube-e4g-squashfs-sysupgrade.bin",
      "sha256": "c14ffd501c8839d737504acf17285a519916830c8df6ca7d281596563c846d1e",
      "type": "sysupgrade"
    }
  ],
  "metadata_version": 1,
  "supported_devices": [
    "alfa-network,tube-e4g"
  ],
  "target": "ramips/mt7620",
  "titles": [
    {
      "model": "Tube-E4G",
      "vendor": "ALFA Network"
    }
  ],
  "version_commit": "r12288-1173719817",
  "version_number": "SNAPSHOT"
}

```

| key        | information                         |
| ---------- | ----------------------------------- |
| `bin_dir`  | relative path to created files      |
| `buildlog` | boolean if buildlog.txt was created |

### Response status codes

The client should check the status code:

| status | meaning                              | information                          |
| ------ | ------------------------------------ | ------------------------------------ |
| `200`  | build finish / upgrade available     | see parameters above                 |
| `202`  | building, queued, imagebuilder setup | building right now or in build queue |
| `400`  | bad request                          | see `error` parameter                |
| `422`  | unknown package                      | unknown package in request           |
| `500`  | build failed                         | see `log` for build log              |


