Skip to content

Commit d6465ab

Browse files
committed
remove shell lint with shellcheck
1 parent 10e5111 commit d6465ab

13 files changed

+567
-794
lines changed

bin/awscli.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html#cliv2-mac-install-cmd
55
# see also https://formulae.brew.sh/formula/awscli#default
66

7-
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
8-
sudo installer -pkg AWSCLIV2.pkg -target /
7+
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIv2.pkg"
8+
sudo installer -pkg AWSCLIv2.pkg -target /
99

1010
# Verify the installation
11-
which aws
11+
command -v aws
1212
aws --version

bin/megalinter-local.sh

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,45 @@ FLAVOR="terraform" # check that this matches the flavor specified in .gitlab-ci.
77

88
# detect if node.js is installed
99
NODE_VERSION=$(node --version)
10-
if [ "X$NODE_VERSION" = "X" ]; then
11-
echo "ERROR: node.js is required, but was not found installed."
12-
echo " Consider installing via 'brew install node'."
13-
exit 13
10+
if [[ "X${NODE_VERSION}" = "X" ]]; then
11+
echo "ERROR: node.js is required, but was not found installed."
12+
echo " Consider installing via 'brew install node'."
13+
exit 13
1414
else
15-
echo "Confirmed node $NODE_VERSION is available."
15+
echo "Confirmed node ${NODE_VERSION} is available."
1616
fi
1717

1818
# detect if docker is installed and running
1919
DOCKER_VERSION=$(docker --version)
20-
if [ "X$DOCKER_VERSION" = "X" ]; then
21-
echo "ERROR: Docker is required, but was not found installed."
22-
echo " Consider installing via 'brew install docker'."
23-
exit 23
20+
if [[ "X${DOCKER_VERSION}" = "X" ]]; then
21+
echo "ERROR: Docker is required, but was not found installed."
22+
echo " Consider installing via 'brew install docker'."
23+
exit 23
2424
else
25-
DOCKER_RUNNING=$(pgrep -f Docker.app)
26-
if [ "X$DOCKER_RUNNING" = "X" ]; then
27-
echo "WARNING: Docker is installed, but was not found running."
28-
echo " Starting Docker (open -a 'Docker Desktop')"
29-
open -a 'Docker Desktop'
30-
sleep 12
31-
# exit 29
32-
else
33-
echo "Confirmed $DOCKER_VERSION is running."
34-
fi
25+
DOCKER_RUNNING=$(pgrep -f Docker.app)
26+
if [[ "X${DOCKER_RUNNING}" = "X" ]]; then
27+
echo "WARNING: Docker is installed, but was not found running."
28+
echo " Starting Docker (open -a 'Docker Desktop')"
29+
open -a 'Docker Desktop'
30+
sleep 12
31+
# exit 29
32+
else
33+
echo "Confirmed ${DOCKER_VERSION} is running."
34+
fi
3535
fi
3636

3737
# Run mega-linter -- in config setup mode, if needed
38-
if [ -f ".mega-linter.yml" ]; then
39-
echo "Loading config from .mega-linter.yml ..."
40-
echo ""
41-
npx mega-linter-runner --flavor $FLAVOR \
42-
-e 'LOG_LEVEL=INFO'
38+
if [[ -f ".mega-linter.yml" ]]; then
39+
echo "Loading config from .mega-linter.yml ..."
40+
echo ""
41+
npx mega-linter-runner --flavor "${FLAVOR}" \
42+
-e 'LOG_LEVEL=INFO'
4343
else
44-
echo ""
45-
echo "Setting up .mega-linter.yml."
46-
npx mega-linter-runner --install
47-
echo ""
48-
echo "Done."
49-
echo " Run this script again to invoke mega-linter with these new settings."
50-
echo ""
44+
echo ""
45+
echo "Setting up .mega-linter.yml."
46+
npx mega-linter-runner --install
47+
echo ""
48+
echo "Done."
49+
echo " Run this script again to invoke mega-linter with these new settings."
50+
echo ""
5151
fi

bin/setup-megalinter.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ UNAME="$(uname -s)"
1313

1414
if ! [[ ${UNAME} =~ "Darwin" ]]; then
1515
# Confirm or install dependencies as necessary
16-
echo "Error: This script is intended for MacOS, but was found to be running on $UNAME"
16+
echo "Error: This script is intended for MacOS, but was found to be running on ${UNAME}"
1717
exit
1818
fi
1919

gitlab/gitlab-bulk-import.sh

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@
1111
API_URI='https://subsplash.io/api/v4'
1212
WEB_URI='https://subsplash.io'
1313

14+
# Organization or Username for the source repository
15+
# Used in the SOURCE_URL and REF_URL
16+
SOURCE_ORG='snappages'
17+
1418
# Check for a valid GitLab Personal Access Token to authenticate / authorize API calls
1519
if [[ -z ${GITLAB_TOKEN} ]]; then
20+
# shellcheck disable=SC2016
1621
echo 'Error: No $GITLAB_TOKEN was found.'
1722
exit
1823
fi
1924

2025
# Check for valid credentials to source system; these variables are used later
2126
if [[ -z ${GITHUB_USER} ]]; then
27+
# shellcheck disable=SC2016
2228
echo 'Error: $GITHUB_USER was Not found.'
2329
echo "If authentication is not required for this source SCM, edit this script and try again."
2430
exit
2531
fi
2632

2733
if [[ -z ${GITHUB_TOKEN} ]]; then
34+
# shellcheck disable=SC2016
2835
echo 'Error: $GITHUB_TOKEN was Not found.'
2936
echo "If authentication is not required for this source SCM, edit this script and try again."
3037
exit
@@ -44,29 +51,29 @@ GROUP_ID=233
4451
# Source project URL
4552
# Note: include https auth in SOURCE_URL if necessary (otherwise, forego "<USERNAME>:<PASSWORD>@")
4653
# Example: https://<USERNAME>:<PASSWORD>@github.com/path/to/repo.git
47-
SOURCE_URL="https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/snappages/"
48-
# SOURCE_URL="https://github.com/snappages/"
54+
SOURCE_URL="https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${SOURCE_ORG}/"
55+
# SOURCE_URL="https://github.com/${SOURCE_ORG}/"
4956

5057
# Project Description
5158
# The REF_URL should match the SOURCE_URL, without any user or token, so it can be included in
5259
# the target project description. See `--form description="Cloned from ${REF_URL}${REPO}" \`
53-
REF_URL="https://github.com/snappages/"
60+
REF_URL="https://github.com/${SOURCE_ORG}/"
5461

5562
# space-delimited list of repositories available from the SOURCE_URL
56-
REPOLIST="${@}"
63+
REPOLIST=( "${@}" )
5764

58-
for REPO in ${REPOLIST}; do
65+
for REPO in "${REPOLIST[@]}"; do
5966

6067
echo "Cloning git repository ${REPO} to ${WEB_URI}/projects/${REPO}/"
6168

