Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shellcheck fix with github action #388

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'ShellCheck'

on:
push:
branches: ["master"]
pull_request:

jobs:
shellcheck:
name: shellcheck
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
markshust marked this conversation as resolved.
Show resolved Hide resolved
id: check
env:
SHELLCHECK_OPTS: -x -e SC2181 -P compose/bin -P compose/env
with:
check_together: true
scandir: './compose/bin'
6 changes: 3 additions & 3 deletions compose/bin/copyfromcontainer
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

REAL_SRC=$(cd -P "src" && pwd)
if [ "$1" == "--all" ]; then
docker cp $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/./ "$REAL_SRC/"
docker cp "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/./ "$REAL_SRC/"
echo "Completed copying all files from container to host"
else
if [ -f "$1" ] ; then
docker cp $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/"$1" "$REAL_SRC/$1"
docker cp "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1" "$REAL_SRC/$1"
else
docker cp $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/"$1" "$REAL_SRC/$(dirname "$1")"
docker cp "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1" "$REAL_SRC/$(dirname "$1")"
fi
echo "Completed copying $1 from container to host"
fi
6 changes: 3 additions & 3 deletions compose/bin/copytocontainer
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

REAL_SRC=$(cd -P "src" && pwd)
if [ "$1" == "--all" ]; then
docker cp "$REAL_SRC/./" $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/
docker cp "$REAL_SRC/./" "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/
echo "Completed copying all files from host to container"
bin/fixowns
bin/fixperms
else
if [ -f "$REAL_SRC/$1" ]; then
docker cp "$REAL_SRC/${1}" $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/"$1"
docker cp "$REAL_SRC/${1}" "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$1"
else
docker cp "$REAL_SRC/${1}" $(docker-compose ps -q phpfpm|awk '{print $1}'):/var/www/html/"$(dirname "$1")"
docker cp "$REAL_SRC/${1}" "$(docker-compose ps -q phpfpm|awk '{print $1}')":/var/www/html/"$(dirname "$1")"
fi
echo "Completed copying $1 from host to container"
bin/fixowns "$1"
Expand Down
17 changes: 9 additions & 8 deletions compose/bin/download
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
#!/bin/bash
set -o errexit
[ -z "$1" ] && echo "Please specify the version to download (ex. 2.0.0)" && exit

edition=${2:-community}

if [[ "$edition" == "enterprise" ]]; then
rm -rf src
composer create-project --repository=https://repo.magento.com/ --ignore-platform-reqs magento/project-enterprise-edition=$1 src
composer create-project --repository=https://repo.magento.com/ --ignore-platform-reqs magento/project-enterprise-edition="$1" src
exit 0
fi

