Script to deploy firmware to device using ethernet ipv6



  • #!/bin/sh

    while getopts "d:p:" opt;
    do
    case "${opt}" in
    d) device=${OPTARG};;
    p) pass=${OPTARG};;
    esac
    done

    if [ -z "$device" ]
    then
    echo "Ethernet device not set, use parameter -d <device>"
    exit 1;
    fi

    address=$(ping6 -c 1 -i 4 -I $device ff02::1 | grep "64 bytes from " | awk '{print $4}' | cut -d"%" -f1 | awk -F':' '{print $0}')

    if [ -z "$address" ]
    then
    echo "IP v6 address not set, use parameter -a <address>"
    exit 1;
    fi

    if [ -z "$pass" ]
    then
    echo "Password not set, use parameter -p <password>"
    exit 1;
    fi

    ssh-keygen -f "~/.ssh/known_hosts" -R "$address%$device"

    echo "Sending Firmware to device...\n"
    sshpass -p$pass scp -6 -o StrictHostKeyChecking=no ~/source/bin/targets/ramips/mt76x8/openwrt-ramips-mt76x8-omega2p-squashfs-sysupgrade.bin root@[$address%$device]:/tmp

    echo "Executing firmware update...\n"
    sshpass -p$pass ssh -6 -o StrictHostKeyChecking=no root@$address%$device sysupgrade -n /tmp/openwrt-ramips-mt76x8-omega2p-squashfs-sysupgrade.bin


  • administrators

    @crispyoz Looks interesting, but can you give some context?



  • @Lazar-Demin

    I need to deploy my custom firmware build to my Omega2S+ based devices, but since a new board will not have a wireless connection I need to use the ethernet connection also built into my board. So there is no reliance upon ipv4 address, this script finds the connected ipv6 device, uses scp to transfer the firmware to the device, then executes sysupgrade on the device.


  • Banned

    This post is deleted!


  • @crispyoz said in Script to deploy firmware to device using ethernet ipv6:

    sshpass

    Hi Thanks for you script. Can you tell me how to install sshpass? Please? THk



  • @Paolo-Moro sshpass is installed on your client machine, not on the Omega, so it depends on what OS you are running on your client machine. On Ubuntu you would use the command sudo apt install sshpass, on windows you can use putty as an alternative to sshpass



  • Thanks!!!!! I need to use an ONION OMEGA to setup the other ONION OMEGA!! šŸ™‚
    I need to install sshpass on Onion.

    https://www.devdungeon.com/content/python-ssh-tutorial

    What do you think about?



  • @Paolo-Moro Seems it will achieve the same thing but why not use sshpass?

    opkg install sshpass

    If it is not found then edit /etc/opkg/distfeeds.conf uncomment lines 2 and 5 then run opkg update then opkg install sshpass



  • If you want a version with more features for the same task, there's been omega2flash here for quite a while now šŸ˜‰

    It has some additional features such as:

    • prevents programming the same omega2(s+) twice
    • can handle (early production) omega2s having no ethernet address and fix that.
    • can set the uboot environment (useful place to have per-device info such as hardware version, without the need for different firmware images).
    • can flash extra files (initial data for the jffs overlay) along with the firmware image.
    • can be run in a loop (e.g. as a service) to program any omega2 hardware it finds on the specified ethernet interface. It does so sequentially, but as initiating the firmware update only takes a few seconds, whereas completing the update can take minutes, this amounts to pretty parallel flashing of multiple devices.
    • can run on standard macOS/Linux, but also runs on OpenWrt under ash shell - so a "flasher" device can be built based on any OpenWrt capable device (I have a PC-engines Alix for that).
    • uses expect tool (usually available on macos/linux) to enter ssh password or sshpass on OpenWrt.

    Any comments, input, contributions welcome, it's on github.



  • @luz very interesting. Thank you for the contribution.
    I did the same thing. But with a different logic.

    • Run the "master" board
    • every minute she try, by wifi, to connect to an omega-... connect on ssh (with key accept by default yes) without sshpass.
    • After a successful connection ssh she inject a script that downloads the .bin from a repository on the LAN and starts the sysupgrade.
      (by wifi)

    I tested it with 100pz in 2 houres, all automatic. I can create many masters... and do everything faster.

    But my version is sh + python script

    Onion Omega2+ is the best! ā‚¬ā‚¬ā‚¬



Looks like your connection to Community was lost, please wait while we try to reconnect.