diff options
author | Didier Wenzek <didier.wenzek@acidalie.com> | 2022-08-19 09:05:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-19 09:05:33 +0200 |
commit | 53c75cb81ec4551fde6dab3e26ef55ff6cd7e7f2 (patch) | |
tree | 73ecbfeae6dfd6c9a3d084c769e802d1e22dc560 | |
parent | ee3047cd76ad7485526f262442d97a48c6427349 (diff) | |
parent | e67ad4d292fb734ed8d6931e7b400cbc2f916dc8 (diff) |
Merge pull request #1326 from matthiasbeyer/add-shellcheck
Add shellcheck action, fix issues
-rw-r--r-- | .github/workflows/pull-request-checks.yml | 8 | ||||
-rwxr-xr-x | ci/build_scripts/build_for_amd64.sh | 1 | ||||
-rwxr-xr-x | ci/build_scripts/build_for_arm.sh | 1 | ||||
-rwxr-xr-x | ci/ci_smoke_test_az.sh | 5 | ||||
-rwxr-xr-x | ci/ci_smoke_test_c8y.sh | 28 | ||||
-rwxr-xr-x | ci/configure_bridge.sh | 28 | ||||
-rwxr-xr-x | ci/installation_scripts/clean_up_rpi.sh | 5 | ||||
-rwxr-xr-x | ci/installation_scripts/install_for_amd64.sh | 3 | ||||
-rwxr-xr-x | ci/installation_scripts/install_for_arm.sh | 3 | ||||
-rwxr-xr-x | ci/package_list.sh | 41 | ||||
-rwxr-xr-x | ci/report/build.sh | 1 | ||||
-rwxr-xr-x | ci/report/build_local.sh | 1 | ||||
-rwxr-xr-x | docs/gen-ref-docs.sh | 2 | ||||
-rwxr-xr-x | get-thin-edge_io.sh | 68 | ||||
-rw-r--r-- | plugins/tedge_docker_plugin/tedge_docker_plugin.sh | 36 | ||||
-rwxr-xr-x | tests/PySys/misc_features/custom_init_system/dummy_init/dummy_init.sh | 10 | ||||
-rwxr-xr-x | uninstall-thin-edge_io.sh | 4 |
17 files changed, 138 insertions, 107 deletions
diff --git a/.github/workflows/pull-request-checks.yml b/.github/workflows/pull-request-checks.yml index e69fb710..9c029163 100644 --- a/.github/workflows/pull-request-checks.yml +++ b/.github/workflows/pull-request-checks.yml @@ -333,6 +333,14 @@ jobs: command: test args: --release --no-run --target=armv7-unknown-linux-gnueabihf --all-features + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + ### Disable cargo-tarpaulin as some tests failed only in this step # cargo-tarpaulin: # name: Run cargo tarpaulin diff --git a/ci/build_scripts/build_for_amd64.sh b/ci/build_scripts/build_for_amd64.sh index 0100c4de..80e940a7 100755 --- a/ci/build_scripts/build_for_amd64.sh +++ b/ci/build_scripts/build_for_amd64.sh @@ -6,6 +6,7 @@ set -euo pipefail cargo install cargo-deb --version 1.38.1 # Load the package list as $RELEASE_PACKAGES and $TEST_PACKAGES +# shellcheck disable=SC1091 source ./ci/package_list.sh # Build release debian packages diff --git a/ci/build_scripts/build_for_arm.sh b/ci/build_scripts/build_for_arm.sh index c43e0d7b..deb2857c 100755 --- a/ci/build_scripts/build_for_arm.sh +++ b/ci/build_scripts/build_for_arm.sh @@ -14,6 +14,7 @@ sudo apt update sudo apt-get --assume-yes install binutils-arm-linux-gnueabihf binutils-aarch64-linux-gnu # Load the release package list as $RELEASE_PACKAGES and $TEST_PACKAGES +# shellcheck disable=SC1091 source ./ci/package_list.sh # Cross build release for target diff --git a/ci/ci_smoke_test_az.sh b/ci/ci_smoke_test_az.sh index e6cf5c00..b28fd57a 100755 --- a/ci/ci_smoke_test_az.sh +++ b/ci/ci_smoke_test_az.sh @@ -19,14 +19,15 @@ set -e # Read device thumbprint from command line THUMB=$(sudo tedge cert show | grep Thumb | cut -c13-) -echo "DEVICE Thumbprint is " $THUMB +echo "DEVICE Thumbprint is $THUMB" python3 -m venv ~/env-eventhub +# shellcheck disable=SC1090 source ~/env-eventhub/bin/activate pip install azure-eventhub -./ci/az_upload_device_cert.py -d $C8YDEVICE -t $THUMB -u $IOTHUBNAME -s iothubowner +./ci/az_upload_device_cert.py -d "$C8YDEVICE" -t "$THUMB" -u "$IOTHUBNAME" -s iothubowner sudo tedge connect az diff --git a/ci/ci_smoke_test_c8y.sh b/ci/ci_smoke_test_c8y.sh index f77d23f0..3aa8516a 100755 --- a/ci/ci_smoke_test_c8y.sh +++ b/ci/ci_smoke_test_c8y.sh @@ -22,49 +22,49 @@ appendtofile() { STRING=$1 FILE=$2 - if grep "$STRING" $FILE; then + if grep "$STRING" "$FILE"; then echo 'line already there' else - echo $STRING >>$FILE + echo "$STRING" >>"$FILE" fi } -if [ -z $C8YDEVICE ]; then +if [ -z "$C8YDEVICE" ]; then echo "Error: Please supply your device name as environment variable C8YDEVICE" exit 1 else echo "Your device: HIDDEN" fi -if [ -z $C8YUSERNAME ]; then +if [ -z "$C8YUSERNAME" ]; then echo "Error: Please supply your user name as environment variable C8YUSERNAME" exit 1 else echo "Your user name: HIDDEN" fi -if [ -z $C8YTENANT ]; then +if [ -z "$C8YTENANT" ]; then echo "Error: Please supply your tenant ID as environment variable C8YTENANT" exit 1 else echo "Your tenant ID: HIDDEN" fi -if [ -z $C8YPASS ]; then +if [ -z "$C8YPASS" ]; then echo "Error: Please supply your Cumulocity password environment variable C8YPASS" exit 1 else echo "Your password: HIDDEN" fi -if [ -z $EXAMPLEDIR ]; then +if [ -z "$EXAMPLEDIR" ]; then echo "Error: Please supply the path to the sawtooth_publisher as EXAMPLEDIR" exit 1 else echo "Your exampledir: $EXAMPLEDIR" fi -if [ -z $TEBASEDIR ]; then +if [ -z "$TEBASEDIR" ]; then echo "Error: Please supply the path to the sawtooth_publisher as TEBASEDIR" exit 1 else @@ -75,12 +75,14 @@ fi PATH=$PATH:/usr/sbin python3 -m venv ~/env-c8y-api +# shellcheck disable=SC1090 source ~/env-c8y-api/bin/activate pip3 install c8y-api retry-decorator -export C8YDEVICEID=$(python3 ./ci/find_device_id.py --tenant $C8YTENANT --user $C8YUSERNAME --device $C8YDEVICE --url $C8YURL) +C8YDEVICEID=$(python3 ./ci/find_device_id.py --tenant "$C8YTENANT" --user "$C8YUSERNAME" --device "$C8YDEVICE" --url "$C8YURL") +export C8YDEVICEID # after calling the script, the ID should be a numeric value -if [[ $C8YDEVICEID =~ ^[0-9]+$ ]]; then +if [[ "$C8YDEVICEID" =~ ^[0-9]+$ ]]; then echo "Your device ID: $C8YDEVICEID" else echo "Error: Please supply your Cumulocity device ID name as environment variable C8YDEVICEID ($C8YDEVICEID)" @@ -95,7 +97,7 @@ echo "Start smoke tests" # Publish some values for val in 20 30 20 30; do - tedge mqtt pub c8y/s/us 211,$val + tedge mqtt pub c8y/s/us "211,$val" sleep 0.1 done @@ -103,13 +105,13 @@ done sleep 12 # Uses SmartREST for publishing -./ci/roundtrip_local_to_c8y.py -m REST -pub $EXAMPLEDIR -u $C8YUSERNAME -t $C8YTENANT -id $C8YDEVICEID +./ci/roundtrip_local_to_c8y.py -m REST -pub "$EXAMPLEDIR" -u "$C8YUSERNAME" -t "$C8YTENANT" -id "$C8YDEVICEID" # Wait some seconds until our 10 seconds window is empty again sleep 12 # Uses thin-edge JSON for publishing -./ci/roundtrip_local_to_c8y.py -m JSON -pub $EXAMPLEDIR -u $C8YUSERNAME -t $C8YTENANT -id $C8YDEVICEID +./ci/roundtrip_local_to_c8y.py -m JSON -pub "$EXAMPLEDIR" -u "$C8YUSERNAME" -t "$C8YTENANT" -id "$C8YDEVICEID" echo "Disonnect again" sudo tedge disconnect c8y diff --git a/ci/configure_bridge.sh b/ci/configure_bridge.sh index 4099efd9..cba16a3e 100755 --- a/ci/configure_bridge.sh +++ b/ci/configure_bridge.sh @@ -1,5 +1,14 @@ #!/bin/bash +for variable in C8YURL C8YUSERNAME C8YPASSWORD C8YDEVICE C8YTENANT C8YDEVICEID; +do + declare -n var_ref=$variable + if [ -z "${var_ref}" ]; then + echo "$variable not set" + exit 1 + fi +done + echo "Disconnect old bridge" # Disconnect - may fail if not there @@ -11,19 +20,20 @@ set -e echo "Configuring Bridge" -URL=$(echo $C8YURL | cut -c 9- - ) +URL=$(echo "$C8YURL" | cut -c 9- - ) sudo tedge cert remove -sudo tedge cert create --device-id=$C8YDEVICE +# shellcheck disable=SC2153 +sudo tedge cert create --device-id="$C8YDEVICE" sudo tedge cert show -sudo tedge config set c8y.url $URL +sudo tedge config set c8y.url "$URL" sudo tedge config set c8y.root.cert.path /etc/ssl/certs -sudo tedge config set az.url $IOTHUBNAME.azure-devices.net +sudo tedge config set az.url "$IOTHUBNAME.azure-devices.net" sudo tedge config set az.root.cert.path /etc/ssl/certs/Baltimore_CyberTrust_Root.pem @@ -31,17 +41,18 @@ sudo tedge config list # Note: This will always upload a new certificate. From time to time # we should delete the old ones in c8y -sudo -E tedge cert upload c8y --user $C8YUSERNAME +sudo -E tedge cert upload c8y --user "$C8YUSERNAME" cat /etc/mosquitto/mosquitto.conf python3 -m venv ~/env-c8y-api +# shellcheck disable=SC1090 source ~/env-c8y-api/bin/activate pip3 install c8y-api retry-decorator # Delete the device (ignore error) set +e -python3 ./ci/delete_current_device_c8y.py --tenant $C8YTENANT --user $C8YUSERNAME --device $C8YDEVICE --url $C8YURL +python3 ./ci/delete_current_device_c8y.py --tenant "$C8YTENANT" --user "$C8YUSERNAME" --device "$C8YDEVICE" --url "$C8YURL" set -e # Give Cumolocity time to process the cert deletion @@ -56,9 +67,10 @@ sleep 2 # Retrieve the Cumulocity device ID -export C8YDEVICEID=$(python3 ./ci/find_device_id.py --tenant $C8YTENANT --user $C8YUSERNAME --device $C8YDEVICE --url $C8YURL) +C8YDEVICEID=$(python3 ./ci/find_device_id.py --tenant "$C8YTENANT" --user "$C8YUSERNAME" --device "$C8YDEVICE" --url "$C8YURL") +export C8YDEVICEID -echo "The new device ID is: " $C8YDEVICEID +echo "The new device ID is: " "$C8YDEVICEID" deactivate diff --git a/ci/installation_scripts/clean_up_rpi.sh b/ci/installation_scripts/clean_up_rpi.sh index f82cf74a..eb250591 100755 --- a/ci/installation_scripts/clean_up_rpi.sh +++ b/ci/installation_scripts/clean_up_rpi.sh @@ -7,8 +7,9 @@ sudo tedge disconnect az sudo systemctl stop apama # Load the release package list as $RELEASE_PACKAGES +# shellcheck disable=SC1091 source ./ci/package_list.sh # Purge packages -sudo apt --assume-yes purge $(echo "${RELEASE_PACKAGES[*]}") -sudo DEBIAN_FRONTEND=noninteractive apt --assume-yes purge $(echo "${EXTERNAL_ARM_PACKAGES[*]}") +sudo apt --assume-yes purge "${RELEASE_PACKAGES[*]}" +sudo DEBIAN_FRONTEND=noninteractive apt --assume-yes purge "${EXTERNAL_ARM_PACKAGES[*]}" diff --git a/ci/installation_scripts/install_for_amd64.sh b/ci/installation_scripts/install_for_amd64.sh index 32071868..fe6d9bd5 100755 --- a/ci/installation_scripts/install_for_amd64.sh +++ b/ci/installation_scripts/install_for_amd64.sh @@ -5,10 +5,11 @@ set -euo pipefail PKG_DIR=$1 # Load the package list as $EXTERNAL_AMD64_PACKAGES and $RELEASE_PACKAGES +# shellcheck disable=SC1091 source ./ci/package_list.sh # Install pre-required packages -sudo apt-get --assume-yes install $(echo "${EXTERNAL_AMD64_PACKAGES[*]}") +sudo apt-get --assume-yes install "${EXTERNAL_AMD64_PACKAGES[*]}" # Install thin-edge packages for PACKAGE in "${RELEASE_PACKAGES[@]}" diff --git a/ci/installation_scripts/install_for_arm.sh b/ci/installation_scripts/install_for_arm.sh index 5d495ea2..45fcd04d 100755 --- a/ci/installation_scripts/install_for_arm.sh +++ b/ci/installation_scripts/install_for_arm.sh @@ -5,10 +5,11 @@ set -euo pipefail PKG_DIR=$1 # Load the package list as $EXTERNAL_ARM_PACKAGES, $RELEASE_PACKAGES +# shellcheck disable=SC1091 source ./ci/package_list.sh # Install pre-required packages -sudo apt-get --assume-yes install $(echo "${EXTERNAL_ARM_PACKAGES[*]}") +sudo apt-get --assume-yes install "${EXTERNAL_ARM_PACKAGES[*]}" # Install thin-edge packages for PACKAGE in "${RELEASE_PACKAGES[@]}" diff --git a/ci/package_list.sh b/ci/package_list.sh index 205b6132..0decfc0d 100755 --- a/ci/package_list.sh +++ b/ci/package_list.sh @@ -2,31 +2,36 @@ # Note: Must be in the expected installation order RELEASE_PACKAGES=( -tedge -tedge_mapper -tedge_agent -tedge_watchdog -tedge_apt_plugin -tedge_apama_plugin -c8y_log_plugin -c8y_configuration_plugin + tedge + tedge_mapper + tedge_agent + tedge_watchdog + tedge_apt_plugin + tedge_apama_plugin + c8y_log_plugin + c8y_configuration_plugin ) +export RELEASE_PACKAGES TEST_PACKAGES=( -sawtooth_publisher -tedge_dummy_plugin + sawtooth_publisher + tedge_dummy_plugin ) +export TEST_PACKAGES EXTERNAL_ARM_PACKAGES=( -mosquitto-clients -mosquitto -libmosquitto1 -collectd-core -collectd + mosquitto-clients + mosquitto + libmosquitto1 + collectd-core + collectd ) +export EXTERNAL_ARM_PACKAGES EXTERNAL_AMD64_PACKAGES=( -mosquitto -libmosquitto1 -collectd-core + mosquitto + libmosquitto1 + collectd-core ) +export EXTERNAL_AMD64_PACKAGES + diff --git a/ci/report/build.sh b/ci/report/build.sh index aca5531b..69872670 100755 --- a/ci/report/build.sh +++ b/ci/report/build.sh @@ -5,6 +5,7 @@ set -e python3 -m venv ~/env-builder +# shellcheck disable=SC1090 source ~/env-builder/bin/activate pip3 install junitparser pip3 install junit2html diff --git a/ci/report/build_local.sh b/ci/report/build_local.sh index 2af08917..01f75975 100755 --- a/ci/report/build_local.sh +++ b/ci/report/build_local.sh @@ -5,6 +5,7 @@ set -e python3 -m venv ~/env-builder +# shellcheck disable=SC1090 source ~/env-builder/bin/activate pip3 install junitparser pip3 install junit2html diff --git a/docs/gen-ref-docs.sh b/docs/gen-ref-docs.sh index cbaed264..a75165ff 100755 --- a/docs/gen-ref-docs.sh +++ b/docs/gen-ref-docs.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + SRC=docs/src/references PATH=$PATH:target/debug:target/release diff --git a/get-thin-edge_io.sh b/get-thin-edge_io.sh index 49db1fb9..248874e9 100755 --- a/get-thin-edge_io.sh +++ b/get-thin-edge_io.sh @@ -18,40 +18,40 @@ EOF } install_basic_components() { - wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_${VERSION}_${ARCH}.deb -P /tmp/tedge - wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_mapper_${VERSION}_${ARCH}.deb -P /tmp/tedge + wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_${VERSION}_${ARCH}.deb" -P /tmp/tedge + wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_mapper_${VERSION}_${ARCH}.deb" -P /tmp/tedge - dpkg -i /tmp/tedge/tedge_${VERSION}_${ARCH}.deb - dpkg -i /tmp/tedge/tedge_mapper_${VERSION}_${ARCH}.deb + dpkg -i "/tmp/tedge/tedge_${VERSION}_${ARCH}.deb" + dpkg -i "/tmp/tedge/tedge_mapper_${VERSION}_${ARCH}.deb" } install_tedge_agent() { - wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_agent_${VERSION}_${ARCH}.deb -P /tmp/tedge + wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_agent_${VERSION}_${ARCH}.deb" -P /tmp/tedge - dpkg -i /tmp/tedge/tedge_agent_${VERSION}_${ARCH}.deb + dpkg -i "/tmp/tedge/tedge_agent_${VERSION}_${ARCH}.deb" } install_tedge_plugins() { # Download and install apt plugin - wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_apt_plugin_${VERSION}_${ARCH}.deb -P /tmp/tedge - dpkg -i /tmp/tedge/tedge_apt_plugin_${VERSION}_${ARCH}.deb + wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_apt_plugin_${VERSION}_${ARCH}.deb" -P /tmp/tedge + dpkg -i "/tmp/tedge/tedge_apt_plugin_${VERSION}_${ARCH}.deb" # Download and install apama plugin - wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_apama_plugin_${VERSION}_${ARCH}.deb -P /tmp/tedge - dpkg -i /tmp/tedge/tedge_apama_plugin_${VERSION}_${ARCH}.deb - + wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_apama_plugin_${VERSION}_${ARCH}.deb" -P /tmp/tedge + dpkg -i "/tmp/tedge/tedge_apama_plugin_${VERSION}_${ARCH}.deb" + # Download and install configuration plugin - wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/c8y_configuration_plugin_${VERSION}_${ARCH}.deb -P /tmp/tedge - dpkg -i /tmp/tedge/c8y_configuration_plugin_${VERSION}_${ARCH}.deb + wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/c8y_configuration_plugin_${VERSION}_${ARCH}.deb" -P /tmp/tedge + dpkg -i "/tmp/tedge/c8y_configuration_plugin_${VERSION}_${ARCH}.deb" # Download and install c8y log plugin - wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/c8y_log_plugin_${VERSION}_${ARCH}.deb -P /tmp/tedge - dpkg -i /tmp/tedge/c8y_log_plugin_${VERSION}_${ARCH}.deb + wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/c8y_log_plugin_${VERSION}_${ARCH}.deb" -P /tmp/tedge + dpkg -i "/tmp/tedge/c8y_log_plugin_${VERSION}_${ARCH}.deb" # Download and install tedge_watchdog - wget https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_watchdog_${VERSION}_${ARCH}.deb -P /tmp/tedge - dpkg -i /tmp/tedge/tedge_watchdog_${VERSION}_${ARCH}.deb + wget "https://github.com/thin-edge/thin-edge.io/releases/download/${VERSION}/tedge_watchdog_${VERSION}_${ARCH}.deb" -P /tmp/tedge + dpkg -i "/tmp/tedge/tedge_watchdog_${VERSION}_${ARCH}.deb" } if [ $# -lt 3 ]; then @@ -72,23 +72,15 @@ fi VERSION=$1 ARCH=$(dpkg --print-architecture) -BLUE='' -COLORRESET='' -if [ -t 1 ]; then - if [ "$(tput colors)" -ge 8 ]; then - BLUE='\033[1;34m' - COLORRESET='\033[0m' - fi -fi - -echo "${BLUE}Thank you for trying thin-edge.io! ${COLORRESET}\n" +echo "Thank you for trying thin-edge.io!" +echo if [ -z "$VERSION" ]; then VERSION=0.7.4 - echo "Version argument has not been provided, installing latest: ${BLUE}$VERSION${COLORRESET}" + echo "Version argument has not been provided, installing latest: $VERSION" echo "To install a particular version use this script with the version as an argument." - echo "For example: ${BLUE}sudo ./get-thin-edge_io.sh $VERSION${COLORRESET}" + echo "For example: sudo ./get-thin-edge_io.sh $VERSION" fi if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ] || [ "$ARCH" = "armhf" ] || [ "$ARCH" = "amd64" ]; then @@ -103,7 +95,7 @@ if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ] || [ "$ARCH" = "armhf" ] || exit 1 fi - echo "${BLUE}Installing for architecture $ARCH ${COLORRESET}" + echo "Installing for architecture $ARCH" else echo "$ARCH is currently not supported. Currently supported are aarch64/arm64, armhf and amd64." exit 0 @@ -113,7 +105,7 @@ if [ -d "/tmp/tedge" ]; then rm -R /tmp/tedge fi -echo "${BLUE}Installing mosquitto as prerequirement for thin-edge.io${COLORRESET}" +echo "Installing mosquitto as prerequirement for thin-edge.io" apt install mosquitto -y case $TYPE in @@ -121,7 +113,7 @@ minimal) install_basic_components ;; full) install_basic_components install_tedge_agent - if apt -v &>/dev/null; then + if apt -v >/dev/null 2>&1; then install_tedge_plugins fi ;; @@ -134,11 +126,13 @@ esac rm -R /tmp/tedge # Test if tedge command is there and working -tedge help >/dev/null -if [ $? -eq 0 ]; then - echo "\n${BLUE}thin-edge.io is now installed on your system!${COLORRESET}" +if tedge help >/dev/null; +then + echo + echo "thin-edge.io is now installed on your system!" echo "" - echo "You can go to our documentation to find next steps:${BLUE} https://github.com/thin-edge/thin-edge.io/blob/main/docs/src/howto-guides/003_registration.md ${COLORRESET}" + echo "You can go to our documentation to find next steps: https://github.com/thin-edge/thin-edge.io/blob/main/docs/src/howto-guides/003_registration.md" else - echo "Something went wrong in the installation process please try the manual installation steps instead:\n https://github.com/thin-edge/thin-edge.io/blob/main/docs/src/howto-guides/002_installation.md" + echo "Something went wrong in the installation process please try the manual installation steps instead:" + echo "https://github.com/thin-edge/thin-edge.io/blob/main/docs/src/howto-guides/002_installation.md" fi diff --git a/plugins/tedge_docker_plugin/tedge_docker_plugin.sh b/plugins/tedge_docker_plugin/tedge_docker_plugin.sh index 9aee79ea..1bdb3bd1 100644 --- a/plugins/tedge_docker_plugin/tedge_docker_plugin.sh +++ b/plugins/tedge_docker_plugin/tedge_docker_plugin.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash usage() { cat << EOF @@ -15,8 +15,8 @@ EOF } unsupported_args_check() { - if ! [ -z $1 ]; then - echo "Unsupported arguments: $@" + if [ -n "$1" ]; then + echo "Unsupported arguments: $*" exit 1 fi } @@ -30,7 +30,7 @@ extract_image_tag_from_args() { shift # Pop image name from args list IMAGE_TAG=$IMAGE_NAME - if ! [ -z $1 ]; then + if [ -n "$1" ]; then case "$1" in --module-version) IMAGE_VERSION="$2" @@ -44,12 +44,12 @@ extract_image_tag_from_args() { esac fi - unsupported_args_check $@ + unsupported_args_check "$@" } -if [ -z $1 ]; then - echo "Provide at least one subcommand\n" +if [ -z "$1" ]; then + echo -e "Provide at least one subcommand\n" usage exit 1 fi @@ -59,49 +59,49 @@ shift # Pop the command from args list case "$COMMAND" in prepare) - unsupported_args_check $@ + unsupported_args_check "$@" # nothing to do here ;; list) - unsupported_args_check $@ + unsupported_args_check "$@" docker image list --format '{{.Repository}}\t{{.Tag}}' || exit 2 ;; install) # Extract the docker image tag into the IMAGE_TAG variable - extract_image_tag_from_args $@ + extract_image_tag_from_args "$@" # Stop all containers using the provided image name - containers=$(docker ps -a --format "{{.ID}} {{.Image}}" | grep $IMAGE_NAME | awk '{print $1}') || exit 2 + containers=$(docker ps -a --format "{{.ID}} {{.Image}}" | grep "$IMAGE_NAME" | awk '{print $1}') || exit 2 if [ -z "$containers" ] then echo "No containers to update. Spawning a new one." - docker run -d $IMAGE_TAG || exit 2 + docker run -d "$IMAGE_TAG" || exit 2 else echo "Updating existing containers." for container in $containers do - docker rm $(docker stop "$container") || exit 2 + docker rm "$(docker stop "$container")" || exit 2 # Spawn new containers with the provided image name and version to replace the stopped one - docker run -d $IMAGE_TAG || exit 2 + docker run -d "$IMAGE_TAG" || exit 2 done fi ;; remove) - extract_image_tag_from_args $@ + extract_image_tag_from_args "$@" - containers=$(docker ps -a --format "{{.ID}} {{.Image}}" | grep $IMAGE_TAG | awk '{print $1}') || exit 2 + containers=$(docker ps -a --format "{{.ID}} {{.Image}}" | grep "$IMAGE_TAG" | awk '{print $1}') || exit 2 if [ -z "$containers" ] then echo "No containers found for the image: $IMAGE_TAG" fi for container in $containers do - docker rm $(docker stop "$container") || exit 2 + docker rm "$(docker stop "$container")" || exit 2 done ;; finalize) - unsupported_args_check $@ + unsupported_args_check "$@" # Prune all the unused images. The --force command is used to avoid a [y/N] user prompt docker image prune --all --force || exit 2 ;; diff --git a/tests/PySys/misc_features/custom_init_system/dummy_init/dummy_init.sh b/tests/PySys/misc_features/custom_init_system/dummy_init/dummy_init.sh index f4021b50..75d32a68 100755 --- a/tests/PySys/misc_features/custom_init_system/dummy_init/dummy_init.sh +++ b/tests/PySys/misc_features/custom_init_system/dummy_init/dummy_init.sh @@ -12,19 +12,19 @@ case "$COMMAND" in echo is_available >> /tmp/dummy_init/dummy_init.out ;; restart) - echo restart $2 >> /tmp/dummy_init/dummy_init.out + echo restart "$2" >> /tmp/dummy_init/dummy_init.out ;; stop) - echo stop $2 >> /tmp/dummy_init/dummy_init.out + echo stop "$2" >> /tmp/dummy_init/dummy_init.out ;; enable) - echo enable $2 >> /tmp/dummy_init/dummy_init.out + echo enable "$2" >> /tmp/dummy_init/dummy_init.out ;; disable) - echo disable $2 >> /tmp/dummy_init/dummy_init.out + echo disable "$2" >> /tmp/dummy_init/dummy_init.out ;; is-active) - echo is-active $2 >> /tmp/dummy_init/dummy_init.out + echo is-active "$2" >> /tmp/dummy_init/dummy_init.out ;; *) echo "Error: unsupported command: $COMMAND." >> /tmp/dummy_init/dummy_init.out diff --git a/uninstall-thin-edge_io.sh b/uninstall-thin-edge_io.sh index 99f19a4a..19756d95 100755 --- a/uninstall-thin-edge_io.sh +++ b/uninstall-thin-edge_io.sh @@ -32,7 +32,7 @@ disconnect_from_cloud() { stop_extension_services() { for service in "${extension_services[@]}"; do - status=$(sudo systemctl is-active "$service") && returncode=$? || returncode=$? + status=$(sudo systemctl is-active "$service") || true if [ "$status" = "active" ]; then sudo systemctl stop "$service" fi @@ -43,7 +43,7 @@ remove_or_purge_package_if_exists() { disconnect_from_cloud stop_extension_services for package in "${packages[@]}"; do - status=$(dpkg -s "$package" | grep -w installed) && returncode=$? || returncode=$? + status=$(dpkg -s "$package" | grep -w installed) || true if [ "$status" = "Status: install ok installed" ]; then sudo apt --assume-yes "$1" "$package" fi |