if [ ! -f ~/.docker-magento/magento2-$1.tar.gz ]; then
if [ ! -f ~/.docker-magento/magento2-"$1".tar.gz ]; then
mkdir -p ~/.docker-magento
(cd ~/.docker-magento && curl -fOL http://pubfiles.nexcess.net/magento/ce-packages/magento2-$1.tar.gz)
(cd ~/.docker-magento && curl -fOL http://pubfiles.nexcess.net/magento/ce-packages/magento2-"$1".tar.gz)
fi

# Fallback download to hypernode if archive doesn't exist on Nexcess (smaller than 1MB)
if [ $(find ~/.docker-magento/magento2-$1.tar.gz -size -1M) ]; then
(cd ~/.docker-magento && curl -o magento2-$1.tar.gz -fOL https://www.magento.mirror.hypernode.com/releases/magento-$1.tar.gz)
if [ "$(find ~/.docker-magento/magento2-"$1".tar.gz -size -1M)" ]; then
(cd ~/.docker-magento && curl -o magento2-"$1".tar.gz -fOL https://www.magento.mirror.hypernode.com/releases/magento-"$1".tar.gz)
fi

# Final fallback. If no archive exists, let's use Composer!
if [ ! -f ~/.docker-magento/magento2-$1.tar.gz ]; then
if [ ! -f ~/.docker-magento/magento2-"$1".tar.gz ]; then
echo "Archive not found, or not yet available due to new version release."
echo "Attempting install with Composer..."
rm -rf src
composer create-project --repository=https://repo.magento.com/ --ignore-platform-reqs magento/project-community-edition=$1 src
composer create-project --repository=https://repo.magento.com/ --ignore-platform-reqs magento/project-community-edition="$1" src
else
echo "Extracting magento2-$1.tar.gz to ./src"
mkdir -p src && tar xzf ~/.docker-magento/magento2-$1.tar.gz -o -C src
mkdir -p src && tar xzf ~/.docker-magento/magento2-"$1".tar.gz -o -C src
fi
6 changes: 4 additions & 2 deletions compose/bin/mysql
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

# shellcheck source=../env/db.env
source env/db.env
if [ -t 0 ]; then
# Need tty to run mysql shell
bin/cli mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
bin/cli mysql -h"${MYSQL_HOST}" -u"${MYSQL_USER}" -p"${MYSQL_PASSWORD}" "${MYSQL_DATABASE}" "$@"
else
# Read from stdin, ex: bin/mysql < dbdump.sql
bin/clinotty mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
bin/clinotty mysql -h"${MYSQL_HOST}" -u"${MYSQL_USER}" -p"${MYSQL_PASSWORD}" "${MYSQL_DATABASE}" "$@"
fi
2 changes: 2 additions & 0 deletions compose/bin/pwa-studio
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
set -o errexit

if [ ! -d pwa-studio ]; then
echo "PWA studio must first be installed by running bin/setup-pwa-studio"
exit
Expand Down
12 changes: 6 additions & 6 deletions compose/bin/removevolumes
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
current_folder=${PWD##*/}
volume_prefix=`echo $current_folder | awk '{print tolower($0)}' | sed 's/\.//g'`
docker volume rm ${volume_prefix}_appdata
docker volume rm ${volume_prefix}_dbdata
docker volume rm ${volume_prefix}_rabbitmqdata
docker volume rm ${volume_prefix}_sockdata
docker volume rm ${volume_prefix}_ssldata
volume_prefix=$(echo "$current_folder" | awk '{print tolower($0)}' | sed 's/\.//g')
docker volume rm "${volume_prefix}"_appdata
docker volume rm "${volume_prefix}"_dbdata
docker volume rm "${volume_prefix}"_rabbitmqdata
docker volume rm "${volume_prefix}"_sockdata
docker volume rm "${volume_prefix}"_ssldata
16 changes: 9 additions & 7 deletions compose/bin/setup
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
set -o errexit

# shellcheck source=../env/db.env
source env/db.env
BASE_URL=${1:-magento2.test}

Expand Down Expand Up @@ -33,12 +35,12 @@ bin/clinotty timeout 30 bash -c "
[ $? != 0 ] && echo "Failed to connect to Elasticsearch" && exit

bin/clinotty bin/magento setup:install \
--db-host=$MYSQL_HOST \
--db-name=$MYSQL_DATABASE \
--db-user=$MYSQL_USER \
--db-password=$MYSQL_PASSWORD \
--base-url=https://$BASE_URL/ \
--base-url-secure=https://$BASE_URL/ \
--db-host="$MYSQL_HOST" \
--db-name="$MYSQL_DATABASE" \
--db-user="$MYSQL_USER" \
--db-password="$MYSQL_PASSWORD" \
--base-url=https://"$BASE_URL"/ \
--base-url-secure=https://"$BASE_URL"/ \
--backend-frontname=admin \
--admin-firstname=John \
--admin-lastname=Smith \
Expand Down Expand Up @@ -87,7 +89,7 @@ bin/copyfromcontainer app
bin/copyfromcontainer vendor

echo "Generating SSL certificate..."
bin/setup-ssl $BASE_URL
bin/setup-ssl "$BASE_URL"

echo "Docker development environment setup complete."
echo "You may now access your Magento instance at https://${BASE_URL}/"
18 changes: 9 additions & 9 deletions compose/bin/setup-composer-auth
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ elif [ $USE_PYTHON3 ]; then
PY3_PASS="import sys, json; print(json.load(sys.stdin)['http-basic']['repo.magento.com']['password'])"

if [ -f "$GLOBAL_AUTH" ]; then
PUBLIC_KEY=$(cat "$GLOBAL_AUTH" | python3 -c "$PY3_USER" 2>/dev/null)
PRIVATE_KEY=$(cat "$GLOBAL_AUTH" | python3 -c "$PY3_USER" 2>/dev/null)
PUBLIC_KEY=$(python3 -c "$PY3_USER" 2>/dev/null < "$GLOBAL_AUTH")
PRIVATE_KEY=$(python3 -c "$PY3_USER" 2>/dev/null < "$GLOBAL_AUTH")
fi

if [ -z "$PUBLIC_KEY" ] || [ -z "$PRIVATE_KEY" ]; then
if [ -f "$PROJECT_AUTH" ]; then
PUBLIC_KEY=$(cat "$PROJECT_AUTH" | python3 -c "$PY3_USER" 2>/dev/null)
PRIVATE_KEY=$(cat "$PROJECT_AUTH" | python3 -c "$PY3_PASS" 2>/dev/null)
PUBLIC_KEY=$(python3 -c "$PY3_USER" 2>/dev/null < "$PROJECT_AUTH")
PRIVATE_KEY=$(python3 -c "$PY3_PASS" 2>/dev/null < "$PROJECT_AUTH")
NEED_AUTH=true
fi
fi
Expand All @@ -49,8 +49,8 @@ if [ -z "$PUBLIC_KEY" ] || [ -z "$PRIVATE_KEY" ]; then
exec < /dev/tty
echo
echo " Authentication required (repo.magento.com, public_key and private_key):"
read -p " Username: " PUBLIC_KEY
read -p " Password: " PRIVATE_KEY
read -r -p " Username: " PUBLIC_KEY
read -r -p " Password: " PRIVATE_KEY
echo
exec <&-
fi
Expand All @@ -62,7 +62,7 @@ fi
# For docker-compose.yml setting: ~/.composer:/var/www/.composer:cached
echo "Authentication will add to host composer global config ($GLOBAL_AUTH) for docekr container"
if [ $USE_COMPOSER ]; then
composer global config http-basic.repo.magento.com $PUBLIC_KEY $PRIVATE_KEY
composer global config http-basic.repo.magento.com "$PUBLIC_KEY" "$PRIVATE_KEY"
elif [ $USE_PYTHON3 ]; then
PY3_MERGE_AUTH="""
import sys, json;
Expand All @@ -89,11 +89,11 @@ def merge(src, dest):
print(json.dumps(merge(auth, data), indent=4))
"""
if [ -f "$GLOBAL_AUTH" ]; then
mkdir -p $(dirname "$GLOBAL_AUTH")
mkdir -p "$(dirname "$GLOBAL_AUTH")"
echo "{}" > "$GLOBAL_AUTH"
fi
mv "$GLOBAL_AUTH" "$GLOBAL_AUTH.bak"
cat "$GLOBAL_AUTH.bak" | python3 -c "$PY3_MERGE_AUTH" > "$GLOBAL_AUTH"
python3 -c "$PY3_MERGE_AUTH" > "$GLOBAL_AUTH" < "$GLOBAL_AUTH.bak"
fi

echo "Success to setup composer auth"
6 changes: 3 additions & 3 deletions compose/bin/setup-grunt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash
DEFAULT_THEME_ID="select value from core_config_data where path = 'design/theme/theme_id'"
THEME_PATH="select theme_path from theme where theme_id in ($DEFAULT_THEME_ID);"
VENDOR_THEME=`bin/n98-magerun2 db:query "$THEME_PATH" | sed -n 2p | cut -d$'\r' -f1`
THEME=`echo $VENDOR_THEME | cut -d'/' -f2`
VENDOR_THEME=$(bin/n98-magerun2 db:query "$THEME_PATH" | sed -n 2p | cut -d$'\r' -f1)
THEME=$(echo "$VENDOR_THEME" | cut -d'/' -f2)

# Generate local-theme.js for custom theme
read -d '' GEN_THEME_JS << EOM
read -r -d '' GEN_THEME_JS << EOM
var fs = require('fs');
var util = require('util');
var theme = require('./dev/tools/grunt/configs/themes');
Expand Down
8 changes: 5 additions & 3 deletions compose/bin/setup-integration-tests
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/bin/bash

# shellcheck source=../env/db.env
source env/db.env

MYSQL_INTEGRATION_CONFIG=dev/tests/integration/etc/install-config-mysql.php

# If database doesn't exist create it and add user permissions
bin/clinotty mysql -h${MYSQL_INTEGRATION_HOST} -uroot -p${MYSQL_ROOT_PASSWORD} ${MYSQL_INTEGRATION_DATABASE} -e exit &> /dev/null ||
bin/clinotty mysqladmin -h${MYSQL_INTEGRATION_HOST} -uroot -p${MYSQL_ROOT_PASSWORD} create ${MYSQL_INTEGRATION_DATABASE} &&
bin/clinotty mysql -h"${MYSQL_INTEGRATION_HOST}" -uroot -p"${MYSQL_ROOT_PASSWORD}" "${MYSQL_INTEGRATION_DATABASE}" -e exit &> /dev/null ||
bin/clinotty mysqladmin -h"${MYSQL_INTEGRATION_HOST}" -uroot -p"${MYSQL_ROOT_PASSWORD}" create "${MYSQL_INTEGRATION_DATABASE}" &&
echo "Database ${MYSQL_INTEGRATION_DATABASE} created." &&
bin/cli mysql -uroot -p${MYSQL_ROOT_PASSWORD} -h${MYSQL_INTEGRATION_HOST} \
bin/cli mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" -h"${MYSQL_INTEGRATION_HOST}" \
-e "GRANT ALL PRIVILEGES ON ${MYSQL_INTEGRATION_DATABASE}.* TO '${MYSQL_INTEGRATION_USER}'@'%';FLUSH PRIVILEGES;"

sed -e "s/'db-host' => 'localhost'/'db-host' => '${MYSQL_INTEGRATION_HOST}'/" \
Expand Down
1 change: 1 addition & 0 deletions compose/bin/setup-pwa-studio
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -o errexit
echo "Install NodeJS and Yarn on host machine, otherwise setup will fail"

BASE_URL=${1:-master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud}
Expand Down
2 changes: 1 addition & 1 deletion compose/bin/setup-ssl-ca
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -o errexit
# Generate a new local CA "/root/.local/share/mkcert"
docker-compose exec -T -u root app mkcert -install

docker cp $(docker-compose ps -q app|awk '{print $1}'):/root/.local/share/mkcert/rootCA.pem .
docker cp "$(docker-compose ps -q app|awk '{print $1}')":/root/.local/share/mkcert/rootCA.pem .
echo "System password requested to install certificate authority on host..."

if [ "$(uname)" == "Darwin" ]; then
Expand Down
21 changes: 13 additions & 8 deletions compose/bin/start
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,42 @@ set -o errexit

# Ref: https://stackoverflow.com/a/51789677/9821321
function parseYaml {
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
local s
local w
local fs
s='[[:space:]]*'
w='[a-zA-Z0-9_]*'
fs=$(echo @|tr @ '\034')
sed -ne "s|,$s\]$s\$|]|" \
-e "s|^\($s\)\($w\)$s:$s\[$s\(.*\)$s\]|\1\2:\n\1 - \3|;p" $1 | \
-e "s|^\($s\)\($w\)$s:$s\[$s\(.*\)$s\]|\1\2:\n\1 - \3|;p" "$1" | \
sed -ne "s|,$s}$s\$|}|" \
-e "s|^\($s\)-$s{$s\(.*\)$s}|\1-\n\1 \2|;p" | \
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)-$s[\"']\(.*\)[\"']$s\$|\1$fs$fs\2|p" \
-e "s|^\($s\)-$s{[\"']\(.*\)[\"']}$s\$|\1$fs$fs\2|p" \
-e "s|^\($s\)-$s\(.*\)$s\$|\1$fs$fs\2|p" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s{[\"']\(.*\)[\"']}$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" | \
awk -F$fs '{
awk -F"$fs" '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]; idx[i]=0}}
if (length($2) == 0) {vname[indent] = ++idx[indent] };
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn = (vn)(vname[i])("_")}
if ("'$2'_" == vn) {
if ("'"$2"'_" == vn) {
print substr($3 ,1 , match($3,":")-1)
}
}
}'
}

# Check if volume files exist to avoid creating an empty folder
VOLUME_LIST=`parseYaml docker-compose.dev.yml services_app_volumes`
VOLUME_LIST=$(parseYaml docker-compose.dev.yml services_app_volumes)
IGNORE_LIST="./src/app/code ./src/m2-hotfixes ./src/patches ./src/var/log ./src/var/report ./src"
IS_VALID=true
# Loop through all files missing from the docker-compose.dev.yml file
for file in $VOLUME_LIST; do
if [ ! -e $file ] && [[ ! " $IGNORE_LIST " =~ " $file " ]]; then
if [ ! -e "$file" ] && [[ ! " $IGNORE_LIST " =~ $file ]]; then
echo "$file: No such file or directory"
IS_VALID=false
fi
Expand Down
3 changes: 2 additions & 1 deletion compose/bin/update
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
mkdir -p tmpupdate && cd $_
set -o errexit
mkdir -p tmpupdate && cd "$_"
curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
rm -rf .git
rsync -av ./ ../
Expand Down
2 changes: 1 addition & 1 deletion compose/bin/xdebug
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ xdebug_disable() {
fi
}

firstArgLetter="$(echo $1 | head -c 1)"
firstArgLetter="$(echo "$1" | head -c 1)"

if [[ $firstArgLetter == "d" ]]; then
xdebug_disable
Expand Down