Skip to content

Commit

Permalink
chore(#8557): add linting for shell scripts (#9142)
Browse files Browse the repository at this point in the history
Co-authored-by: mrjones-plip <mrjones-plip@plip.com>
  • Loading branch information
nydr and mrjones-plip authored Jun 5, 2024
1 parent 5c42456 commit 9879478
Show file tree
Hide file tree
Showing 24 changed files with 882 additions and 121 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test_couchdb.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: Test CouchDB (Conditional)
on:
pull_request:
paths:
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
# shellcheck disable=SC1091 # don't test thirdparty packages
. "$(dirname -- "$0")/_/husky.sh"

branch="$(git rev-parse --abbrev-ref HEAD)"
Expand Down
1 change: 1 addition & 0 deletions couchdb/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ if [ "$1" = '/opt/couchdb/bin/couchdb' ]; then

chown -f couchdb:couchdb $CLUSTER_CREDENTIALS || true

# shellcheck disable=SC2145 # needs additional investigation about intention before I'm confident in changing
su -c "ulimit -n 100000 && exec $@" couchdb
else
exec "$@"
Expand Down
6 changes: 3 additions & 3 deletions nginx/ssl-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ create_self_signed_ssl_certificate()
mkdir -p /etc/nginx/private
set_environment_variables_if_not_set
openssl req -x509 -nodes -newkey rsa:4096 \
-keyout $SSL_KEY_FILE_PATH -out $SSL_CERT_FILE_PATH -days 365 \
-keyout "$SSL_KEY_FILE_PATH" -out "$SSL_CERT_FILE_PATH" -days 365 \
-subj "/emailAddress=$EMAIL/C=$COUNTRY/ST=$STATE/L=$LOCALITY/O=$ORGANISATION/OU=$DEPARTMENT/CN=$COMMON_NAME"

return "$?"
}

generate_self_signed_cert(){
if [ -f $SSL_CERT_FILE_PATH -a -f $SSL_KEY_FILE_PATH ]; then
if [ -f "$SSL_CERT_FILE_PATH" ] && [ -f "$SSL_KEY_FILE_PATH" ]; then
echo "self signed SSL cert already exists." >&2
else
create_self_signed_ssl_certificate \
Expand All @@ -66,7 +66,7 @@ generate_self_signed_cert(){

ensure_own_cert_exits(){

if [ ! -f $SSL_CERT_FILE_PATH -a ! -f $SSL_KEY_FILE_PATH ]; then
if [ ! -f "$SSL_CERT_FILE_PATH" ] && [ ! -f "$SSL_KEY_FILE_PATH" ]; then
echo "Please provide add your certificate ($SSL_CERT_FILE_PATH) and key ($SSL_KEY_FILE_PATH) in the /etc/nginx/private/ directory"
exit 1
fi
Expand Down
12 changes: 4 additions & 8 deletions nginx/tests/ssl-install.bats
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# shellcheck disable=SC2030,SC2031 # exports doesn't need to leave subshell
setup() {
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
load '/app/bash-shellmock/shellmock'
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"

#shellcheck
# shellcheck disable=SC1091 # not testing third party scripts
. shellmock

#create temp cert files
base_temp_path="$TEST_TEMP_DIR/tmp/bats/etc/nginx/private"
mkdir -p $base_temp_path
mkdir -p "$base_temp_path"
export SSL_CERT_FILE_PATH="$base_temp_path/cert.pem"
export SSL_KEY_FILE_PATH="$base_temp_path/key.pem"


}

teardown()
Expand All @@ -28,7 +24,7 @@ teardown()
rm -rf "$TEST_TEMP_DIR"
fi

rm -rf $base_temp_path
rm -rf "$base_temp_path"
}


Expand Down
Loading

0 comments on commit 9879478

Please sign in to comment.