Skip to content

Commit b8707f6

Browse files
committed
[shellcheck] fixes
1 parent 2032f2a commit b8707f6

28 files changed

+72
-208
lines changed

.shellcheckrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
disable=SC2230
2+
disable=SC2236
3+
disable=SC2164
4+
disable=SC2237
5+
disable=SC2002

bin/backup/run.sh

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ cd "$(dirname "$0")"
1818

1919
function check_connectivity_mongo() {
2020
local MONGO_OK;
21-
MONGO_OK=$(mongo \
22-
--quiet \
23-
--eval "db.serverStatus().ok == true")
2421

25-
if [[ $? != 0 || "$MONGO_OK" != true ]]; then
22+
if MONGO_OK=$(mongo --quiet --eval "db.serverStatus().ok == true") || [[ "$MONGO_OK" != true ]]; then
2623
echo "error: mongodb service check failed"
2724
return 1
2825
fi
@@ -35,7 +32,7 @@ function check_connectivity() {
3532
retries=600
3633
until eval "check_connectivity_$*"; do
3734
sleep 1
38-
let retries--
35+
(( retries-- ))
3936
if [ $retries == 0 ]; then
4037
echo "time out while waiting for $* is ready"
4138
exit 1

bin/commands/countly.sh

+24-18
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ run_upgrade (){
5858
if [ -f "$DIR/../upgrade/$i/upgrade_fs.sh" ]; then
5959
if [[ " ${arr[*]} " != *" -y "* ]]; then
6060
echo "Upgrading filesystem for $i. y/n?";
61-
read choice;
61+
read -r choice;
6262
if [ "$choice" != "y" ]; then
6363
continue
6464
fi
@@ -72,7 +72,7 @@ run_upgrade (){
7272
if [ -f "$DIR/../upgrade/$i/upgrade_db.sh" ]; then
7373
if [[ " ${arr[*]} " != *" -y "* ]]; then
7474
echo "Upgrading database for $i. y/n?";
75-
read choice;
75+
read -r choice;
7676
if [ "$choice" != "y" ]; then
7777
continue
7878
fi
@@ -85,7 +85,7 @@ run_upgrade (){
8585
if [ -f "$DIR/../upgrade/$i/upgrade.sh" ]; then
8686
if [[ " ${arr[*]} " != *" -y "* ]]; then
8787
echo "Upgrading for $i. y/n?";
88-
read choice;
88+
read -r choice;
8989
if [ "$choice" != "y" ]; then
9090
continue
9191
fi
@@ -114,7 +114,7 @@ countly_upgrade (){
114114

115115
if [ "$INOFFLINEMODE" == "false" ]
116116
then
117-
(cd $DIR/../..;
117+
(cd "$DIR"/../..;
118118
echo "Installing dependencies...";
119119
sudo npm install;)
120120
fi
@@ -127,8 +127,7 @@ countly_upgrade (){
127127
)
128128
elif [ "$1" == "auto" ]
129129
then
130-
UPGRADE=$(nodejs "$DIR/../scripts/checking_versions.js");
131-
if [ $? -eq 0 ]
130+
if UPGRADE=$(nodejs "$DIR/../scripts/checking_versions.js");
132131
then
133132
run_upgrade "$UPGRADE" "$2" "$y";
134133
else
@@ -140,16 +139,20 @@ countly_upgrade (){
140139
then
141140
if [ "$2" == "fs" ] || [ "$2" == "db" ]
142141
then
143-
UPGRADE=$(nodejs "$DIR/../scripts/checking_versions.js" "$3" "$4");
142+
if UPGRADE=$(nodejs "$DIR/../scripts/checking_versions.js" "$3" "$4")
143+
then
144+
run_upgrade "$UPGRADE" "$2" "$y";
145+
else
146+
echo "$UPGRADE";
147+
fi
144148
elif [ $# -ge 3 ]
145149
then
146-
UPGRADE=$(nodejs "$DIR/../scripts/checking_versions.js" "$2" "$3");
147-
fi
148-
if [ $? -eq 0 ]
149-
then
150-
run_upgrade "$UPGRADE" "$2" "$y";
151-
else
152-
echo "$UPGRADE";
150+
if UPGRADE=$(nodejs "$DIR/../scripts/checking_versions.js" "$2" "$3")
151+
then
152+
run_upgrade "$UPGRADE" "$2" "$y";
153+
else
154+
echo "$UPGRADE";
155+
fi
153156
fi
154157
else
155158
echo "Provide upgrade version in format:";
@@ -338,7 +341,7 @@ countly_backupfiles (){
338341
cp -a "$DIR/../../frontend/express/certificates/." files/frontend/express/certificates/
339342
fi
340343

341-
for d in $DIR/../../plugins/*; do
344+
for d in "$DIR"/../../plugins/*; do
342345
PLUGIN="$(basename "$d")";
343346
if [ -f "$d/config.js" ]; then
344347
mkdir -p "files/plugins/$PLUGIN" ;
@@ -367,7 +370,8 @@ countly_backupdb (){
367370
echo "Backing up mongodb...";
368371
shift
369372
#allow passing custom flags
370-
connection=( $(node "$DIR/scripts/db.conf.js") "${@}" );
373+
IFS=" " read -r -a con <<< "$(node "$DIR/scripts/db.conf.js")"
374+
connection=( "${con[@]}" "${@}" );
371375
mongodump "${connection[@]}" --db countly > /dev/null;
372376
mongodump "${connection[@]}" --db countly_drill > /dev/null;
373377
mongodump "${connection[@]}" --db countly_fs > /dev/null;
@@ -410,7 +414,7 @@ countly_save (){
410414

411415
if [ "$files" -gt 0 ]
412416
then
413-
for d in $2/*; do
417+
for d in "$2"/*; do
414418
diff=$(diff "$1" "$d" | wc -l)
415419
if [ "$diff" == 0 ]
416420
then
@@ -504,7 +508,8 @@ countly_restoredb (){
504508
fi
505509
shift
506510
#allow passing custom flags
507-
connection=( $(node "$DIR/scripts/db.conf.js") "${@}" );
511+
IFS=" " read -r -a con <<< "$(node "$DIR/scripts/db.conf.js")"
512+
connection=( "${con[@]}" "${@}" );
508513
if [ -d "$1/dump/countly" ]; then
509514
echo "Restoring countly database...";
510515
mongorestore "${connection[@]}" --db countly --batchSize=10 "$1/dump/countly" > /dev/null;
@@ -550,6 +555,7 @@ countly_thp (){
550555
}
551556

552557
#load real platform/init sys file to overwrite stubs
558+
# shellcheck source=/dev/null
553559
source "$DIR/enabled/countly.sh"
554560

555561
#process command

bin/commands/scripts/add_user.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ else
1616

1717
if [ -z "$2" ]
1818
then
19-
read -sp "Enter password: " password
19+
read -srp "Enter password: " password
2020
echo ""
21-
read -sp "Enter password again: " password_confirmation
21+
read -srp "Enter password again: " password_confirmation
2222
echo ""
2323

2424
if [ "$password" != "$password_confirmation" ]

bin/commands/scripts/decrypt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ usage (){
99

1010
if [ -z "$1" ]
1111
then
12-
read -p "Text to decrypt: " text
12+
read -rp "Text to decrypt: " text
1313
else
1414
text=$1
1515
fi

bin/commands/scripts/encrypt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ usage (){
99

1010
if [ -z "$1" ]
1111
then
12-
read -p "Text to encrypt: " text
12+
read -rp "Text to encrypt: " text
1313
else
1414
text=$1
1515
fi

bin/commands/scripts/healthcheck.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33

44
if [ "$1" = "all" ]; then
5-
for d in $DIR/healthcheck/* ; do
5+
for d in "$DIR"/healthcheck/* ; do
66
name=$(basename "$d");
77
ext="${name##*.}";
88
if [ "$ext" == "sh" ]; then
@@ -17,7 +17,7 @@ elif ! [ $# -eq 0 ]; then
1717
done
1818
else
1919
scripts=""
20-
for d in $DIR/healthcheck/* ; do
20+
for d in "$DIR"/healthcheck/* ; do
2121
name=$(basename "$d");
2222
ext="${name##*.}";
2323
if [ "$ext" == "sh" ]; then

bin/commands/scripts/healthcheck/accessibility.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#!/bin/bash
22
status=""
3-
wget -q -t 1 --timeout=10 127.0.0.1:6001/ping
4-
if [ $? -ne 0 ]; then
3+
if ! wget -q -t 1 --timeout=10 127.0.0.1:6001/ping
4+
then
55
status=${status}"\n Dashboard is not accessible";
66
fi
77

8-
wget -q -t 1 --timeout=10 127.0.0.1:3001/o/ping
9-
if [ $? -ne 0 ]; then
8+
if ! wget -q -t 1 --timeout=10 127.0.0.1:3001/o/ping
9+
then
1010
status=${status}"\n Api is not accessible";
1111
fi
1212

13-
wget -q -t 1 --timeout=10 127.0.0.1/ping
14-
if [ $? -ne 0 ]; then
13+
if ! wget -q -t 1 --timeout=10 127.0.0.1/ping
14+
then
1515
status=${status}"\n Dashboard is not accessible through Nginx";
1616
fi
1717

18-
wget -q -t 1 --timeout=10 127.0.0.1/o/ping
19-
if [ $? -ne 0 ]; then
18+
if ! wget -q -t 1 --timeout=10 127.0.0.1/o/ping
19+
then
2020
status=${status}"\n Api is not accessible through Nginx";
2121
fi
2222

bin/commands/scripts/healthcheck/disk.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ res=""
44
for disk in $(df |grep dev |grep -v tmpfs |grep -v udev| awk -F" " '{print $1}' | cut -d/ -f3); do
55
space_use=$(df | grep "$disk " | awk -F" " '{print $5}' | cut -d% -f1)
66
if [ "$space_use" -gt "$alert_threshold" ]; then
7-
info_disk=($(df -h | grep "$disk " | awk -F" " '{print $6, $2, $3, $4, $5}'))
7+
IFS=" " read -r -a info_disk <<< "$(df -h | grep "$disk " | awk -F" " '{print $6, $2, $3, $4, $5}'))"
88
res=${res}"\n Mount point : ${info_disk[O]}"
99
res=${res}"\n - Total space : ${info_disk[1]}"
1010
res=${res}"\n - Used space : ${info_disk[2]}"

bin/commands/scripts/healthcheck/mongo.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
con=($(countly mongo))
2+
IFS=" " read -r -a con <<< "$(countly mongo)"
33
res=$(mongo countly "${con[@]}" --eval "print('CLYTest')")
44
if ! [[ "$res" == *"CLYTest"* ]]; then
55
echo -e "Can't connect to MongoDB";

bin/commands/scripts/healthcheck/ntp.sh

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

33
if [ -x "$(command -v ntpstat)" ]; then
4-
ntpstat;
5-
if [ $? -ne 0 ]; then
4+
if ! ntpstat
5+
then
66
echo -e "NTP does not seem to work properly";
77
fi
88
elif [ -x "$(command -v ntpq)" ]; then
@@ -12,7 +12,6 @@ elif [ -x "$(command -v ntpq)" ]; then
1212
fi
1313
elif [ -x "$(command -v timedatectl)" ]; then
1414
res=$(timedatectl status | grep 'NTP synchronized' | tr -d ' ' | cut -d ':' -f 2);
15-
echo "result $res"
1615
if ! [[ "$res" == "yes" ]]; then
1716
echo -e "NTP does not seem to work properly";
1817
fi

bin/commands/scripts/healthcheck/permissions.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ procowner="0"
44
fileowner=$(stat -c '%U' "$(countly dir)")
55
# shellcheck disable=SC2009
66
paths=$(ps -ux | grep countly)
7-
while read line; do
7+
while read -r line; do
88
if [[ "$line" = *"dashboard node"* ]]; then
99
procowner=$(echo "${line}" | tr -s ' ' | cut -d ' ' -f 1)
1010
break

bin/commands/scripts/healthcheck/process.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mempercentthreshold=80
66
cpuover=""
77
memover=""
88
top=$(top -b -n 1 | sed -e "1,7d")
9-
while read line; do
9+
while read -r line; do
1010
cpuutil=$(echo "${line}" | awk '{print $9}' | cut -d"." -f 1)
1111
memutil=$(echo "${line}" | awk '{print $10}' | cut -d"." -f 1)
1212
procname=$(echo "${line}" | awk '{print $12}' | cut -d"." -f 1)
@@ -34,7 +34,7 @@ apiproc=0
3434
workers=0
3535
# shellcheck disable=SC2009
3636
paths=$(ps -ax | grep countly)
37-
while read line; do
37+
while read -r line; do
3838
if [[ "$line" = *"dashboard node"* ]]; then
3939
appproc=$((appproc+1))
4040
fi
@@ -47,7 +47,7 @@ while read line; do
4747
done <<< "$paths"
4848
res=""
4949
if [ "${appproc}" -gt "${appprocthreshold}" ]; then
50-
res=$"{res}\n Too many processes for app.js: $appproc"
50+
res="${res}\n Too many processes for app.js: $appproc"
5151
elif [ "${appproc}" == 0 ]; then
5252
res="${res}\n Process app.js is not found"
5353
fi

bin/commands/scripts/plugin.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ usage (){
1616
}
1717

1818
if [ "$1" = "list" ]; then
19-
for d in $DIR/../../../plugins/*/; do
19+
for d in "$DIR"/../../../plugins/*/; do
2020
if [ "$2" = "states" ]; then
2121
PLUGIN="$(basename "$d")" ;
2222
if grep -Fq "\"$PLUGIN\"" "$DIR/../../../plugins/plugins.json"

bin/commands/scripts/remove_user.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ else
1616

1717
if [ -z "$2" ]
1818
then
19-
read -sp "Enter password: " password
19+
read -srp "Enter password: " password
2020
echo ""
2121
else
2222
password=$2

bin/config/countly_user.sh

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if [ ! -f "$COUNTLY_DIR/bin/config/supervisord.conf.backup" ]; then
1515
fi
1616

1717
#copy new supervisord configuration file
18+
# shellcheck disable=SC2216
1819
yes | cp -rf "$DIR/supervisort.wuser.conf" "$COUNTLY_DIR/bin/config/supervisord.conf"
1920

2021
#check if user not created yet

bin/countly.install_rhel.sh

+3-4
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ if grep -q -i "release 6" /etc/redhat-release ; then
7878
yum install -y wget
7979
wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
8080
yum install -y devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils
81+
# shellcheck disable=SC1091
8182
source /opt/rh/devtoolset-2/enable
82-
CC="$(which gcc)"
83-
CXX="$(which g++)"
84-
export $CC
85-
export $CXX
83+
#CC="$(which gcc)"
84+
#CXX="$(which g++)"
8685
fi
8786

8887
#install grunt & npm modules

bin/countly.install_travis.sh

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ g++ --version
5252
apt-get -y install nginx || (echo "Failed to install nginx." ; exit)
5353

5454
#install node.js
55-
#bash $DIR/scripts/install.nodejs.deb.sh || (echo "Failed to install nodejs." ; exit)
5655
apt-get -y install nodejs || (echo "Failed to install nodejs." ; exit)
5756

5857
#install supervisor

bin/countly.install_ubuntu.sh

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ g++ --version
4848
apt-get -y install nginx || (echo "Failed to install nginx." ; exit)
4949

5050
#install node.js
51-
#bash $DIR/scripts/install.nodejs.deb.sh || (echo "Failed to install nodejs." ; exit)
5251
apt-get -y install nodejs || (echo "Failed to install nodejs." ; exit)
5352

5453
#if npm is not installed, install it too

bin/docker/modify.sh

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

3+
# shellcheck disable=SC1091
34
source /etc/os-release
45

56
# Remove plugins unsupported in Docker distribution
@@ -57,6 +58,7 @@ if [ "${COUNTLY_CONTAINER}" != "frontend" ]; then
5758
rm -rf ~/.cache
5859
else
5960
yum install -y python36 python36-libs python36-devel python36-pip centos-release-scl devtoolset-7-gcc-c++
61+
# shellcheck disable=SC1091
6062
source /opt/rh/devtoolset-7/enable
6163
export CC=/opt/rh/devtoolset-7/root/usr/bin/gcc
6264
export CXX=/opt/rh/devtoolset-7/root/usr/bin/g++

bin/docker/preinstall.sh

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

3+
# shellcheck disable=SC1091
34
source /etc/os-release
45

56
while IFS= read -r -d '' plugin

bin/scripts/install-google-chrome.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pushd ${working_directory}
5555
# A helper to make sure that Chrome is linked correctly
5656
function installation_status() {
5757
google-chrome-stable --version > /dev/null 2>&1
58-
[ $? -eq 0 ]
58+
#[ $? -eq 0 ]
5959
}
6060

6161

@@ -230,8 +230,9 @@ rm -rf ${working_directory}
230230
popd > /dev/null
231231

232232
# Print out the success status message and exit.
233-
version="$(google-chrome-stable --version)"
234-
if [ $? -eq 0 ]; then
233+
234+
if version="$(google-chrome-stable --version)"
235+
then
235236
echo "Successfully installed google-chrome-stable, ${version}."
236237
exit 0
237238
else

0 commit comments

Comments
 (0)