diff --git a/.github/workflows/pr-checker.yml b/.github/workflows/pr-checker.yml index 7e76727..e077f2c 100644 --- a/.github/workflows/pr-checker.yml +++ b/.github/workflows/pr-checker.yml @@ -27,6 +27,11 @@ jobs: run: | cd identity-tools/test-cases ./test.sh + - name: Create one developer identity-tools + run: | + cd identity-tools/developer_identity + ./create-dev-identity.sh -h + ./create-dev-identity.sh -d -w CI-test run-pysh-check: runs-on: ubuntu-22.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5297a8b..a13adfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ -## Izuma Edge utilities 2.1.1 +## Izuma Edge utilities 2.2.0 +1. [edge-info] Add support for different localhost:/status ports (snap port `8081`, edge-core only `8080` and LmP `9091`). 1. [edge-info] Removed unused files. +1. [edge-info] Path fixes for snap-pelion-edge information. +1. [edge-testnet] Check also snapcraft.io specific addresses, if running in a snap. +1. [identity-tools/developer_identity] Merge the logging functionality from `common.sh` into `create-dev-identity.sh` (and remove that `common.sh` completely). ## Izuma Edge utilities 2.1.0 1. [edge-info] Rename `info` tool to `edge-info`. Linux already has a command called `info`, so we need to avoid that overlap with names. diff --git a/edge-info/edge-info b/edge-info/edge-info index 98b0f50..7c83cf9 100755 --- a/edge-info/edge-info +++ b/edge-info/edge-info @@ -21,47 +21,82 @@ #---------------Configuration-------------# # No, you cannot export the colors - printing goes crazy if you do that. -NORM="$(tput sgr0)" -BOLD="$(tput bold)" -REV="$(tput smso)" -UND="$(tput smul)" -#BLACK="$(tput setaf 0)" -#RED="$(tput setaf 1)" -GREEN="$(tput setaf 2)" -YELLOW="$(tput setaf 3)" -#BLUE="$(tput setaf 4)" -MAGENTA="$(tput setaf 5)" -CYAN="$(tput setaf 6)" -#WHITE="$(tput setaf 7)" -#ERROR="${REV}Error:${NORM}" -version="2.1.1" +NORM="\u001b[0m" +BOLD="\u001b[1m" +REV="\u001b[7m" +UND="\u001b[4m" +GREEN="\u001b[32m" +YELLOW="\u001b[33m" +MAGENTA="\u001b[35m" +CYAN="\u001b[36m" +version="2.2.0" export LogToTerm=1 loglevel=info; THISMACHINE=$(uname -m) _debug(){ - if [[ $loglevel = "debug" ]]; then + if [[ "$loglevel" = "debug" ]]; then echo "debug: $1" fi } -#This bash program is intended to work on multiple build systems. In yocto/linux micro platform (LMP) we set EDGE_DATA at build time to a user variable (default: /var/rootdirs/userdata) using sed. For other build systems, follow that technique OR add on to the following function to detect your system and set RFILE and IFILE to your desired locations. +# This bash program is intended to work on multiple build systems. +# In yocto/linux micro platform (LMP) we set EDGE_DATA at build time to a user variable +# (default: /var/rootdirs/userdata) using sed. +# For other build systems, follow that technique OR +# add on to the following function to detect your system and set RFILE and IFILE to your desired locations. STORAGE=EDGE_DATA set_storage_locations(){ - if [[ -e "$STORAGE" ]]; then - RFILE="$STORAGE/info/relaystatics.sh" + # We're running in snap - try the /var/snap/pelion-edge + if [[ -n "${SNAP}" ]]; then + IFILE="/var/snap/${SNAP_NAME}/current/userdata/edge_gw_identity/identity.json" + if ! [[ -f "$IFILE" ]]; then + IFILE="$STORAGE/edge_gw_config/identity.json" + fi + elif [[ -e "$STORAGE" ]] && [[ -d "$STORAGE" ]]; then IFILE="$STORAGE/edge_gw_config/identity.json" + # Fallbacks, in case the files cannot be found. + if ! [[ -f "$IFILE" ]]; then + IFILE=/userdata/edge_gw_config/identity.json + fi + if ! [[ -f "$IFILE" ]]; then + IFILE=/edge/etc/identity.json + fi else - RFILE=/userdata/info/relaystatics.sh IFILE=/userdata/edge_gw_config/identity.json + if ! [[ -f "$IFILE" ]]; then + IFILE=/userdata/edge_gw_config/identity.json + fi + if ! [[ -f "$IFILE" ]]; then + IFILE=/edge/etc/identity.json + fi fi - if [ -e /edge/mbed/edge-core ]; then - # edge paths. - BASE_PATH="/edge" + # BASE_PATH is used for finding versions.json and edge-core + if [[ -n "${SNAP}" ]]; then + if [[ -e "${SNAP}/wigwag/mbed/edge-core" ]]; then + BASE_PATH="${SNAP}/wigwag/mbed" + elif [[ -e "${SNAP}/edge/edge-core" ]]; then + BASE_PATH="${SNAP}/edge/" + elif [[ -e "/mbed/edge-core" ]]; then + BASE_PATH="/mbed" + elif [[ -e "/bin/edge-core" ]]; then + BASE_PATH="/bin" + else + # wigwag paths. + BASE_PATH="/wigwag" + fi else - # wigwag paths. - BASE_PATH="/wigwag" + if [ -e /edge/mbed/edge-core ]; then + # edge paths. + BASE_PATH="/edge/mbed" + elif [ -e /bin/edge-core ]; then + # edge paths. + BASE_PATH="/bin/" + else + # wigwag paths. + BASE_PATH="/wigwag" + fi fi } set_storage_locations @@ -117,11 +152,25 @@ set_machine_vars(){ } load_statistics(){ - if [[ -e "$RFILE" ]]; then - # shellcheck disable=SC1090 - source "$RFILE" + # Check if we're running as a snap or not and change port accordingly. + # If env variable SNAP exists, we're running as SNAP. + if [[ -n "${SNAP}" ]]; then + EDGEPORT=8081 + else + # Try if we're on LmP. + EDGEPORT=9101 + EDGECORESTATUS=$(curl -s "localhost:${EDGEPORT}/status") + if [[ -z $(echo "$EDGECORESTATUS" | jq -r '."endpoint-name"') ]]; then + # Must be running on edge-core only then. + EDGEPORT=8080 + EDGECORESTATUS=$(curl -s "localhost:${EDGEPORT}/status") + if [[ -z $(echo "$EDGECORESTATUS" | jq -r '."endpoint-name"') ]]; then + echo "ERROR - can't find localhost:/status, is edge-core running?" + fi + fi fi - EDGECORESTATUS=$(curl -s localhost:9101/status); + + EDGECORESTATUS=$(curl -s localhost:"$EDGEPORT"/status); if [[ $EDGECORESTATUS = "" ]]; then Status="${MAGENTA}offline${NORM}" elif [[ $AccountID = "" ]]; then @@ -140,20 +189,9 @@ load_statistics(){ else Status=$(echo "$EDGECORESTATUS" | jq -r '."status"') fi - if [[ ! -e "$RFILE" && "$URL_gatewayServicesAddress" != "" ]]; then - { - echo "AccountID=\"$AccountID\"" - echo "DID=\"$DID\"" - echo "URL_LWM2Mserver=\"$URL_LWM2Mserver\"" - echo "URL_gatewayServicesAddress=\"$URL_gatewayServicesAddress\"" - echo "URL_edgek8sServicesAddress=\"$URL_edgek8sServicesAddress\"" - echo "URL_containerServicesAddress=\"$URL_containerServicesAddress\"" - } > $RFILE - fi } - _exec(){ local cmd="$1" out=$(eval "$cmd" >> /dev/null 2>&1) @@ -315,9 +353,14 @@ geo(){ } firmware(){ - if [[ -e "${BASE_PATH}/etc/versions.json" ]]; then - currentV=$(grep -ne 'version' ${BASE_PATH}/etc/versions.json 2> /dev/null | xargs | awk -F ' ' '{print $8}') - currentV=${currentV%%,*} + if [[ -n "${SNAP}" ]] ; then + currentV="${SNAP_VERSION}" + elif [[ -e "${BASE_PATH}/etc/versions.json" ]]; then + currentV=$(jq -r ".version" < "${BASE_PATH}/etc/versions.json") + elif [[ -e "${BASE_PATH}/versions.json" ]]; then + currentV=$(jq -r ".version" < "${BASE_PATH}/versions.json") + elif [[ -e "/edge/etc/versions.json" ]]; then + currentV=$(jq -r ".version" < "/edge/etc/versions.json") else currentV="versions.json not available" fi @@ -327,8 +370,8 @@ firmware(){ echo "${NORM}" _placeTitle "Firmware Version Information" _placeLine " - Pelion Edge Version:" "$currentV" - if [[ -e "${BASE_PATH}/mbed/edge-core" ]]; then - _placeLine " - edge-core" "$(${BASE_PATH}/mbed/edge-core -v | awk -F '-' '{print $1}')" + if [[ -e "${BASE_PATH}/edge-core" ]]; then + _placeLine " - edge-core" "$(${BASE_PATH}/edge-core -v | awk -F '-' '{print $1}')" else _placeLine " - edge-core" fi @@ -336,7 +379,15 @@ firmware(){ _placeLine " - OS Version:" "$OSVERSION" _placeLine " - OS Machine:" "$THISMACHINE" _placeLine " - Kernel Version:" "$kernelV" - + if [[ -n ${SNAP} ]]; then + _placeLine " - SNAP:" "${SNAP}" + _placeLine " - SNAP_NAME:" "${SNAP_NAME}" + _placeLine " - SNAP_VERSION:" "${SNAP_VERSION}" + _placeLine " - SNAP_REVISION:" "${SNAP_REVISION}" + _placeLine " - SNAP_DATA:" "${SNAP_DATA}" + _placeLine " - SNAP_COMMON:" "${SNAP_COMMON}" + _placeLine " - SNAP_USER_COMMON:" "${SNAP_USER_COMMON}" + fi } account(){ @@ -588,9 +639,13 @@ main(){ account #manufacturing if [[ $memory -eq 1 ]]; then - procState - performance - memory + if [[ -z "$SNAP" ]]; then + procState + performance + memory + else + echo "NOTE! Cannot run -m option in a snap." + fi fi fi } diff --git a/fw-tools/edge-testnet b/fw-tools/edge-testnet index 06394d9..2f3f3cb 100755 --- a/fw-tools/edge-testnet +++ b/fw-tools/edge-testnet @@ -19,6 +19,9 @@ LWT=$temp/test-lwm2m.txt L3T=$temp/layer3.txt L4T=$temp/layer4.txt +# For faster testing w/o actually building the whole snap +#SNAP="snap-test" + VERBOSE=0 DONTDELETE=0 @@ -155,7 +158,6 @@ test_gateway() { fi } - test_L3() { _url() { if [[ $(ping -q -c 1 "$1" >>"$L3T" 2>&1) -eq 0 ]]; then @@ -168,6 +170,17 @@ test_L3() { verbose "---------------------------------" _url bootstrap.us-east-1.mbedcloud.com _url lwm2m.us-east-1.mbedcloud.com + # Check if we're running as a snap or not and change port accordingly. + # If env variable SNAP exists, we're running as SNAP. + if [[ -n "${SNAP}" ]]; then + verbose "Test Layer 3 for snapcraft.io" + _url api.snapcraft.io + _url canonical-lgw01.cdn.snapcraftcontent.com + _url canonical-lcy01.cdn.snapcraftcontent.com + _url canonical-lcy02.cdn.snapcraftcontent.com + _url canonical-bos01.cdn.snapcraftcontent.com + _url serial-vault-partners.canonical.com + fi } test_L4() { @@ -186,6 +199,18 @@ test_L4() { _nc lwm2m.us-east-1.mbedcloud.com 5684 _nc k8s.us-east-1.mbedcloud.com 443 _nc gateways.us-east-1.mbedcloud.com 443 + if [[ -n "${SNAP}" ]]; then + # https://snapcraft.io/docs/network-requirements + _nc api.snapcraft.io 443 + _nc dashboard.snapcraft.io 443 + _nc login.ubuntu.com 443 + _nc storage.snapcraftcontent.com 443 + _nc canonical-lgw01.cdn.snapcraftcontent.com 443 + _nc canonical-lcy01.cdn.snapcraftcontent.com 443 + _nc canonical-lcy02.cdn.snapcraftcontent.com 443 + _nc canonical-bos01.cdn.snapcraftcontent.com 443 + _nc serial-vault-partners.canonical.com 443 + fi } main() { diff --git a/identity-tools/developer_identity/VERSION b/identity-tools/developer_identity/VERSION index 3e3c2f1..edbec98 100644 --- a/identity-tools/developer_identity/VERSION +++ b/identity-tools/developer_identity/VERSION @@ -1 +1,2 @@ -2.1.1 +2.2.0 + diff --git a/identity-tools/developer_identity/common.sh b/identity-tools/developer_identity/common.sh deleted file mode 100644 index 75d4961..0000000 --- a/identity-tools/developer_identity/common.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2019, Arm Limited and affiliates. -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -cli_log() { - script_name=${0##*/} - timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - echo "$timestamp $script_name LOG $1" -} - -cli_error() { - script_name=${0##*/} - timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - echo "$timestamp $script_name ERROR $1" -} - -cli_warn() { - script_name=${0##*/} - timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - echo "$timestamp $script_name WARN $1" -} - -cli_debug() { - if [ ! -z $VERBOSE ]; then - script_name=${0##*/} - timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - echo "$timestamp $script_name DEBUG $1" - fi -} \ No newline at end of file diff --git a/identity-tools/developer_identity/create-dev-identity.sh b/identity-tools/developer_identity/create-dev-identity.sh index 57f0ddb..c6c57a3 100755 --- a/identity-tools/developer_identity/create-dev-identity.sh +++ b/identity-tools/developer_identity/create-dev-identity.sh @@ -17,8 +17,31 @@ set -e -export DEVID_CLI_DIR=$(cd $(dirname $0) && pwd) -. "$DEVID_CLI_DIR/common.sh" +cli_log() { + script_name=${0##*/} + timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo "$timestamp $script_name LOG $1" +} + +cli_error() { + script_name=${0##*/} + timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo "$timestamp $script_name ERROR $1" +} + +cli_warn() { + script_name=${0##*/} + timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo "$timestamp $script_name WARN $1" +} + +cli_debug() { + if [ -n "$VERBOSE" ]; then + script_name=${0##*/} + timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo "$timestamp $script_name DEBUG $1" + fi +} HW_VERSION="unknown" [ -f /proc/device-tree/model ] && HW_VERSION=$(sed 's/ /_/g' <<< $(tr -d '\0'