Skip to content

Commit fcea71d

Browse files
committed
[scripts] shellcheck fixes
1 parent b55a19a commit fcea71d

18 files changed

+112
-68
lines changed

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ before_script:
2020
- nodejs --version
2121
- ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --version
2222
- cat ${PWD}/mongod.log
23-
script: sudo npm test
23+
script:
24+
- countly shellcheck
25+
- sudo npm test
2426
after_script:
2527
- cat log/countly-api.log
2628
- cat log/countly-dashboard.log

bin/backup/run.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
cd "$(dirname "$0")"
1818

1919
function check_connectivity_mongo() {
20-
local MONGO_OK=$(mongo \
20+
local MONGO_OK;
21+
MONGO_OK=$(mongo \
2122
--quiet \
2223
--eval "db.serverStatus().ok == true")
2324

@@ -32,16 +33,16 @@ function check_connectivity_mongo() {
3233
# generic check connectivity function
3334
function check_connectivity() {
3435
retries=600
35-
until eval "check_connectivity_$@"; do
36+
until eval "check_connectivity_$*"; do
3637
sleep 1
3738
let retries--
3839
if [ $retries == 0 ]; then
39-
echo "time out while waiting for $@ is ready"
40+
echo "time out while waiting for $* is ready"
4041
exit 1
4142
fi
42-
echo "$@ is not reachable yet, trying again..."
43+
echo "$* is not reachable yet, trying again..."
4344
done
44-
echo "$@ is up and running..."
45+
echo "$* is up and running..."
4546
}
4647

4748
# wait till mongo becomes online.

bin/commands/countly.sh

+43-16
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ run_upgrade (){
5050
else
5151
echo "Upgrading versions: $1";
5252
fi
53-
arr=$@;
53+
arr=("$@");
5454
for i in ${1//;/ }
5555
do
5656
if [[ $2 == "fs" ]]
@@ -63,7 +63,7 @@ run_upgrade (){
6363
continue
6464
fi
6565
fi
66-
bash "$DIR/../upgrade/$i/upgrade_fs.sh";
66+
#bash "$DIR/../upgrade/$i/upgrade_fs.sh";
6767
else
6868
echo "No filesystem upgrade script provided for $i";
6969
fi
@@ -101,6 +101,11 @@ countly_upgrade (){
101101
arr=("$@");
102102
if [[ " ${arr[*]} " == *" -y "* ]]; then
103103
y="-y";
104+
for arg do
105+
shift
106+
[ "$arg" = "-y" ] && continue
107+
set -- "$@" "$arg"
108+
done
104109
fi
105110
countly_root ;
106111
if [ $# -eq 0 ]
@@ -183,8 +188,8 @@ countly_upgrade (){
183188
(cd "$DIR/../..";
184189
tar xaf countly-enterprise-edition*.tar.gz --strip=1 countly;)
185190

186-
EE_PLUGINS=$(cat "$DIR/../../plugins/plugins.ee.json" | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g')
187-
CE_PLUGINS=$(cat "$DIR/../../plugins/plugins.ce.json" | sed 's/\"//g' | sed 's/\[//g' | sed 's/\]//g')
191+
EE_PLUGINS=$(sed 's/\"//g' "$DIR/../../plugins/plugins.ee.json" | sed 's/\[//g' | sed 's/\]//g')
192+
CE_PLUGINS=$(sed 's/\"//g' "$DIR/../../plugins/plugins.ce.json" | sed 's/\[//g' | sed 's/\]//g')
188193
PLUGINS_DIFF=$(echo " ${EE_PLUGINS}, ${CE_PLUGINS}" | tr ',' '\n' | sort | uniq -u)
189194
echo "Enabling plugins..."
190195
for plugin in $PLUGINS_DIFF; do
@@ -297,8 +302,13 @@ countly_backupdb (){
297302
(mkdir -p "$1" ;
298303
cd "$1" ;
299304
echo "Backing up mongodb...";
300-
mongodump $(node $DIR/scripts/db.conf.js countly) > /dev/null;
301-
mongodump $(node $DIR/scripts/db.conf.js countly_drill) > /dev/null;
305+
shift
306+
#allow passing custom flags
307+
connection=( $(node "$DIR/scripts/db.conf.js") "${@}" );
308+
mongodump "${connection[@]}" --db countly > /dev/null;
309+
mongodump "${connection[@]}" --db countly_drill > /dev/null;
310+
mongodump "${connection[@]}" --db countly_fs > /dev/null;
311+
mongodump "${connection[@]}" --db countly_out > /dev/null;
302312
)
303313
}
304314

@@ -333,13 +343,13 @@ countly_save (){
333343
if [ -f "$1" ]
334344
then
335345
match=false
336-
files=$(ls "$2" | wc -l)
346+
files=$(find "$2" -maxdepth 1 -type f -printf x | wc -c)
337347

338-
if [ $files -gt 0 ]
348+
if [ "$files" -gt 0 ]
339349
then
340350
for d in $2/*; do
341-
diff=$(diff $1 $d | wc -l)
342-
if [ $diff == 0 ]
351+
diff=$(diff "$1" "$d" | wc -l)
352+
if [ "$diff" == 0 ]
343353
then
344354
match=true
345355
break
@@ -348,7 +358,7 @@ countly_save (){
348358
fi
349359

350360
files=$((files+1))
351-
filebasename=$(basename $1)
361+
filebasename=$(basename "$1")
352362
if [ "$match" == false ]
353363
then
354364
cp -a "$1" "$2/${filebasename}.backup.${files}"
@@ -401,7 +411,7 @@ countly_restorefiles (){
401411
fi
402412

403413
for d in files/plugins/*; do
404-
PLUGIN=$(basename $d);
414+
PLUGIN=$(basename "$d");
405415
if [ -f "$d/config.js" ]; then
406416
mkdir -p "$DIR/../../plugins/$PLUGIN" ;
407417
cp "$d/config.js" "$DIR/../../plugins/$PLUGIN/config.js" ;
@@ -429,18 +439,35 @@ countly_restoredb (){
429439
echo "Please provide path" ;
430440
return 0;
431441
fi
442+
shift
443+
#allow passing custom flags
444+
connection=( $(node "$DIR/scripts/db.conf.js") "${@}" );
432445
if [ -d "$1/dump/countly" ]; then
433446
echo "Restoring countly database...";
434-
mongorestore $(node $DIR/scripts/db.conf.js countly) --batchSize=10 "$1/dump/countly" > /dev/null;
447+
mongorestore "${connection[@]}" --db countly --batchSize=10 "$1/dump/countly" > /dev/null;
435448
else
436449
echo "No countly database dump to restore from";
437450
fi
438451
if [ -d "$1/dump/countly_drill" ]; then
439452
echo "Restoring countly_drill database...";
440-
mongorestore $(node $DIR/scripts/db.conf.js countly_drill) --batchSize=10 "$1/dump/countly_drill" > /dev/null;
453+
mongorestore "${connection[@]}" --db countly_drill --batchSize=10 "$1/dump/countly_drill" > /dev/null;
441454
else
442455
echo "No countly_drill database dump to restore from";
443456
fi
457+
458+
if [ -d "$1/dump/countly_fs" ]; then
459+
echo "Restoring countly_fs database...";
460+
mongorestore "${connection[@]}" --db countly_fs --batchSize=10 "$1/dump/countly_fs" > /dev/null;
461+
else
462+
echo "No countly_fs database dump to restore from";
463+
fi
464+
465+
if [ -d "$1/dump/countly_out" ]; then
466+
echo "Restoring countly_out database...";
467+
mongorestore "${connection[@]}" --db countly_out --batchSize=10 "$1/dump/countly_out" > /dev/null;
468+
else
469+
echo "No countly_out database dump to restore from";
470+
fi
444471
}
445472

446473
countly_restore (){
@@ -465,9 +492,9 @@ source "$DIR/enabled/countly.sh"
465492
#process command
466493
NAME="$1";
467494
SCRIPT="$2";
468-
if [ -n "$(type -t countly_$1)" ] && [ "$(type -t countly_$1)" = function ]; then
495+
if [ -n "$(type -t "countly_$1")" ] && [ "$(type -t "countly_$1")" = function ]; then
469496
shift;
470-
countly_${NAME} "$@";
497+
"countly_${NAME}" "$@";
471498
elif [ -f "$DIR/scripts/$NAME.sh" ]; then
472499
shift;
473500
bash "$DIR/scripts/$NAME.sh" "$@";

bin/commands/launchd/install.sh

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash
22

3-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
4-
53
sudo cp /usr/local/Cellar/mongodb/2.2.0-x86_64/homebrew.mxcl.mongodb.plist /Library/LaunchDaemons/
64
sudo cp com.countly.dashboard.plist /Library/LaunchDaemons/
75
sudo cp com.countly.api.plist /Library/LaunchDaemons/

bin/commands/scripts/healthcheck/nginx.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
nginxpath="/var/log/nginx/error.log"
44
curdate=$(date "+%Y/%m/%d %H")
5-
errors=$(cat ${nginxpath} | grep "${curdate}" | wc -l);
5+
errors=$(grep "${curdate}" ${nginxpath} -c);
66

77
if [ "${errors}" -gt 0 ]; then
88
echo -e "You have $errors error(s) in the last hour in your nginx error.log";

bin/commands/scripts/healthcheck/permissions.sh

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
procowner="0"
44
fileowner=$(stat -c '%U' "$(countly dir)")
5+
# shellcheck disable=SC2009
56
paths=$(ps -ux | grep countly)
67
while read line; do
78
if [[ "$line" = *"dashboard node"* ]]; then

bin/commands/scripts/healthcheck/process.sh

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ workersthreshold=$(nproc)
3232
appproc=0
3333
apiproc=0
3434
workers=0
35+
# shellcheck disable=SC2009
3536
paths=$(ps -ax | grep countly)
3637
while read line; do
3738
if [[ "$line" = *"dashboard node"* ]]; then

bin/commands/scripts/shellcheck.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash
22
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33

4-
find $DIR/../../../ -type f -name "*.sh" -print |
4+
find "$DIR/../../../" -type f -name "*.sh" -print |
55
while IFS="" read -r file
66
do
7-
shellcheck "$file"
7+
if [[ $file != *"/node_modules/"* ]] && [[ $file != *"/core/"* ]] && [[ $file != *"/bin/scripts/nghttp2/"* ]]; then
8+
shellcheck "$file"
9+
fi
810
done

bin/config/countly_user.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fi
1818
yes | cp -rf "$DIR/supervisort.wuser.conf" "$COUNTLY_DIR/bin/config/supervisord.conf"
1919

2020
#check if user not created yet
21-
if [ $(getent passwd countly)x == 'x' ]; then
21+
if [ "$(getent passwd countly)x" == 'x' ]; then
2222

2323
#create countly user
2424
useradd -r -M -U -d "$COUNTLY_DIR" -s /bin/false countly

bin/countly.install_rhel.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ set +e
4040
NODE_JS_CMD=$(which nodejs)
4141
set -e
4242
if [[ -z "$NODE_JS_CMD" ]]; then
43-
ln -s $(which node) /usr/bin/nodejs
43+
ln -s "$(which node)" /usr/bin/nodejs
4444
fi
4545

4646
#install nginx
@@ -77,7 +77,10 @@ if grep -q -i "release 6" /etc/redhat-release ; then
7777
wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
7878
yum install -y devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils
7979
source /opt/rh/devtoolset-2/enable
80-
export CC=$(which gcc) CXX=$(which g++)
80+
CC="$(which gcc)"
81+
CXX="$(which g++)"
82+
export $CC
83+
export $CXX
8184
fi
8285

8386
#install grunt & npm modules
@@ -146,7 +149,7 @@ cd "$DIR/.." && grunt dist-all
146149
#finally start countly api and dashboard
147150
countly start
148151

149-
ENABLED=`getenforce`
152+
ENABLED=$(getenforce)
150153
if [ "$ENABLED" == "Enforcing" ]; then
151154
echo -e "\e[31mSELinux is enabled, please disable it or add nginx to exception for Countly to work properly\e[0m"
152155
fi

bin/docker/cmd.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ case "$COUNTLY_CONTAINER" in
1414
* )
1515
# Run custom command. Thanks to this line we can still use
1616
# "docker run our_image /bin/bash" and it will work
17-
exec $CMD ${@:2}
17+
exec "$CMD" "${@:2}"
1818
;;
1919
esac

bin/docker/preinstall.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

3-
for plugin in `find /opt/countly/plugins -type d -mindepth 1 -maxdepth 1`
3+
while IFS= read -r -d '' plugin
44
do
5-
echo "Installing $plugin..."
5+
echo "Installing $plugin..."
66
(cd "$plugin" && HOME=/tmp npm install)
77
echo "done"
8-
done
8+
done < <(find /opt/countly/plugins -type d -mindepth 1 -maxdepth 1)

bin/scripts/deploy.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_REPO_SLUG" == "Countly/countly-server" ]; then
44
if [ "$TRAVIS_BRANCH" == "master" ] || [ "$TRAVIS_BRANCH" == "next" ]; then
5-
openssl aes-256-cbc -K "$encrypted_2b5a1ad4da99_key" -iv "$encrypted_2b5a1ad4da99_iv" -in deploy-key.enc -out deploy-key -d;
5+
openssl aes-256-cbc -K "${encrypted_2b5a1ad4da99_key:?}" -iv "${encrypted_2b5a1ad4da99_iv:?}" -in deploy-key.enc -out deploy-key -d;
66
chmod 600 deploy-key;
77
mv deploy-key ~/.ssh/id_rsa;
8-
ssh -oStrictHostKeyChecking=no "countly@$TRAVIS_BRANCH.count.ly" "bash /home/countly/deploy.sh > /home/countly/logs/countly-deploy-$TRAVIS_BUILD_NUMBER-$TRAVIS_COMMIT.log 2>&1 &"
8+
ssh -oStrictHostKeyChecking=no "countly@$TRAVIS_BRANCH.count.ly" "bash /home/countly/deploy.sh > /home/countly/logs/countly-deploy-\$TRAVIS_BUILD_NUMBER-\$TRAVIS_COMMIT.log 2>&1 &"
99
fi
1010
fi

bin/scripts/detect.init.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ INITSYS="systemd"
77

88
if [ -z "$COUNTLY_CONTAINER" ]
99
then
10-
if [[ `/sbin/init --version` =~ upstart ]];
10+
if [[ $(/sbin/init --version) =~ upstart ]];
1111
then
1212
INITSYS="upstart"
1313
fi 2> /dev/null

bin/scripts/generateDocs.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
#Original source https://gist.github.com/vidavidorra/548ffbcdae99d752da02
44

@@ -30,7 +30,7 @@ git config user.email "[email protected]"
3030
# stayed the same and will only update the changed files. So the gh-pages branch
3131
# can be safely cleaned, and it is sure that everything pushed later is the new
3232
# documentation.
33-
rm -rf *
33+
rm -rf ./*
3434

3535
# Need to create a .nojekyll file to allow filenames starting with an underscore
3636
# to be seen on the gh-pages site. Therefore creating an empty .nojekyll file.

0 commit comments

Comments
 (0)