#!/bin/sh /etc/rc.common
# Copyright (C) 2016 OpenWrt.org

START=45

boot() {
    [ -s /etc/.app_store.id ] && return 0

    mkdir -p /tmp/is-inst/var/lock
    ARCH=`opkg -f /dev/null --offline-root /tmp/is-inst print-architecture | grep -v 'arch all' | grep -v 'arch noarch' | cut -d ' ' -f2`
    rm -rf /tmp/is-inst

    for iface in eth0 br-lan; do
        if [ -e /sys/class/net/$iface/address ]; then
            HASH=`md5sum /sys/class/net/$iface/address | cut -d ' ' -f1`
            break
        fi
    done

    if [ -z "$HASH" ]; then
        HASH=`dd if=/dev/urandom bs=512 count=1 2>/dev/null | md5sum | cut -d ' ' -f1`
    fi

    echo "{\"arch\":\"${ARCH}\", \"uid\":\"${HASH}\"}" > /etc/.app_store.id
}
