Skip to content

Commit 48d864d

Browse files
committed
Improve shell scripts
Signed-off-by: Kai Hudalla <[email protected]>
1 parent bf886de commit 48d864d

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

create_dependencies_list.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ DEPENDENCIES="legal/src/main/resources/legal/DEPENDENCIES"
2929

3030
mvn dependency:list -DexcludeGroupIds=org.eclipse,org.junit -Pmetrics-prometheus,build-docker-image,build-native-image | grep -Poh "\S+:(runtime|compile|provided)" | sed -e 's/^\(.*\)\:.*$/\1/' | sort | uniq > $HONO_MAVEN_DEPS
3131

32-
java -Dorg.eclipse.dash.timeout=60 -jar $DASH_LICENSE_JAR -batch 90 -summary $DEPENDENCIES $HONO_MAVEN_DEPS $@
33-
sort -o $DEPENDENCIES $DEPENDENCIES
32+
java -Dorg.eclipse.dash.timeout=60 -jar "${DASH_LICENSE_JAR}" -batch 90 -summary ${DEPENDENCIES} ${HONO_MAVEN_DEPS} "$@"
33+
sort -o ${DEPENDENCIES} ${DEPENDENCIES}

demo-certs/create_certs.sh

+16-14
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ function create_key {
5353
echo ""
5454
if [ $KEY_ALG == "EC" ]
5555
then
56-
openssl ecparam -name secp384r1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt -inform PEM -outform PEM -out $DIR/$1
56+
openssl ecparam -name secp384r1 -genkey -noout | openssl pkcs8 -topk8 -nocrypt -inform PEM -outform PEM -out "$DIR/$1"
5757
else
58-
openssl genrsa 4096 | openssl pkcs8 -topk8 -nocrypt -inform PEM -outform PEM -out $DIR/$1
58+
openssl genrsa 4096 | openssl pkcs8 -topk8 -nocrypt -inform PEM -outform PEM -out "$DIR/$1"
5959
fi
6060

6161
if [ $? -ne 0 ]; then
@@ -74,14 +74,14 @@ function create_cert {
7474

7575
echo ""
7676
echo "creating $1 key and certificate"
77-
create_key $1-key.pem
78-
openssl req -config ca_opts -new -key $DIR/$1-key.pem -subj "/C=CA/L=Ottawa/O=Eclipse IoT/OU=Hono/CN=$1" | \
79-
openssl x509 -req -extfile ca_opts -extensions req_ext_$1 -out $DIR/$1.pem -days 365 -CA $DIR/ca-cert.pem -CAkey $DIR/ca-key.pem -CAcreateserial
80-
cat $DIR/$1.pem $DIR/ca-cert.pem > $DIR/$1-cert.pem && rm $DIR/$1.pem
81-
if [ $2 ]
77+
create_key "$1-key.pem"
78+
openssl req -config ca_opts -new -key "$DIR/$1-key.pem" -subj "/C=CA/L=Ottawa/O=Eclipse IoT/OU=Hono/CN=$1" | \
79+
openssl x509 -req -extfile ca_opts -extensions "req_ext_$1" -out "$DIR/$1.pem" -days 365 -CA "$DIR/ca-cert.pem" -CAkey "$DIR/ca-key.pem" -CAcreateserial
80+
cat "$DIR/$1.pem" "$DIR/ca-cert.pem" > "$DIR/$1-cert.pem" && rm "$DIR/$1.pem"
81+
if [ "$2" ]
8282
then
8383
echo "adding key/cert for $1 to key store $DIR/$2"
84-
openssl pkcs12 -export -inkey $DIR/$1-key.pem -in $DIR/$1-cert.pem -out $DIR/$2 -name $1 -password pass:$3
84+
openssl pkcs12 -export -inkey "$DIR/$1-key.pem" -in "$DIR/$1-cert.pem" -out "$DIR/$2" -name "$1" -password "pass:$3"
8585
fi
8686

8787
if [ $? -ne 0 ]; then
@@ -94,7 +94,7 @@ function create_cert {
9494
function create_client_cert {
9595
echo ""
9696
echo "creating client key and certificate for device $1"
97-
create_key device-$1-key.pem
97+
create_key "device-$1-key.pem"
9898
openssl req -new -key "$DIR/device-$1-key.pem" -subj "/C=CA/L=Ottawa/O=Eclipse IoT/OU=Hono/CN=Device $1" | \
9999
openssl x509 -req -out "$DIR/device-$1-cert.pem" -days 365 -CA $DIR/default_tenant-cert.pem -CAkey $DIR/default_tenant-key.pem -CAcreateserial
100100
SUBJECT=$(openssl x509 -in "$DIR/device-$1-cert.pem" -noout -subject -nameopt RFC2253)
@@ -154,11 +154,13 @@ CA_SUBJECT=$(openssl x509 -in $DIR/default_tenant-cert.pem -noout -subject -name
154154
PK=$(openssl x509 -in $DIR/default_tenant-cert.pem -noout -pubkey | sed /^---/d | sed -z 's/\n//g')
155155
NOT_BEFORE=$(date --date="$(openssl x509 -in $DIR/default_tenant-cert.pem -noout -startdate -nameopt RFC2253 | sed s/^notBefore=//)" --iso-8601=seconds)
156156
NOT_AFTER=$(date --date="$(openssl x509 -in $DIR/default_tenant-cert.pem -noout -enddate -nameopt RFC2253 | sed s/^notAfter=//)" --iso-8601=seconds)
157-
echo "trusted-ca.subject-dn=$CA_SUBJECT" > $DIR/trust-anchor.properties
158-
echo "trusted-ca.public-key=$PK" >> $DIR/trust-anchor.properties
159-
echo "trusted-ca.algorithm=$KEY_ALG" >> $DIR/trust-anchor.properties
160-
echo "trusted-ca.not-before=$NOT_BEFORE" >> $DIR/trust-anchor.properties
161-
echo "trusted-ca.not-after=$NOT_AFTER" >> $DIR/trust-anchor.properties
157+
{
158+
echo "trusted-ca.subject-dn=$CA_SUBJECT"
159+
echo "trusted-ca.public-key=$PK"
160+
echo "trusted-ca.algorithm=$KEY_ALG"
161+
echo "trusted-ca.not-before=$NOT_BEFORE"
162+
echo "trusted-ca.not-after=$NOT_AFTER"
163+
} > $DIR/trust-anchor.properties
162164

163165
create_cert qdrouter
164166
create_cert auth-server $AUTH_SERVER_KEY_STORE $AUTH_SERVER_KEY_STORE_PWD

deploy/src/main/deploy/services.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
NS=${1:-hono}
1616

1717
function get_service_ip {
18-
IP_ADDR=$(kubectl get service $1 --output='jsonpath={.status.loadBalancer.ingress[0].ip}' -n $NS 2> /dev/null)
19-
if [ $? -eq 0 ]
20-
then
21-
if [ "$IP_ADDR" != '' ]
18+
19+
if IP_ADDR=$(kubectl get service "$1" --output='jsonpath={.status.loadBalancer.ingress[0].ip}' -n "$NS" 2> /dev/null); then
20+
if [ "${IP_ADDR}" != '' ]
2221
then
23-
echo export $2=$IP_ADDR
22+
echo "export $2=${IP_ADDR}"
2423
else
2524
echo "echo \"could not determine IP address of service '$1'\""
2625
fi

push_hono_images.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ NATIVE_IMAGES="hono-adapter-amqp-native \
3737
hono-service-command-router-native \
3838
hono-service-device-registry-mongodb-native"
3939

40-
ME=`basename "$0"`
40+
ME=$(basename "$0")
4141
echo "called as $ME"
4242

4343
if [[ "push_hono_native_images.sh" == "$ME" ]]
@@ -53,12 +53,12 @@ then
5353
if [[ "docker.io" != "${CR}" || "eclipse" != "${REPO}" ]]
5454
then
5555
IMAGE_NAME="${CR}/${REPO}/${image}"
56-
docker tag $ECLIPSE_IMAGE_NAME:$TAG $IMAGE_NAME:$TAG
56+
docker tag "${ECLIPSE_IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:${TAG}"
5757
else
58-
IMAGE_NAME=$ECLIPSE_IMAGE_NAME
58+
IMAGE_NAME="${ECLIPSE_IMAGE_NAME}"
5959
fi
60-
echo "pushing image $IMAGE_NAME:$TAG ..."
61-
docker push $IMAGE_NAME:$TAG
60+
echo "pushing image ${IMAGE_NAME}:${TAG} ..."
61+
docker push "${IMAGE_NAME}:${TAG}"
6262
done
6363
else
6464
echo "This script can be used to push Hono's images from"

site/build-site.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@
1212
# SPDX-License-Identifier: EPL-2.0
1313
#*******************************************************************************
1414

15-
hugo version
16-
if [ $? != 0 ]
17-
then
15+
16+
if ! hugo version; then
1817
echo "Please install \"hugo\" to be able to build the hono documentation. See readme.md for further details."
1918
exit 0
2019
fi
2120

22-
if [ $1 ]
21+
if [ "$1" ]
2322
then
2423
TARGET="$1"
2524
else
2625
TARGET="public"
2726
fi
2827

29-
cd homepage/
28+
cd homepage || exit
3029
WEBSITE_THEME_CLONING_REQUIRED=1
3130
if [ -d themes/hugo-universal-theme/.git ]
3231
then
@@ -50,7 +49,7 @@ echo "Building homepage in directory: $TARGET"
5049
hugo -v -d $TARGET
5150
cd ..
5251

53-
cd documentation/
52+
cd documentation || exit
5453
DOC_THEME_CLONING_REQUIRED=1
5554
if [ -d themes/hugo-theme-relearn/.git ]
5655
then

0 commit comments

Comments
 (0)