Skip to content

Instantly share code, notes, and snippets.

@selankon
Last active May 5, 2024 14:20
Show Gist options
  • Select an option

  • Save selankon/067d748c59b8bddd2926e543d5ddfc28 to your computer and use it in GitHub Desktop.

Select an option

Save selankon/067d748c59b8bddd2926e543d5ddfc28 to your computer and use it in GitHub Desktop.
Lime packages utils
#!/bin/bash
# Description
# This scripts modify the mastertest.lua file to use the IP address of the interface provided as an argument
# It also creates a json file with the latest firmware information with the IP address of the interface provided as an argument
# Board name of the json file
BOARD_NAME="librerouter-librerouter-v1"
#BOARD_NAME="hilink-hlk-7621a-evb"
# IMG SUM write on the JSON file
IMG_SUM="78e176785975a6e8624258b95d98cd27f77550d7222cfeaf4b82482b14104262"
# Image name write on the JSON file
REPO_IMAGE="librerouteros_23_05_snapshot_r1+1_48c81b80b2_ath79_generic_librerouter.bin"
#REPO_IMAGE="librerouteros-23.05-82e2d34-ramips-squashfs-sysupgrade.bin"
# Version of the OS that is wrote on the JSON
VERSION="LibreRouterOs 1.6"
# Repo name on the folder
REPO_NAME="librerouteros_javi"
# Where to write the new JSON file
LATEST_DEST="../firmware-repository/$REPO_NAME/latest/$BOARD_NAME.json"
# Master test file that is going to be executed on the router which sets de repository
MASTER_TEST_FILE="packages/lime-mesh-upgrade/files/usr/lib/lua/mastertest.lua"
# Port of the local repository server
PORT=":8081"
# Check if at least one argument is provided
if [ $# -eq 0 ]; then
echo "Use: <enable-wan-iface ex:wlan0>"
exit 1
fi
node_id=$1
# Modify mastertest.lua with the correct interface
# Get the IP address
IP=$(ip -4 addr show $node_id | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
# Check if the IP was found
if [ -z "$IP" ]; then
echo "No IP address found for interface $node_id"
exit 1
fi
echo "IP address of $node_id is: $IP"
# Delete the line containing 'local ip = "'
sed -i '/local repository = "/d' "$MASTER_TEST_FILE"
local_repository_url="$IP$PORT"
# Add new line with the current value of IP
sed -i "1s/^/local repository = \"http:\/\/$local_repository_url\/\"\n/" "$MASTER_TEST_FILE"
json_latest=$(cat <<EOF
{
"metadata-version": 1,
"images": [
{
"name": "firmware.bin",
"type": "sysupgrade",
"download-urls": [
"http://$local_repository_url/$REPO_IMAGE"
],
"sha256": "$IMG_SUM"
}
],
"board": "test-board",
"version": "$VERSION",
"release-info-url": "https://foro.librerouter.org/t/lanzamiento-librerouteros-1-5/337"
}
EOF
)
echo "$json_latest" > $LATEST_DEST
#python3 -m http.server 8081
#!/usr/bin/env bash
# Just helper to run qemu_dev_start command
# First arg is the node id, like 0 or 1
# If an interface is specified as second argument, it is used with --enable-wan command
# Check if at least one argument is provided
if [ $# -eq 0 ]; then
echo "Use: <node-id> <enable-wan-iface ex:wlan0>"
exit 1
fi
node_id=$1
enable_wan=""
# Check if a second argument is provided
if [ $# -ge 2 ]; then
# Append the second argument as an option to the command
enable_wan="--enable-wan $2"
fi
sudo ./tools/qemu_dev_start --verbose --node-id $node_id $enable_wan \
--libremesh-workdir . \
../qemu/ow23/libremesh-master-ow23-default-x86-64-generic-rootfs.tar.gz \
../qemu/ow23/libremesh-master-ow23-default-x86-64-generic-initramfs-kernel.bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment