meta-digi/meta-digi-dey/recipes-aws/greengrass/greengrass-1.0.0/0001-greengrassd-remove-bas...

115 lines
4.1 KiB
Diff

From: Javier Viguera <javier.viguera@digi.com>
Date: Wed, 7 Jun 2017 20:44:56 +0200
Subject: [PATCH] greengrassd: remove bashisms in launcher shell script
So it runs properly in other Posix shells (like the one in Busybox)
Signed-off-by: Javier Viguera <javier.viguera@digi.com>
---
greengrassd | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/greengrassd b/greengrassd
index cadaa6b0101e..e24422af2f3d 100755
--- a/greengrassd
+++ b/greengrassd
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
##########Environment Requirement for Greengrass Daemon##########
# by default, the daemon assumes it's going to be launched from a directory
@@ -38,19 +38,19 @@ setup() {
mkdir -p $GGC_ROOT_FS
# Mask greengrass directory for containers
- mknod $GGC_ROOT_FS/greengrass c 1 3 &>/dev/null || true
+ mknod $GGC_ROOT_FS/greengrass c 1 3 >/dev/null 2>&1 || true
}
validatePlatformSecurity() {
- if [[ -f $FS_SETTINGS/protected_hardlinks &&
- -f $FS_SETTINGS/protected_symlinks ]]; then
+ if [ -f $FS_SETTINGS/protected_hardlinks ] &&
+ [ -f $FS_SETTINGS/protected_symlinks ]; then
PROT_HARDLINK_VAL=$(cat $FS_SETTINGS/protected_hardlinks)
PROT_SOFTLINK_VAL=$(cat $FS_SETTINGS/protected_symlinks)
- if [[ "$PROT_HARDLINK_VAL" -ne 1 || "$PROT_SOFTLINK_VAL" -ne 1 ]]; then
+ if [ "$PROT_HARDLINK_VAL" -ne 1 ] || [ "$PROT_SOFTLINK_VAL" -ne 1 ]; then
echo "AWS Greengrass detected insecure OS configuration: No hardlink/softlink protection enabled." | tee -a $CRASH_LOG
exit 1
fi
@@ -127,7 +127,7 @@ validateEnvironment() {
start() {
setup
- if [[ $INSECURE -ne 1 ]]; then
+ if [ "${INSECURE}" != "1" ]; then
validatePlatformSecurity
fi
@@ -139,7 +139,7 @@ start() {
then
pid=$!
# sleep 5 seconds to wait for daemon to start or exit
- for i in {1..5}; do
+ for i in $(seq 1 5); do
echo -n "."
sleep 1
done
@@ -147,10 +147,10 @@ start() {
if [ -e "/proc/$pid" ]
then
echo "$pid" > $PID_FILE
- echo -e "\e[0;32mGreengrass daemon started with PID: $pid\e[0m"
+ printf "\e[0;32mGreengrass daemon started with PID: $pid\e[0m\n"
else
echo "Greengrass daemon $pid failed to start"
- echo -e "\e[0;31m$(cat $CRASH_LOG)\e[0m"
+ printf "\e[0;31m$(cat $CRASH_LOG)\e[0m\n"
exit 1
fi
else
@@ -179,7 +179,7 @@ stop() {
# If the pid no longer exists, we're done, remove the pid file and exit. Otherwise, just increment the loop counter
if [ ! -e "/proc/$PID" ]; then
rm $PID_FILE
- echo -e "\nStopped greengrass daemon, exiting with success"
+ printf "\nStopped greengrass daemon, exiting with success\n"
break
else
total_sleep_seconds=$(($total_sleep_seconds+1))
@@ -194,7 +194,7 @@ stop() {
if [ $total_sleep_seconds -ge $MAX_DAEMON_KILL_WAIT_SECONDS ]; then
# If we are here, we never exited in the previous loop and the pid still exists. Exit with failure.
- echo -e "\nProcess with pid $PID still alive after timeout of $MAX_DAEMON_KILL_WAIT_SECONDS seconds. Unable to kill process, exiting with failure."
+ printf "\nProcess with pid $PID still alive after timeout of $MAX_DAEMON_KILL_WAIT_SECONDS seconds. Unable to kill process, exiting with failure.\n"
exit 1
fi
fi
@@ -204,16 +204,16 @@ usage() {
echo ""
echo "Usage: $0 [FLAGS] {start|stop|restart}"
echo ""
- echo -e "[FLAGS]: -i, --insecure \t Run GGC in insecure mode without hardlink/softlink protection, (highly discouraged for production use)"
+ printf "[FLAGS]: -i, --insecure \t Run GGC in insecure mode without hardlink/softlink protection, (highly discouraged for production use)\n"
echo ""
exit 1
}
-if [[ $# -eq 0 ]]; then
+if [ $# -eq 0 ]; then
usage
fi
-while [[ $# -gt 0 ]]
+while [ $# -gt 0 ]
do
key="$1"
case $key in