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

115 lines
4.2 KiB
Diff

From: Tatiana Leon <tatiana.leon@digi.com>
Date: Mon, 13 Nov 2017 20:01:59 +0100
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: Tatiana Leon <tatiana.leon@digi.com>
---
.../ggc/packages/1.1.0/greengrassd | 27 +++++++++++-----------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/ggc/packages/1.1.0/greengrassd
index 9bece0c..4d68477 100755
--- a/ggc/packages/1.1.0/greengrassd
+++ b/ggc/packages/1.1.0/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
@@ -42,20 +42,21 @@ 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
mkdir -p $(dirname "$CRASH_LOG")
}
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
@@ -134,13 +135,13 @@ finish() {
pid=$1
echo "$pid" > $PID_FILE
echo ""
- echo -e "\e[0;32mGreengrass successfully started with PID: $pid\e[0m"
+ printf "\e[0;32mGreengrass successfully started with PID: $pid\e[0m\n"
exit 0
}
start() {
setup
- if [[ $INSECURE -ne 1 ]]; then
+ if [ "${INSECURE}" != "1" ]; then
validatePlatformSecurity
fi
@@ -159,7 +160,7 @@ start() {
echo ""
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
else
echo "Failed to start Greengrass daemon"
@@ -191,7 +192,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))
@@ -207,7 +208,7 @@ stop() {
if [ $total_sleep_seconds -ge $MAX_DAEMON_KILL_WAIT_SECONDS ] && [ -e "/proc/$PID" ]; then
# If we are here, we never exited in the previous loop and the pid still exists. Exit with failure.
kill -9 "$PID" > /dev/null 2>&1
- echo -e "\nProcess with pid $PID still alive after timeout of $MAX_DAEMON_KILL_WAIT_SECONDS seconds. Forced 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
@@ -217,12 +218,12 @@ usage() {
echo ""
echo "Usage: $0 [FLAGS] {start|stop|restart}"
echo ""
- echo -e "[FLAGS]: \n -i, --insecure \t Run GGC in insecure mode without hardlink/softlink protection, (highly discouraged for production use) \n -v, --version \t\t Outputs the version of GGC."
+ printf "[FLAGS]: \n -i, --insecure \t Run GGC in insecure mode without hardlink/softlink protection, (highly discouraged for production use) \n -v, --version \t\t Outputs the version of GGC.\n"
echo ""
exit 1
}
-if [[ $# -eq 0 ]]; then
+if [ $# -eq 0 ]; then
usage
fi
@@ -236,7 +237,7 @@ do
esac
done
-while [[ $# -gt 0 ]]
+while [ $# -gt 0 ]
do
key="$1"
case $key in