From b152773f44d99bbf697d0d6fa2e6d67607f8676f Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Tue, 7 Feb 2017 23:12:27 +0200 Subject: [PATCH] initial work on generalized firmware update --- board/common/overlay/etc/os.conf | 5 ++ board/common/overlay/sbin/fwupdate | 54 +++++++++++++++++++ .../usr/libexec/list-versions-bitbucket | 15 ++++++ .../overlay/usr/libexec/list-versions-github | 15 ++++++ package/motioneye/update.py | 2 +- 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 board/common/overlay/sbin/fwupdate create mode 100755 board/common/overlay/usr/libexec/list-versions-bitbucket create mode 100755 board/common/overlay/usr/libexec/list-versions-github diff --git a/board/common/overlay/etc/os.conf b/board/common/overlay/etc/os.conf index 71f84de6e6..0272c71078 100644 --- a/board/common/overlay/etc/os.conf +++ b/board/common/overlay/etc/os.conf @@ -7,3 +7,8 @@ os_ppp="ppp0" os_networkless="false" os_country="US" +os_firmware_method="github" +os_firmware_repo="ccrisan/motioneyeos" +os_firmware_username="" +os_firmware_password="" + diff --git a/board/common/overlay/sbin/fwupdate b/board/common/overlay/sbin/fwupdate new file mode 100644 index 0000000000..566539000f --- /dev/null +++ b/board/common/overlay/sbin/fwupdate @@ -0,0 +1,54 @@ +#!/bin/bash + +function exit_usage() { + echo "Usage: $0 latest" + echo " $0 current" + echo " $0 upgrade " + echo " $0 progress" + + exit -1 +} + +if [ -z "$1" ]; then + exit_usage +fi + +function show_latest() { +} + +function show_current() { +} + +function do_upgrade() { +} + +function show_progress() { +} + + +case "$1" in + latest) + show_latest + ;; + + current) + show_current + ;; + + upgrade) + if [ -z "$2" ]; + exit_usage + fi + + do_upgrade $2 + ;; + + progress) + show_progress + ;; + + *) + exit_usage + ;; +esac + diff --git a/board/common/overlay/usr/libexec/list-versions-bitbucket b/board/common/overlay/usr/libexec/list-versions-bitbucket new file mode 100755 index 0000000000..e2a76eb078 --- /dev/null +++ b/board/common/overlay/usr/libexec/list-versions-bitbucket @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo "Usage: $0 " 1>&2 + exit -1 +fi + +opts="-s -S -f" +test -n "$BITBUCKET_USERNAME" && opts+=" --user $BITBUCKET_USERNAME:$BITBUCKET_PASSWORD" +url=https://api.bitbucket.org/2.0/repositories/$1/downloads?pagelen=100 +jq_expr='.values[] | [{a: .name | capture("[^-]+-(?[^-]+)-(?[^-]+)\\.img\\.?.*"), url: .links.self.href}] | map(.a.c, "false", .a.b, .url) | join("|")' + +curl $opts $url | jq --raw-output "$jq_expr" +exit ${PIPESTATUS[0]} + diff --git a/board/common/overlay/usr/libexec/list-versions-github b/board/common/overlay/usr/libexec/list-versions-github new file mode 100755 index 0000000000..479e0eca67 --- /dev/null +++ b/board/common/overlay/usr/libexec/list-versions-github @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo "Usage: $0 " 1>&2 + exit -1 +fi + +opts="-s -S -f" +test -n "$GITHUB_USERNAME" && opts+=" --user $GITHUB_USERNAME:$GITHUB_PASSWORD" +url=https://api.github.com/repos/$1/releases +jq_expr='.[] | {version: .name, prerelease: .prerelease | tostring, name: .assets[].name | capture("[^-]+-(?[^-]+)") | flatten, asset: .assets[].browser_download_url} | flatten | join("|")' + +curl $opts $url | jq --raw-output "$jq_expr" +exit ${PIPESTATUS[0]} + diff --git a/package/motioneye/update.py b/package/motioneye/update.py index e9fd184b4b..40135b1290 100644 --- a/package/motioneye/update.py +++ b/package/motioneye/update.py @@ -50,7 +50,7 @@ def get_all_versions(): url = _LIST_VERSIONS_URL url += '?_=' + str(int(time.time())) # prevents caching - want_prereleases = subprocess.check_output('source /data/etc/os.conf && echo $os_prereleases', shell=True, stderr=subprocess.STDOUT).strip() == 'true' + want_prereleases = subprocess.check_output('source /data/etc/os.conf && echo $os_prereleases', shell=True, stderr=subprocess.STDOUT).strip() == 'true' try: logging.debug('board is %s' % _BOARD)