Cobrador on Nostr: ### Using the image-builder in practice Earlier we explained the ins and outs of ...
### Using the image-builder in practice
Earlier we explained the ins and outs of building packages and images for OpenWRT. Now lets actually build a package rather than just talking about it.
##### Lets clone the image-builder
```
git clone https://github.com/OpenTollGate/tollgate-image-builder.git
```
##### Lets install a tool to interact with blossom servers
```
curl -sSL https://raw.githubusercontent.com/OpenTollGate/tollgate-sdk/refs/heads/main/blossom-installer.sh | sudo bash
```
##### Lets install a python library for interacting with nostr relays
```
pip3 install nostr
```
##### Lets prepare a file containing the keys for these tools
```
cat blossom_secrets.json
{
"servers": [
"https://files.v0l.io/";,
"https://nostr.download/";,
"https://blossom.poster.place/";
],
"relays": [
"wss://orangesync.tech",
"wss://nostr.mom",
"wss://nostr.chaima.info"
],
"secret_key": "nsec[your_secret_key]",
"secret_key_hex": "[hex_version_of_your_secret_key]",
"public_key": "npub[your_public_key]",
"public_key_hex": "[hex_version_of_your_public_key]"
}
```
##### Lets go!
```
./build-firmware gl-mt3000
```
The above script
* downloads the OpenWRT image-builder
* downloads your [custom packages](https://github.com/OpenTollGate/tollgate-image-builder/blob/d4d48ea0df756b3c25aeb0b77201c242a1a789aa/build-firmware#L244-L246) from blossom
* [installs all the packages](https://github.com/OpenTollGate/tollgate-image-builder/blob/d4d48ea0df756b3c25aeb0b77201c242a1a789aa/build-firmware#L267-L275) in an OpenWRT image
> [!Known bug]
> You might get an error saying that the websocket connection to your nostr relays can't be opened. In that case, just abort and run the above command again. It often works on the second try.
> ```
> DEBUG: Error getting event: socket is already closed.
No valid events found for architecture: aarch64_cortex-a53
> ```
> Pull requests welcome..
##### Are you winning?
Eventually you should see the following output. This is the nostr event that your npub just broadcasted to announce that you compiled your custom feed successfully and that your packages are available on this listed blossom servers. Maybe franzap (nprofile…ucf3) has advice on how we can improve this workflow.
```
Number of ids (unique uids + gids) 1
Number of uids 1
unknown (0)
Number of gids 1
unknown (0)
Exportable Squashfs 4.0 filesystem, xz compressed, data block size 262144
compressed data, compressed metadata, compressed fragments,
no xattrs, compressed ids
duplicates are removed
Filesystem size 64302.32 Kbytes (62.80 Mbytes)
24.24% of uncompressed filesystem size (265222.92 Kbytes)
Inode table size 109854 bytes (107.28 Kbytes)
20.87% of uncompressed inode table size (526354 bytes)
Directory table size 140778 bytes (137.48 Kbytes)
38.40% of uncompressed directory table size (366654 bytes)
Number of duplicate files found 494
Number of inodes 16283
Number of files 14440
Number of fragments 371
Number of symbolic links 242
Number of device nodes 1
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 1600
Number of hard-links 0
Number of ids (unique uids + gids) 1
Number of uids 1
unknown (0)
Number of gids 1
unknown (0)
64302+1 records in
64303+0 records out
65846272 bytes (66 MB, 63 MiB) copied, 0.091405 s, 720 MB/s
64302+1 records in
64303+0 records out
65846272 bytes (66 MB, 63 MiB) copied, 0.091405 s, 720 MB/s
/tmp/openwrt-build/openwrt-imagebuilder-23.05.3-mediatek-filogic.Linux-x86_64/staging_dir/host/bin/tar: Option --mtime: Treating date '@1711145382' as 2024-03-22 23:09:42
sysupgrade-glinet_gl-mt3000/
sysupgrade-glinet_gl-mt3000/CONTROL
sysupgrade-glinet_gl-mt3000/kernel
/tmp/openwrt-build/openwrt-imagebuilder-23.05.3-mediatek-filogic.Linux-x86_64/staging_dir/host/bin/tar: Option --mtime: Treating date '@1711145382' as 2024-03-22 23:09:42
sysupgrade-glinet_gl-mt3000/
sysupgrade-glinet_gl-mt3000/CONTROL
sysupgrade-glinet_gl-mt3000/kernel
sysupgrade-glinet_gl-mt3000/root
sysupgrade-glinet_gl-mt3000/root
Calculating checksums...
Calculating checksums...
Build successful! Firmware image created at:
Image size (62.7952
62.7952MB)
/tmp/openwrt-build/openwrt-imagebuilder-23.05.3-mediatek-filogic.Linux-x86_64/bin/targets/mediatek/filogic/openwrt-23.05.3-mediatek-filogic-glinet_gl-mt3000-squashfs-sysupgrade.bin
```
##### How do I install this thing?
Copy the `sysupgrade.bin` file to the `/tmp` directory of your router.
```
scp /tmp/openwrt-build/openwrt-imagebuilder-23.05.3-mediatek-filogic.Linux-x86_64/bin/targets/mediatek/filogic/openwrt-23.05.3-mediatek-filogic-glinet_gl-mt3000-squashfs-sysupgrade.bin root@[routers-ip-address]:/tmp
```
> [!NOTE]
> The `/tmp` directory is part of your device's RAM rather than its (small) flash storage, so it should have a lot of space for such binaries.
Now lets install it
```
sysupgrade -n [your-sysupgrade-file].bin
```
Please leave your router plugged in and give it a minute or two of time to install the new image. It might show up with a new IP address and you will be prompted to delete the old router from your cached `ssh` keys when you try to log in to it.
##### How can you help? #help
* do you know how to make git actions for this?
* we are [struggling](
* have you fixed that bug already?
* please DM us if you have questions or your looking for other ways to contribute
Earlier we explained the ins and outs of building packages and images for OpenWRT. Now lets actually build a package rather than just talking about it.
##### Lets clone the image-builder
```
git clone https://github.com/OpenTollGate/tollgate-image-builder.git
```
##### Lets install a tool to interact with blossom servers
```
curl -sSL https://raw.githubusercontent.com/OpenTollGate/tollgate-sdk/refs/heads/main/blossom-installer.sh | sudo bash
```
##### Lets install a python library for interacting with nostr relays
```
pip3 install nostr
```
##### Lets prepare a file containing the keys for these tools
```
cat blossom_secrets.json
{
"servers": [
"https://files.v0l.io/";,
"https://nostr.download/";,
"https://blossom.poster.place/";
],
"relays": [
"wss://orangesync.tech",
"wss://nostr.mom",
"wss://nostr.chaima.info"
],
"secret_key": "nsec[your_secret_key]",
"secret_key_hex": "[hex_version_of_your_secret_key]",
"public_key": "npub[your_public_key]",
"public_key_hex": "[hex_version_of_your_public_key]"
}
```
##### Lets go!
```
./build-firmware gl-mt3000
```
The above script
* downloads the OpenWRT image-builder
* downloads your [custom packages](https://github.com/OpenTollGate/tollgate-image-builder/blob/d4d48ea0df756b3c25aeb0b77201c242a1a789aa/build-firmware#L244-L246) from blossom
* [installs all the packages](https://github.com/OpenTollGate/tollgate-image-builder/blob/d4d48ea0df756b3c25aeb0b77201c242a1a789aa/build-firmware#L267-L275) in an OpenWRT image
> [!Known bug]
> You might get an error saying that the websocket connection to your nostr relays can't be opened. In that case, just abort and run the above command again. It often works on the second try.
> ```
> DEBUG: Error getting event: socket is already closed.
No valid events found for architecture: aarch64_cortex-a53
> ```
> Pull requests welcome..
##### Are you winning?
Eventually you should see the following output. This is the nostr event that your npub just broadcasted to announce that you compiled your custom feed successfully and that your packages are available on this listed blossom servers. Maybe franzap (nprofile…ucf3) has advice on how we can improve this workflow.
```
Number of ids (unique uids + gids) 1
Number of uids 1
unknown (0)
Number of gids 1
unknown (0)
Exportable Squashfs 4.0 filesystem, xz compressed, data block size 262144
compressed data, compressed metadata, compressed fragments,
no xattrs, compressed ids
duplicates are removed
Filesystem size 64302.32 Kbytes (62.80 Mbytes)
24.24% of uncompressed filesystem size (265222.92 Kbytes)
Inode table size 109854 bytes (107.28 Kbytes)
20.87% of uncompressed inode table size (526354 bytes)
Directory table size 140778 bytes (137.48 Kbytes)
38.40% of uncompressed directory table size (366654 bytes)
Number of duplicate files found 494
Number of inodes 16283
Number of files 14440
Number of fragments 371
Number of symbolic links 242
Number of device nodes 1
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 1600
Number of hard-links 0
Number of ids (unique uids + gids) 1
Number of uids 1
unknown (0)
Number of gids 1
unknown (0)
64302+1 records in
64303+0 records out
65846272 bytes (66 MB, 63 MiB) copied, 0.091405 s, 720 MB/s
64302+1 records in
64303+0 records out
65846272 bytes (66 MB, 63 MiB) copied, 0.091405 s, 720 MB/s
/tmp/openwrt-build/openwrt-imagebuilder-23.05.3-mediatek-filogic.Linux-x86_64/staging_dir/host/bin/tar: Option --mtime: Treating date '@1711145382' as 2024-03-22 23:09:42
sysupgrade-glinet_gl-mt3000/
sysupgrade-glinet_gl-mt3000/CONTROL
sysupgrade-glinet_gl-mt3000/kernel
/tmp/openwrt-build/openwrt-imagebuilder-23.05.3-mediatek-filogic.Linux-x86_64/staging_dir/host/bin/tar: Option --mtime: Treating date '@1711145382' as 2024-03-22 23:09:42
sysupgrade-glinet_gl-mt3000/
sysupgrade-glinet_gl-mt3000/CONTROL
sysupgrade-glinet_gl-mt3000/kernel
sysupgrade-glinet_gl-mt3000/root
sysupgrade-glinet_gl-mt3000/root
Calculating checksums...
Calculating checksums...
Build successful! Firmware image created at:
Image size (62.7952
62.7952MB)
/tmp/openwrt-build/openwrt-imagebuilder-23.05.3-mediatek-filogic.Linux-x86_64/bin/targets/mediatek/filogic/openwrt-23.05.3-mediatek-filogic-glinet_gl-mt3000-squashfs-sysupgrade.bin
```
##### How do I install this thing?
Copy the `sysupgrade.bin` file to the `/tmp` directory of your router.
```
scp /tmp/openwrt-build/openwrt-imagebuilder-23.05.3-mediatek-filogic.Linux-x86_64/bin/targets/mediatek/filogic/openwrt-23.05.3-mediatek-filogic-glinet_gl-mt3000-squashfs-sysupgrade.bin root@[routers-ip-address]:/tmp
```
> [!NOTE]
> The `/tmp` directory is part of your device's RAM rather than its (small) flash storage, so it should have a lot of space for such binaries.
Now lets install it
```
sysupgrade -n [your-sysupgrade-file].bin
```
Please leave your router plugged in and give it a minute or two of time to install the new image. It might show up with a new IP address and you will be prompted to delete the old router from your cached `ssh` keys when you try to log in to it.
##### How can you help? #help
* do you know how to make git actions for this?
* we are [struggling](
) to build images for the `gl-ar300m` target. This might be connected with the fact that there are two similar devices (`gl-ar300m` and `gl-ar300m16`) that don't have the exact same architecturequoting nevent1q…pezm#### Open tasks
- [ ] investigate [support for other devices](https://github.com/OpenTollGate/tollgate-sdk/commit/1a9718556dbe8b6cecc36714d7982986862d27ef) - [testing required](https://nostrudel.ninja/#/n/nevent1qqste4adj6hxshyusg7c98qxx5lnpghpzedr2lpmx4z3z83y4y9wy6qpzpmhxue69uhkummnw3ezumt0d5hsz9thwden5te0dehhxarj9ehhsarj9ejx2a30qyt8wumn8ghj7mmjv9hxwetn09hxxtn5v43kstcrqsqqqqqpqgs04e59dy6q87zzvg868rufut7lc8kqh9w0ej42rxdu3lavkukjapqcjrqnw)
- [x] Builds for both GL-AR300m and GL-MT3000 with [this change](https://github.com/OpenTollGate/custom-nostr-feed/commit/278cf417b3b27298b8b1ea9fc116177dd227eb71#diff-add219057bcf13ad46b272dc8b0b41a32891c92e81acd8f8fcf28837a56eeefa)
- [x] Fixed `GOOS` and `GOARCH`
- [x] ready to add [our other go packages](https://njump.me/nevent1qqsfr7cv90sr7u00k4967yfucce576zc4892dt9qu5j6rpamwjw4xjgppemhxue69uhkummn9ekx7mp0qgswmfau3q22zvunk4etqh97aznddp60rwuq3ghcfnlrn9xnm7vy6xgrqsqqqqqp9vk9a5)
- [x] build all packages from custom feed
- [x] no longer require that the user specifies which package to build as a CLI argument to `build-firmeware`
- [x] Automate [upload to blossom](https://njump.me/nevent1qqsramr2agk02gm7zvefvs4myl9yjlx88mh8f7t69g554xsztad4znspzpmhxue69uhkummnw3ezumt0d5hsyg86u6zkjdqrlppxyrar37y79l0urmqtjh8ue24pnx7gl7ktwtfwsspsgqqqqqqs8vu68v) server
- [x] Facing [issues](https://njump.me/nevent1qqsf8xf4r7td2halxe7kgkppc66jw06tjlmjq8h34uxlxmlp3rlw35spz4mhxue69uhkummnw3ezummcw3ezuer9wchs4f943e) with `sattelite.earth`
- [x] uploads to other public blossom servers fine
- [x] created [events](https://njump.me/nevent1qqs90s57k22ktsf8vcmdks2x030xrxn64h9cctjfh9lpl77n9kqnuqgpzpmhxue69uhkummnw3ezumt0d5hsyg8d577gs99pxwfm2u4stjlw3fkksa83hwqg5tuyel3ejnfalxzdrypsgqqqqqqsn6lf7c) that map commit hashes and binary checksums to blossom servers that store the binaries
- [x] [include all binaries](https://github.com/OpenTollGate/tollgate-image-builder/pull/4) in image
- [x] the binaries are included, but the image seems to be too large sometimes
- [x] figuring out [what the problem is](https://njump.me/nevent1qqsz24ahpxt47c7xv9ehy7kga3qmfed3cjkqljvgslamwnuenmutmmcpzpmhxue69uhkummnw3ezumt0d5hsz9thwden5te0dehhxarj9ehhsarj9ejx2a30qyt8wumn8ghj7mmjv9hxwetn09hxxtn5v43kstcdwre6e) and fixing the user output
- [x] test sysupgrade image on `GL-MT3000`
- [x] Updated `init.d`, waiting for OS upgrade to complete so that I can resolve [this error](https://njump.me/nevent1qqstv0dsr0tvezmuurydelwnzj7n2emjyecg9a0lp8gcuhwft32fnqcpzpmhxue69uhkummnw3ezumt0d5hsz9thwden5te0dehhxarj9ehhsarj9ejx2a30qyt8wumn8ghj7mmjv9hxwetn09hxxtn5v43kstcrae7kt)
- [ ] Test `ipks` on GL-AR300m
- [ ] Perhaps there is an issue with the arch?
`GOOS=linux GOARCH=mips CGO_ENABLED=0 go build -ldflags="-s -w"`
**Confirmed:**
```
root@GL-AR300M:/tmp# opkg install whoami.ipk
Unknown package 'tollgate-module-whoami-go'.
Collected errors:
* pkg_hash_check_unresolved: cannot find dependency golang for tollgate-module-whoami-go
* pkg_hash_fetch_best_installation_candidate: Packages for tollgate-module-whoami-go found, but incompatible with the architectures configured
* opkg_install_cmd: Cannot install package tollgate-module-whoami-go.
```
- [ ] Perhaps [this](nevent1q…mgl2) is progress
- [ ] Generate an image successfully without any of the go stuff
- [ ] Maybe I should have been testing on the router with the external antennas. Maybe these routers [are different](nevent1q…dwpk)..
- [ ] Confirmed the distinction between [nand and nor ](nevent1q…vu8a)seems to be part of the problem.
- [ ] Left off on [these branches](https://njump.me/nevent1qqsf3rsax464heme366h478krauacwtcgy309yeajhyjhu9gu2kqpwgpzpmhxue69uhkummnw3ezumt0d5hsz9thwden5te0dehhxarj9ehhsarj9ejx2a30qyt8wumn8ghj7mmjv9hxwetn09hxxtn5v43kstcq3jxq2)
- [ ] Ensure that the blossom downloader can distinguish between them correctly based on the hashtags
- [ ] Ensure that sysupgrade binaries can be generated for both nor and nand
- [ ] Try installing the ipk files on the router after flashing it with a binary that doesn't contain any go programs yet
- [ ] Install the `whoami` module manually using the ipk - also test with the `relay` module since the changes to `golang.mk` affect both packages, but the changes to the `relay`'s make file only affect the relay
- [ ] Cry and go back to messing with the Makefile in the SDK if that doesn't work. Note that each package has its own Makefile, and
- [ ] Test `ipks` on GL-MT3000
- [ ] test sysupgrade image on `GL-AR300M`
- [ ] Compare with code that worked on previous commit of main
- [ ] Upload OpenWRT image to blossom as well
- [ ] **make captive portal front-end work again & improve new image -- Working on this one**
- [ ] test the install step of makefiles and use that to configure programs
- [ ] would like to switch to [local golang](https://github.com/OpenTollGate/custom-nostr-feed/blob/9cd211abcfc964f26a900c2bdacefa931be4d051/tollgate-module-relay-go/Makefile#L55-L61) for better reproducibility across build environment, branch: `with_golang_feed`
- [ ] would like to start using actions so that we can use this [runner](naddr1qq…aqht)
- [ ] Make installer for `ipk` and `sysupgrade` files from blossom
* have you fixed that bug already?
* please DM us if you have questions or your looking for other ways to contribute