Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved snap support #44

Merged
merged 16 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/pr-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Izuma Edge utilities 2.1.1
## Izuma Edge utilities 2.2.0
1. [edge-info] Add support for different localhost:<port>/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.
Expand Down
151 changes: 103 additions & 48 deletions edge-info/edge-info
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:<port>/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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -327,16 +370,24 @@ 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
_placeLine " - OS:" "$OS ($bito bit)"
_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(){
Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 26 additions & 1 deletion fw-tools/edge-testnet
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -155,7 +158,6 @@ test_gateway() {
fi
}


test_L3() {
_url() {
if [[ $(ping -q -c 1 "$1" >>"$L3T" 2>&1) -eq 0 ]]; then
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion identity-tools/developer_identity/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
2.1.1
2.2.0

42 changes: 0 additions & 42 deletions identity-tools/developer_identity/common.sh

This file was deleted.

27 changes: 25 additions & 2 deletions identity-tools/developer_identity/create-dev-identity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' </proc/device-tree/model))
Expand Down