From 5914088bd17962047cdd96433fac20636c924d0c Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sat, 11 Jan 2014 12:35:07 +0100 Subject: [PATCH 1/6] autoupdater: fix usage of /lib/ar71xx.sh --- gluon/gluon-autoupdater/files/usr/sbin/autoupdater | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater index b2f0ce7..7db5755 100755 --- a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater +++ b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater @@ -37,7 +37,9 @@ cleanup() { trap cleanup INT TERM EXIT PIPE -my_model="$(cat /tmp/sysinfo/model | sed 's/ /-/g' | tr '[A-Z]' '[a-z]')" +. /lib/ar71xx.sh + +my_model="$(ar71xx_board_name)" case "$my_model" in "tl-wdr4300") From f9ea8e686281528efaaf637c80eb73624bae9526 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sat, 11 Jan 2014 12:38:48 +0100 Subject: [PATCH 2/6] autoupdater: use set -e for safety --- .../files/usr/sbin/autoupdater | 62 ++++++------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater index 7db5755..2f949a9 100755 --- a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater +++ b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater @@ -1,5 +1,8 @@ #!/bin/sh +# abort on error +set -e + if test $(uci get autoupdater.settings.enabled) != 1; then echo "autoupdater is disabled" exit 0 @@ -18,7 +21,8 @@ if test "a$1" != "a-f"; then fi BASE=$(uci get autoupdater.${BRANCH}.url) -PUBKEYS=$(uci get autoupdater.${BRANCH}.pubkey) +# if no signatures are needed, no pubkeys need to be defined, so don't fail +PUBKEYS=$(uci get autoupdater.${BRANCH}.pubkey) || true GOOD_SIGNATURES=$(uci get autoupdater.${BRANCH}.good_signatures) VERSION_FILE=/lib/gluon/release @@ -35,6 +39,11 @@ cleanup() { rm -f $manifest_lower } +fail() { + echo "$@" >&2 + exit 1 +} + trap cleanup INT TERM EXIT PIPE . /lib/ar71xx.sh @@ -51,10 +60,7 @@ case "$my_model" in ;; esac -if [ ! -f "$VERSION_FILE" ]; then - echo "Couldn't determine firmware version!" >&2 - exit 1 -fi +[ -f "$VERSION_FILE" ] || fail "Couldn't determine firmware version!" my_version="$(cat "$VERSION_FILE")" @@ -63,19 +69,10 @@ manifest=$(mktemp) manifest_upper=$(mktemp) manifest_lower=$(mktemp) -wget -O$manifest "$BASE"/manifest +wget -O$manifest "$BASE"/manifest || fail "Couldn't fetch manifest" -if test $? -ne 0; then - echo "Couldn't fetch manifest" >&2 - exit 1 -fi - -seperator_line=$(cat $manifest|grep -n "^---$"|cut -d: -f1|head -n1) - -if test -z "$seperator_line"; then - echo "Couldn't find --- marker!" >&2 - exit 1 -fi +seperator_line=$(cat $manifest|grep -n "^---$"|cut -d: -f1|head -n1) || \ + fail "Could't find --- marker!" head -n$(($seperator_line-1)) $manifest > $manifest_upper tail -n+$(($seperator_line+1)) $manifest > $manifest_lower @@ -94,26 +91,12 @@ for key in $PUBKEYS; do pubkeys="$pubkeys -p $key" done -ecdsaverify -n $GOOD_SIGNATURES $pubkeys $signatures $manifest_upper +ecdsaverify -n $GOOD_SIGNATURES $pubkeys $signatures $manifest_upper || \ + fail "Not enough valid signatures!" -if test $? -ne 0; then - echo "Not enough valid signatures!" >&2 - exit 1 -fi +grep -q "^BRANCH=${BRANCH}$" $manifest_upper || fail "Wrong branch. We'are on ${BRANCH}" -grep -q "^BRANCH=${BRANCH}$" $manifest_upper - -if test $? -ne 0; then - echo "Wrong branch. We'are on ${BRANCH}" >&2 - exit 1 -fi - -my_firmware=$(grep "^${my_model} " $manifest_upper) - -if test $? -ne 0; then - echo "No matching firmware found (model ${my_model})" >&2 - exit 1 -fi +my_firmware=$(grep "^${my_model} " $manifest_upper) || fail "No matching firmware found (model ${my_model})" fw_version=$(echo "${my_firmware}"|cut -d' ' -f2) fw_md5=$(echo "${my_firmware}"|cut -d' ' -f3) @@ -121,16 +104,11 @@ fw_file=$(echo "${my_firmware}"|cut -d' ' -f4) if newer_than "$fw_version" "$my_version"; then echo "New version available" - wget -O$fw_image "${BASE}/${fw_file}" - if test $? -ne 0; then - echo "Error downloading image" >&2 - exit 1 - fi + wget -O$fw_image "${BASE}/${fw_file}" || fail "Error downloading image" image_md5=$(md5sum "$fw_image"|cut -b-32) if test "$image_md5" != "$fw_md5"; then - echo "Invalid image checksum" >&2 - exit 1 + fail "Invalid image checksum" fi echo "Upgrading firmware." From ec5b2adbf1e1fb87cf904479d13f64738602f9dc Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sat, 11 Jan 2014 12:39:10 +0100 Subject: [PATCH 3/6] autoupdater: Use awk instead of grep+head+tail to split manifest --- gluon/gluon-autoupdater/files/usr/sbin/autoupdater | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater index 2f949a9..2821c41 100755 --- a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater +++ b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater @@ -71,11 +71,7 @@ manifest_lower=$(mktemp) wget -O$manifest "$BASE"/manifest || fail "Couldn't fetch manifest" -seperator_line=$(cat $manifest|grep -n "^---$"|cut -d: -f1|head -n1) || \ - fail "Could't find --- marker!" - -head -n$(($seperator_line-1)) $manifest > $manifest_upper -tail -n+$(($seperator_line+1)) $manifest > $manifest_lower +awk 'BEGIN { sep=0 } /^---$/ { sep=1; next } { if(sep==0) print; else print > "'$manifest_lower'" }' $manifest > $manifest_upper signatures="" while read sig; do From 0d01eb472ac965edb94cf82e8104078a9d485189 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sat, 11 Jan 2014 18:00:17 +0100 Subject: [PATCH 4/6] autoupdater: fix usage of set -e --- gluon/gluon-autoupdater/files/usr/sbin/autoupdater | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater index 2821c41..cccf614 100755 --- a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater +++ b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater @@ -13,8 +13,7 @@ BRANCH=$(uci get autoupdater.settings.branch) PROBABILITY=$(uci get autoupdater.${BRANCH}.probability) if test "a$1" != "a-f"; then - echo | awk "END{srand();exit rand() > $PROBABILITY}" - if test $? -ne 0; then + if ! echo | awk "END{srand();exit rand() > $PROBABILITY}"; then echo "No autoupdate this time. Use -f to override" exit 0 fi From bca358bdeeb326572e355bd9dd8f4f3f3c58d64f Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sun, 12 Jan 2014 18:58:41 +0100 Subject: [PATCH 5/6] autoupdater: make cleanup more secure --- gluon/gluon-autoupdater/files/usr/sbin/autoupdater | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater index cccf614..3b3bd25 100755 --- a/gluon/gluon-autoupdater/files/usr/sbin/autoupdater +++ b/gluon/gluon-autoupdater/files/usr/sbin/autoupdater @@ -32,10 +32,10 @@ newer_than() { } cleanup() { - rm -f $manifest - rm -f $fw_image - rm -f $manifest_upper - rm -f $manifest_lower + [ -f "$manifest" ] && rm -f "$manifest" + [ -f "$fw_image" ] && rm -f "$fw_image" + [ -f "$manifest_upper" ] && rm -f "$manifest_upper" + [ -f "$manifest_lower" ] && rm -f "$manifest_lower" } fail() { From 71bf3aba58e2a9ab8772cba982107f88d6397908 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sun, 12 Jan 2014 19:23:59 +0100 Subject: [PATCH 6/6] added gluon-alfred and gluon-alfred-ffmap --- gluon/gluon-alfred-ffmap/Makefile | 32 +++++++++++++++++++ .../files/etc/alfred/ffmap.sh | 21 ++++++++++++ gluon/gluon-alfred/Makefile | 32 +++++++++++++++++++ .../alfred/invariant/010-enable-alfred | 5 +++ 4 files changed, 90 insertions(+) create mode 100644 gluon/gluon-alfred-ffmap/Makefile create mode 100755 gluon/gluon-alfred-ffmap/files/etc/alfred/ffmap.sh create mode 100644 gluon/gluon-alfred/Makefile create mode 100755 gluon/gluon-alfred/files/lib/gluon/upgrade/alfred/invariant/010-enable-alfred diff --git a/gluon/gluon-alfred-ffmap/Makefile b/gluon/gluon-alfred-ffmap/Makefile new file mode 100644 index 0000000..cc3bbc3 --- /dev/null +++ b/gluon/gluon-alfred-ffmap/Makefile @@ -0,0 +1,32 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-alfred-ffmap +PKG_VERSION:=0.1 +PKG_RELEASE:=1.$(GLUON_CONFIG_VERSION) + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/gluon-alfred-ffmap + SECTION:=gluon + CATEGORY:=Gluon + DEPENDS:=+gluon-alfred +gluon-location + TITLE:=Distribute data for ffmap via alfred +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/gluon-alfred-ffmap/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,gluon-alfred-ffmap)) diff --git a/gluon/gluon-alfred-ffmap/files/etc/alfred/ffmap.sh b/gluon/gluon-alfred-ffmap/files/etc/alfred/ffmap.sh new file mode 100755 index 0000000..a79addd --- /dev/null +++ b/gluon/gluon-alfred-ffmap/files/etc/alfred/ffmap.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +if [ -f /lib/functions/jshn.sh ]; then + . /lib/functions/jshn.sh +elif [ -f /usr/share/libubox/jshn.sh ]; then + . /usr/share/libubox/jshn.sh +else + echo "Error: jshn.sh not found!" + exit 1 +fi + +[ -z "$ALFRED_DATA_TYPE" ] && ALFRED_DATA_TYPE=158 + +set -e + +json_init +json_add_string "name" "$(uci get 'system.@system[0].hostname')" +if [ "$(uci get 'system.@system[0].share_location')" = 1 ]; then + json_add_string "gps" "$(uci get 'system.@system[0].latitude') $(uci get 'system.@system[0].longitude')" +fi +json_dump | tr -d '\n' | alfred -s "$ALFRED_DATA_TYPE" diff --git a/gluon/gluon-alfred/Makefile b/gluon/gluon-alfred/Makefile new file mode 100644 index 0000000..c67d920 --- /dev/null +++ b/gluon/gluon-alfred/Makefile @@ -0,0 +1,32 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-alfred +PKG_VERSION:=0.1 +PKG_RELEASE:=1.$(GLUON_CONFIG_VERSION) + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include $(INCLUDE_DIR)/package.mk + +define Package/gluon-alfred + SECTION:=gluon + CATEGORY:=Gluon + DEPENDS:=+alfred +gluon-cron + TITLE:=Configure alfred +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/gluon-alfred/install + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,gluon-alfred)) diff --git a/gluon/gluon-alfred/files/lib/gluon/upgrade/alfred/invariant/010-enable-alfred b/gluon/gluon-alfred/files/lib/gluon/upgrade/alfred/invariant/010-enable-alfred new file mode 100755 index 0000000..20ff5df --- /dev/null +++ b/gluon/gluon-alfred/files/lib/gluon/upgrade/alfred/invariant/010-enable-alfred @@ -0,0 +1,5 @@ +#!/bin/sh + +uci set alfred.alfred.interface=br-client +uci set alfred.alfred.mode=slave +uci delete alfred.alfred.disabled