Skip to content

Commit 2ee38eb

Browse files
authored
Apply shellcheck to all bash scripts (hestiacp#2183)
* Fix Shellcheck error source= was missing * Fix javascript error * Add missing php8.0 * Add check if theme exists + Fix error in v-list-sys-themes * Add correct validation for short_order * Check input also for last name if exists Input / abuse still possible over CLI * Improve check if language is valid * Add missing validation vars * Add missing validation v-add-sys-ip Helo field was open for abuse * Add exit codes * Prevent insertion of unvalidated data * Add validation for few arguments * Add new checks * Checked source code with shellcheck - Prevent sourced config files to be ran use source_conf instead - Removed errors with shell checked - Prevented globbing vars - replaces ! -z with -n and other suggestions from shell check - Prevent ' and " used to be used in some settings - Added /etc/hestiacp/hestia.conf to /bin/ files * Load hestia.conf * Enable shell check for install folder * Fix bug in v-add-mail-domain * Update test.bats * Use source for upgrade.conf As it is not supported yet due to # * Add Lint / Shellcheck to pipe line Use docker image made for linting * Add skip ylm * Use koalaman/shellcheck-alpine as docker image instead * Update permissions * Fix error installer * Fix 2 errors due to shell check * Fix error in exit at end shellcheck * Add extra tests + Improve speed sourcing * Fix test * Fix list-user-notification test * Fix list-user-notification test * Fix bug in v-copy-user-package * Move test order adjust v-add-user-package * Fix bug in v-revoke-api-key * Fix bug in package handling
1 parent 8171092 commit 2ee38eb

File tree

499 files changed

+4092
-2900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

499 files changed

+4092
-2900
lines changed

.drone.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ steps:
8686
trigger:
8787
event: [ push, pull_request ]
8888

89+
---
90+
kind: pipeline
91+
type: docker
92+
name: Linting
93+
94+
concurrency:
95+
limit: 1
96+
97+
steps:
98+
- name: shellcheck
99+
image: koalaman/shellcheck-alpine
100+
commands:
101+
- ./test/shellcheck.sh
102+
103+
trigger:
104+
event: [ pull_request, push ]
105+
89106
---
90107
kind: signature
91-
hmac: bca7f80ac6198662bc658235d7345485213847f1c00f027e1439775e02776bc7
108+
hmac: 48d34d11001c99b470114f50c4284fa107a5e61ad08ada38307493b9e9b2883f

bin/v-acknowledge-user-notification

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ user=$1
1717
id=$2
1818

1919
# Includes
20+
# shellcheck source=/etc/hestiacp/hestia.conf
21+
source /etc/hestiacp/hestia.conf
2022
# shellcheck source=/usr/local/hestia/func/main.sh
2123
source $HESTIA/func/main.sh
22-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
23-
source $HESTIA/conf/hestia.conf
24-
25-
24+
# load config file
25+
source_conf "$HESTIA/conf/hestia.conf"
2626
#----------------------------------------------------------#
2727
# Verifications #
2828
#----------------------------------------------------------#

bin/v-add-backup-host

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ path=${5-/backup}
2222
port=$6
2323

2424
# Includes
25+
# shellcheck source=/etc/hestiacp/hestia.conf
26+
source /etc/hestiacp/hestia.conf
2527
# shellcheck source=/usr/local/hestia/func/main.sh
2628
source $HESTIA/func/main.sh
27-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
28-
source $HESTIA/conf/hestia.conf
29+
30+
# load config file
31+
source_conf "$HESTIA/conf/hestia.conf"
2932

3033
# Paths
3134
b2cli="/usr/local/bin/b2"
@@ -103,11 +106,14 @@ EOF
103106

104107
if [ "$type" != 'local' ];then
105108
check_args '4' "$#" "TYPE HOST USERNAME PASSWORD [PATH] [PORT]"
106-
is_format_valid 'user' 'host' 'path' 'port'
109+
is_format_valid 'host' 'path' 'port'
110+
is_username_format_valid "$username" "username"
107111
is_password_valid
112+
format_no_quotes "$password" "password"
113+
108114
if [ "$type" = 'sftp' ]; then
109115
which expect >/dev/null 2>&1
110-
check_result $? "expect command not found" $E_NOTEXIST
116+
check_result $? "expect command not found" "$E_NOTEXIST"
111117
fi
112118
if [ "$type" != 'b2' ]; then
113119
if ! (is_ip_format_valid "$host" >/dev/null); then
@@ -132,10 +138,10 @@ if [ "$type" = 'ftp' ]; then
132138
fconn=$(ftpc 2>&1)
133139
ferror=$(echo $fconn |\
134140
grep -i -e failed -e error -e "can't" -e "not conn" -e "incorrect")
135-
if [ ! -z "$ferror" ]; then
141+
if [ -n "$ferror" ]; then
136142
echo "Error: can't login to ftp $user@$host"
137143
log_event "$E_CONNECT" "$ARGUMENTS"
138-
exit $E_CONNECT
144+
exit "$E_CONNECT"
139145
fi
140146

141147
# Checking write permissions
@@ -146,12 +152,12 @@ if [ "$type" = 'ftp' ]; then
146152
ftmpdir="$path/vst.bK76A9SUkt"
147153
fi
148154
ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir"|grep -v Trying)
149-
if [ ! -z "$ftp_result" ] ; then
155+
if [ -n "$ftp_result" ] ; then
150156
echo "$ftp_result"
151157
rm -rf $tmpdir
152158
echo "Error: can't create $ftmpdir folder on the ftp"
153159
log_event "$E_FTP" "$ARGUMENTS"
154-
exit $E_FTP
160+
exit "$E_FTP"
155161
fi
156162
fi
157163

@@ -202,7 +208,7 @@ if [ "$type" = 'b2' ]; then
202208

203209
b2 clear-account > /dev/null 2>&1
204210
b2 authorize-account "$user" "$raw_password"> /dev/null 2>&1
205-
b2 ls --long $host $user > /dev/null 2>&1
211+
b2 ls --long "$host" "$user" > /dev/null 2>&1
206212

207213
if [ $? -ne 0 ]; then
208214
check_result "$E_CONNECT" "b2 failed to verify connection"

bin/v-add-cron-hestia-autoupdate

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ user=admin
1515
mode=$1
1616

1717
# Includes
18+
# shellcheck source=/etc/hestiacp/hestia.conf
19+
source /etc/hestiacp/hestia.conf
1820
# shellcheck source=/usr/local/hestia/func/main.sh
1921
source $HESTIA/func/main.sh
20-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
21-
source $HESTIA/conf/hestia.conf
22+
# load config file
23+
source_conf "$HESTIA/conf/hestia.conf"
2224

2325

2426
#----------------------------------------------------------#
@@ -30,7 +32,7 @@ is_package_full 'CRON_JOBS'
3032
get_next_cronjob
3133
check_cron_apt=$(grep 'v-update-sys-hestia-all' $USER_DATA/cron.conf)
3234
check_cron_git=$(grep 'v-update-sys-hestia-git' $USER_DATA/cron.conf)
33-
if [ ! -z "$check_cron_apt" ] || [ ! -z "$check_cron_git" ]; then
35+
if [ -n "$check_cron_apt" ] || [ -n "$check_cron_git" ]; then
3436
exit
3537
fi
3638

@@ -87,7 +89,7 @@ sync_cron_jobs
8789
#----------------------------------------------------------#
8890

8991
# Increasing cron value
90-
increase_user_value $user '$U_CRON_JOBS'
92+
increase_user_value "$user" '$U_CRON_JOBS'
9193

9294
# Restarting crond
9395
$BIN/v-restart-cron

bin/v-add-cron-job

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ job=$8
2525
restart=$9
2626

2727
# Includes
28+
# shellcheck source=/etc/hestiacp/hestia.conf
29+
source /etc/hestiacp/hestia.conf
2830
# shellcheck source=/usr/local/hestia/func/main.sh
2931
source $HESTIA/func/main.sh
30-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
31-
source $HESTIA/conf/hestia.conf
32+
# load config file
33+
source_conf "$HESTIA/conf/hestia.conf"
3234

3335
HIDE=7
3436

@@ -84,7 +86,7 @@ sync_cron_jobs
8486
increase_user_value $user '$U_CRON_JOBS'
8587

8688
# Restarting crond
87-
$BIN/v-restart-cron $restart
89+
$BIN/v-restart-cron "$restart"
8890
check_result $? "Cron restart failed" >/dev/null
8991

9092
# Logging

bin/v-add-cron-letsencrypt-job

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
#----------------------------------------------------------#
1212

1313
# Includes
14+
# shellcheck source=/etc/hestiacp/hestia.conf
15+
source /etc/hestiacp/hestia.conf
1416
# shellcheck source=/usr/local/hestia/func/main.sh
1517
source $HESTIA/func/main.sh
16-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
17-
source $HESTIA/conf/hestia.conf
18+
# load config file
19+
source_conf "$HESTIA/conf/hestia.conf"
1820

1921

2022
#----------------------------------------------------------#
@@ -33,7 +35,7 @@ check_hestia_demo_mode
3335
# Add cron job
3436
cmd="sudo $HESTIA/bin/v-update-sys-queue letsencrypt"
3537
check_cron=$(grep "$cmd" $HESTIA/data/users/admin/cron.conf 2> /dev/null)
36-
if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then
38+
if [ -z "$check_cron" ] && [ -n "$CRON_SYSTEM" ]; then
3739
$BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
3840
fi
3941

bin/v-add-cron-reports

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
user=$1
1818

1919
# Includes
20+
# shellcheck source=/etc/hestiacp/hestia.conf
21+
source /etc/hestiacp/hestia.conf
2022
# shellcheck source=/usr/local/hestia/func/main.sh
2123
source $HESTIA/func/main.sh
22-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
23-
source $HESTIA/conf/hestia.conf
24+
# load config file
25+
source_conf "$HESTIA/conf/hestia.conf"
2426

2527

2628
#----------------------------------------------------------#

bin/v-add-cron-restart-job

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
#----------------------------------------------------------#
1212

1313
# Includes
14+
# shellcheck source=/etc/hestiacp/hestia.conf
15+
source /etc/hestiacp/hestia.conf
1416
# shellcheck source=/usr/local/hestia/func/main.sh
1517
source $HESTIA/func/main.sh
16-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
17-
source $HESTIA/conf/hestia.conf
18+
# load config file
19+
source_conf "$HESTIA/conf/hestia.conf"
1820

1921

2022
#----------------------------------------------------------#
@@ -33,7 +35,7 @@ check_hestia_demo_mode
3335
# Add cron job
3436
cmd="sudo $HESTIA/bin/v-update-sys-queue restart"
3537
check_cron=$(grep "$cmd" $HESTIA/data/users/admin/cron.conf 2> /dev/null)
36-
if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then
38+
if [ -z "$check_cron" ] && [ -n "$CRON_SYSTEM" ]; then
3739
$BIN/v-add-cron-job admin '*' '*' '*' '*' '*' "$cmd"
3840
fi
3941

bin/v-add-database

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ charset=${7-UTF8}
2929
charset=$(echo "$charset" |tr '[:lower:]' '[:upper:]')
3030

3131
# Includes
32+
# shellcheck source=/etc/hestiacp/hestia.conf
33+
source /etc/hestiacp/hestia.conf
3234
# shellcheck source=/usr/local/hestia/func/main.sh
3335
source $HESTIA/func/main.sh
3436
# shellcheck source=/usr/local/hestia/func/db.sh
3537
source $HESTIA/func/db.sh
36-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
37-
source $HESTIA/conf/hestia.conf
38+
# load config file
39+
source_conf "$HESTIA/conf/hestia.conf"
3840

3941
if [ "$type" = "pgsql" ]; then
4042
database=$(echo "$user"_"$2" | tr '[:upper:]' '[:lower:]');
@@ -62,10 +64,10 @@ is_password_valid
6264
if [ "$type" = "pgsql" ]; then
6365
exclude="-"
6466
if [[ "$dbuser" =~ $exclude ]]; then
65-
check_result $E_INVALID "invalid database user format"
67+
check_result "$E_INVALID" "invalid database user format"
6668
fi
6769
if [[ "$database" =~ $exclude ]]; then
68-
check_result $E_INVALID "invalid database format"
70+
check_result "$E_INVALID" "invalid database format"
6971
fi
7072
fi
7173

bin/v-add-database-host

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ template=${7}
2727
port=${8}
2828

2929
# Includes
30+
# shellcheck source=/etc/hestiacp/hestia.conf
31+
source /etc/hestiacp/hestia.conf
3032
# shellcheck source=/usr/local/hestia/func/main.sh
3133
source $HESTIA/func/main.sh
3234
# shellcheck source=/usr/local/hestia/func/db.sh
3335
source $HESTIA/func/db.sh
34-
# shellcheck source=/usr/local/hestia/conf/hestia.conf
35-
source $HESTIA/conf/hestia.conf
36+
# load config file
37+
source_conf "$HESTIA/conf/hestia.conf"
3638

3739
is_mysql_host_alive() {
3840
mycnf=$(mktemp)
3941
echo "[client]">$mycnf
4042
echo "host='$host'" >> $mycnf
41-
echo "user='$user'" >> $mycnf
43+
echo "user='$dbuser'" >> $mycnf
4244
echo "password='$password'" >> $mycnf
4345
echo "port='$port'" >> $mycnf
4446

@@ -49,7 +51,7 @@ is_mysql_host_alive() {
4951
if [ "$?" -ne '0' ]; then
5052
echo "Error: MySQL connection to $host failed"
5153
log_event "$E_CONNECT" "$ARGUMENTS"
52-
exit $E_CONNECT
54+
exit "$E_CONNECT"
5355
fi
5456
}
5557

@@ -59,7 +61,7 @@ is_pgsql_host_alive() {
5961
if [ "$?" -ne '0' ]; then
6062
echo "Error: PostgreSQL connection to $host failed"
6163
log_event "$E_CONNECT" "$ARGUMENTS"
62-
exit $E_CONNECT
64+
exit "$E_CONNECT"
6365
fi
6466
}
6567

0 commit comments

Comments
 (0)