Skip to content

Commit 3f76f6e

Browse files
Cruz Monrreal IICruz Monrreal II
authored andcommitted
Fixed shellcheck issues found in functions.sh
Added comments to functions
1 parent 260c97a commit 3f76f6e

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

tools/test/travis-ci/functions.sh

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@
1818

1919
set -o pipefail
2020

21+
22+
#
23+
# Helper functions for printing status information.
24+
# Uses 'echo' instead of 'printf' due to Travis CI stdout sync issues.
25+
#
2126
info() { echo -e "I: ${1}"; }
22-
die() { echo -e "E: ${1}" 1>&2; exit ${2:-1}; }
27+
die() { echo -e "E: ${1}" 1>&2; exit "${2:-1}"; }
2328

29+
30+
#
31+
# Sets the GitHub job status for a given commit.
32+
#
2433
set_status()
2534
{
2635
local job_name=${NAME}
27-
local payload=$(<<< "
36+
local payload=""
37+
38+
payload=$(<<< "
2839
{
2940
'state': '${1}',
3041
'description': '${2}',
@@ -38,10 +49,21 @@ set_status()
3849
}
3950

4051

52+
#
53+
# Sources a pre-compiled GCC installation from AWS, installing the archive by
54+
# extracting and prepending the executable directory to PATH.
55+
#
56+
# Note: Expects 'deps_url' and 'deps_dir' to already be defined.
57+
#
4158
_install_gcc()
4259
{
60+
# Ignore shellcheck warnings: Variables defined in .travis.yml
61+
# shellcheck disable=SC2154
4362
local url="${deps_url}/gcc6-linux.tar.bz2"
63+
64+
# shellcheck disable=SC2154
4465
local gcc_path="${deps_dir}/gcc/gcc-arm-none-eabi-6-2017-q2-update/"
66+
4567
local archive="gcc.tar.bz2"
4668

4769
info "URL: ${url}"
@@ -64,14 +86,17 @@ _install_gcc()
6486
}
6587

6688

89+
#
90+
# Downloads a list of packages from AWS, really fast.
91+
#
6792
_fetch_deps()
6893
{
6994
local pkg="${1}"
7095
local dep_list="${2}"
7196

7297
info "Fetching '${pkg}' archives"
7398

74-
while read dep; do
99+
while read -r dep; do
75100

76101
curl --location "${deps_url}/${dep}.deb" \
77102
--output "${deps_dir}/${dep}.deb" \
@@ -83,25 +108,37 @@ _fetch_deps()
83108
wait
84109
}
85110

111+
112+
#
113+
# Installs a list of Debian packages, fetching them if not locally found.
114+
#
86115
_install_deps()
87116
{
88117
local pkg="${1}"
89118
local dep_list="${2}"
119+
local first_dep=""
90120

91121
# Assume that if the first package isn't cached, none are.
92-
local first_dep=$(<<< "${dep_list}" head -n1)
122+
first_dep=$(<<< "${dep_list}" head -n1)
93123
[ ! -f "${deps_dir}/${first_dep}.deb" ] && _fetch_deps "${pkg}" "${dep_list}"
94124

95125
# Install dependencies
96126
info "Installing '${pkg}' packages"
127+
128+
# Ignore shellcheck warnings: Word splitting is specifically used to build
129+
# command in one go, and expression non-expansion
130+
# is intentional.
131+
# shellcheck disable=SC2046 disable=SC2016
97132
sudo dpkg -i $(<<< "${dep_list}" sed -e 's_^ *__' -e 's_^\(.*\)$_'"${deps_dir}"'/\1.deb_' | tr $'\n' ' ')
98133
}
99134

100135

136+
#
137+
# Wrapper for installing a given package.
138+
#
101139
source_pkg()
102140
{
103-
local pkg="${1}"
104-
141+
# Debian dependencies needed for a single package.
105142
local aspell_deps="aspell
106143
aspell-en
107144
dictionaries-common
@@ -115,10 +152,13 @@ source_pkg()
115152
libsepol1-dev
116153
libc-bin"
117154

155+
local pkg="${1}"
118156

119157
case "${pkg}" in
120158

121159
"fuse" )
160+
# 'fuse' does not require an 'apt-get update' to install in Travis CI, so
161+
# there's no reason to upload it or its dependencies into AWS.
122162
sudo apt-get -o=dir::cache="${deps_dir}/apt-get" install fuse \
123163
|| die "Installation failed"
124164
;;

0 commit comments

Comments
 (0)