6269
IMPORT=$(curl --request POST \
63-
--url $API_URI/projects \
70+
--url "${API_URI}"/projects \
6471
--header 'Content-Type: multipart/form-data;' \
6572
--header "Authorization: Bearer ${GITLAB_TOKEN}" \
6673
--form description="Cloned from ${REF_URL}${REPO}" \
6774
--form import_url="${SOURCE_URL}${REPO}.git" \
68-
--form mirror=${MIRROR} \
69-
--form namespace_id=${GROUP_ID} \
75+
--form mirror="${MIRROR}" \
76+
--form namespace_id="${GROUP_ID}" \
7077
--form path="${REPO}" \
7178
--form allow_merge_on_skipped_pipeline=false \
7279
--form analytics_access_level=disabled \
@@ -97,7 +104,7 @@ for REPO in ${REPOLIST}; do
97104

98105
# access properties in JSON structure of $IMPORT results
99106
echo ""
100-
echo "Cloned project to $(echo ${IMPORT} | jq '.web_url')"
107+
echo "Cloned project to $(echo "${IMPORT}" | jq '.web_url')"
101108
ID=$(echo "${IMPORT}" | jq '.id')
102109

103110
# pause for a moment, before trying to archive the newly imported project
@@ -126,9 +133,9 @@ exit
126133

127134
# GitHub API notes:
128135
# List repositories for an Org
129-
curl https://$GITHUB_USER:$GITHUB_TOKEN@api.github.com/orgs/snappages/repos | jq '.[].name'
136+
# curl https://"${GITHUB_USER}":"${GITHUB_TOKEN}"@api.github.com/orgs/${SOURCE_ORG}/repos | jq '.[].name'
130137

131-
curl https://$GITHUB_USER:$GITHUB_TOKEN@api.github.com/snappages/
132-
curl -I https://api.github.com/users/octocat/orgs
138+
# curl https://"${GITHUB_USER}":"${GITHUB_TOKEN}"@api.github.com/${SOURCE_ORG}/
139+
# curl -I https://api.github.com/users/octocat/orgs
133140

134-
curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com
141+
# curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com

gitlab/gitlab-proj-runner-settings.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
API_URI='https://subsplash.io/api/v4'
2020
WEB_URI='https://subsplash.io'
2121

22-
if [[ -z $@ ]]; then
22+
if [[ -z "$@" ]]; then
2323
echo ''
2424
echo "Error: No Project was specified."
2525
echo ''
@@ -34,7 +34,8 @@ if [[ -z $@ ]]; then
3434
fi
3535

3636
# Check for a valid GitLab Personal Access Token to authenticate / authorize API calls
37-
if [[ -z $GITLAB_TOKEN ]]; then
37+
if [[ -z ${GITLAB_TOKEN} ]]; then
38+
# shellcheck disable=SC2016
3839
echo 'Error: No $GITLAB_TOKEN was found.'
3940
exit
4041
fi
@@ -48,16 +49,16 @@ fi
4849
# space-delimited list of projects to apply the settings to
4950
# Can be a numerical Project ID or a URL-encoded URI
5051
# https://docs.gitlab.com/ee/api/README.html#namespaced-path-encoding
51-
PROJLIST=$@
52+
PROJLIST=( "${@}" )
5253

53-
for PROJ in $PROJLIST; do
54+
for PROJ in "${PROJLIST[@]}"; do
5455

5556
echo ''
5657
echo "Updating CI Runner settings for ${WEB_URI}/projects/${PROJ}/"
5758
echo ''
5859

5960
curl --silent --request GET \
60-
--header "Authorization: Bearer $GITLAB_TOKEN" \
61+
--header "Authorization: Bearer ${GITLAB_TOKEN}" \
6162
"${API_URI}/projects/${PROJ}/runners" #\
6263
# | jq '. | {id,name,description,web_url}'
6364

@@ -95,6 +96,7 @@ for PROJ in $PROJLIST; do
9596
# | jq '. | {id,web_url}'
9697

9798
done
99+
98100
exit
99101

100102
# Scratchpad area of other, related, possibly useful gitlab API samples

gitlab/gitlab-project-settings.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ WEB_URI='https://subsplash.io'
2121

2222
# Check for a valid GitLab Personal Access Token to authenticate / authorize API calls
2323
if [[ -z ${GITLAB_TOKEN} ]]; then
24+
# shellcheck disable=SC2016
2425
echo 'Error: No $GITLAB_TOKEN was found.'
2526
exit
2627
fi
@@ -34,25 +35,25 @@ fi
3435
# space-delimited list of projects to apply the settings to
3536
# Can be a numerical Project ID or a URL-encoded URI
3637
# https://docs.gitlab.com/ee/api/README.html#namespaced-path-encoding
37-
PROJLIST=$@
38+
PROJLIST=( "${@}" )
3839

39-
for PROJ in ${PROJLIST}; do
40+
for PROJ in "${PROJLIST[@]}"; do
4041

4142
echo ''
4243
echo "Updating settings for ${WEB_URI}/projects/${PROJ}/"
4344
echo ''
4445

4546
# RFE / TODO: get current Description. If blank, parse README for Description text
4647
curl --silent --request GET \
47-
--header "Authorization: Bearer $GITLAB_TOKEN" \
48+
--header "Authorization: Bearer ${GITLAB_TOKEN}" \
4849
"${API_URI}/projects/${PROJ}" |
4950
jq '. | {id,name,description,web_url}'
5051

5152
# Project settings are specified in form entries on their own line
5253
# Sorted in alphabetical order
5354
curl --silent --request PUT "${API_URI}/projects/${PROJ}" \
5455
--header 'Content-Type: multipart/form-data;' \
55-
--header "Authorization: Bearer $GITLAB_TOKEN" \
56+
--header "Authorization: Bearer ${GITLAB_TOKEN}" \
5657
--form allow_merge_on_skipped_pipeline=false \
5758
--form analytics_access_level=disabled \
5859
--form approvals_before_merge=1 \
@@ -91,7 +92,7 @@ for PROJ in ${PROJLIST}; do
9192
# 40 => Maintainer access
9293
# 60 => Admin access
9394
curl --silent --request POST \
94-
--header "Authorization: Bearer $GITLAB_TOKEN" \
95+
--header "Authorization: Bearer ${GITLAB_TOKEN}" \
9596
"${API_URI}/projects/${PROJ}/protected_branches/?name=main&push_access_level=60&merge_access_level=30&unprotect_access_level=60&code_owner_approval_required=true" |
9697
jq '. | {message}'
9798

@@ -101,7 +102,7 @@ for PROJ in ${PROJLIST}; do
101102
# https://docs.gitlab.com/ee/api/merge_request_approvals.html
102103
# approvals_before_merge is set above for the project
103104
curl --silent --request POST \
104-
--header "Authorization: Bearer $GITLAB_TOKEN" \
105+
--header "Authorization: Bearer ${GITLAB_TOKEN}" \
105106
"${API_URI}/projects/${PROJ}/approvals?merge_requests_author_approval=true&reset_approvals_on_push=true" |
106107
jq '. | {approvals_before_merge}'
107108

gitlab/gitlab-stats-analyze.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#!/usr/bin/env bash
22

3-
cd ~/repo/GitStats
3+
cd ~/repo/GitStats || exit
44

55
#for file in $(find ./3p -name "*.csv"); do echo $file; done
66

77
for DIR in $(ls -d *); do
8-
printf "INFO: Working in $DIR ...\n"
8+
printf "INFO: Working in %S ...\n" "${DIR}"
99

10-
find $DIR -name "*.csv"
11-
for file in $(find $DIR -name "*.csv"); do
12-
echo "cat file: $file"
13-
cat $file >>GitLab_stats.txt
14-
done
15-
# echo "break"
16-
# break
10+
find $DIR -mtime -7 -name '*.csv' -print0 | while IFS= read -r -d '' file
11+
for file in $(find $DIR -name "*.csv"); do
12+
echo "cat file: $file"
13+
cat $file >> GitLab_stats.txt
14+
done
15+
# echo "break"
16+
# break
1717
done
1818

1919
exit 0

0 commit comments

Comments
 (0)