Skip to content

Commit

Permalink
make go-xcat pass ShellCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
samveen committed Aug 5, 2024
1 parent c8cb1d6 commit 628007a
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions xCAT-server/share/xcat/tools/go-xcat
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
function usage()
{
local script="${0##*/}"
local version="$(version)"
local -r version="$(version)"

while read -r ; do echo "${REPLY}" ; done <<-EOF
${script} version ${version}
Expand Down Expand Up @@ -106,7 +106,7 @@ function usage()
#
# verbose_usage This function be will be called when user run
# `go-xcat --long-help'.
# Including a bunch of secert usage.
# Including a bunch of secret usage.
#
function verbose_usage()
(
Expand All @@ -119,8 +119,7 @@ function verbose_usage()
local -i i
for (( i = 0 ; i < "$1" ; ++i ))
do
read -r -u 42
[[ "$?" -ne "0" ]] && break
read -r -u 42 || break
echo "${REPLY}"
done
}
Expand All @@ -135,7 +134,7 @@ function verbose_usage()
while read -r ; do echo "${REPLY}" ; done <<-EOF
check check the version of the installed packages
of xCAT and packages in the repository
smoke test preform basic tests of the xCAT installation
smoke test perform basic tests of the xCAT installation
EOF
println 11
while read -r ; do echo "${REPLY}" ; done <<-EOF
Expand Down Expand Up @@ -230,7 +229,7 @@ function warn_if_bad()

# Broken
shift
echo "${script}: $@" >&2
echo "${script}: $*" >&2
return "${rc}"
}

Expand Down Expand Up @@ -519,8 +518,8 @@ function check_arch()

function check_linux_distro()
{
local distro="$(source /etc/os-release >/dev/null 2>&1 &&
echo "${ID}")"
local distro
distro="$(awk -F= '/^ID=/{print $2}' /etc/os-release 2>/dev/null)"
[[ -z "${distro}" && -f /etc/redhat-release ]] && distro="rhel"
[[ -z "${distro}" && -f /etc/SuSE-release ]] && distro="sles"
[[ -z "${distro}" && -f /etc/SUSE-brand ]] && distro="sles"
Expand All @@ -529,8 +528,8 @@ function check_linux_distro()

function check_linux_version()
{
local ver="$(source /etc/os-release >/dev/null 2>&1 &&
echo "${VERSION_ID}")"
local ver
ver="$(awk -F= '/^VERSION_ID=/{print $2}' /etc/os-release 2>/dev/null)"
[[ -z "${ver}" && -f /etc/redhat-release ]] &&
# Need gawk to do this trick
ver="$(awk '{ match($0, /([.0-9]+)/, a); print substr($0, a[1, "start"], a[1, "length"]); }' \
Expand Down Expand Up @@ -613,7 +612,7 @@ function check_package_version_deb()
function check_package_version()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
# $@ package names
Expand Down Expand Up @@ -898,7 +897,11 @@ function check_repo_version_zypper()
function check_repo_version_apt()
{
type apt-cache >/dev/null 2>&1 || return 255
# Shellcheck doesn't handle identical names in local contexts
# well: https://github.com/koalaman/shellcheck/wiki/SC2178#exceptions
# shellcheck disable=SC2178
local name=""
# shellcheck disable=SC2178
local ver=""
while read -r name ver
do
Expand Down Expand Up @@ -927,7 +930,7 @@ function check_repo_version_apt()
function check_repo_version()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
# $1 repo id
Expand Down Expand Up @@ -1002,13 +1005,13 @@ function get_package_list_apt()
# $1 repo id
function get_package_list()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
function download_file_curl()
{
local script="${0##*/}"
local version="$(version)"
local -r version="$(version)"
local user_agent="${script}/${version} (${GO_XCAT_OS}; ${GO_XCAT_ARCH}; ${GO_XCAT_LINUX_DISTRO} ${GO_XCAT_LINUX_VERSION})"
type curl >/dev/null 2>&1 || return 255
local url="$1"
Expand Down Expand Up @@ -1115,7 +1118,7 @@ function download_file_curl()
function download_file_wget()
{
local script="${0##*/}"
local version="$(version)"
local -r version="$(version)"
local user_agent="${script}/${version} (${GO_XCAT_OS}; ${GO_XCAT_ARCH}; ${GO_XCAT_LINUX_DISTRO} ${GO_XCAT_LINUX_VERSION})"
type wget >/dev/null 2>&1 || return 255
local url="$1"
Expand Down Expand Up @@ -1147,7 +1150,7 @@ function download_file_wget()
function download_file()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
# $1 repo file
Expand Down Expand Up @@ -1245,7 +1248,7 @@ function add_repo_by_file_apt()
function add_repo_by_file()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
# $1 archive
Expand All @@ -1256,7 +1259,7 @@ function extract_archive()
local archive="$1"
local repo_id="$2"
local install_path="$3"
local umask="$(umask)"
local -r umask="$(umask)"
local -i ret=0
[[ -f "${archive}" ]]
Expand All @@ -1276,7 +1279,7 @@ function extract_archive()
[[ "${PIPESTATUS[0]}" -eq 0 && "${PIPESTATUS[1]}" -eq 0 &&
"${PIPESTATUS[2]}" -eq 1 ]]
warn_if_bad "$?" "${archive}: bad compressed tarball" || return 1
rm -rf "${install_path}/${repo_id}"
rm -rf "${install_path:-${GO_XCAT_DEFAULT_INSTALL_PATH}}/${repo_id}"
uncompress -c "${archive}" | ( cd "${install_path}" && tar -x -f - )
;;
*".tz"|*".tgz"|*".tar.gz")
Expand All @@ -1285,7 +1288,7 @@ function extract_archive()
[[ "${PIPESTATUS[0]}" -eq 0 && "${PIPESTATUS[1]}" -eq 0 &&
"${PIPESTATUS[2]}" -eq 1 ]]
exit_if_bad "$?" "${archive}: bad gzipped tarball" || return 1
rm -rf "${install_path}/${repo_id}"
rm -rf "${install_path:-${GO_XCAT_DEFAULT_INSTALL_PATH}}/${repo_id}"
gzip -d -c "${archive}" | ( cd "${install_path}" && tar -x -f - )
;;
*".tbz"|*".tbz2"|*".tar.bz"|*".tar.bz2")
Expand All @@ -1294,7 +1297,7 @@ function extract_archive()
[[ "${PIPESTATUS[0]}" -eq 0 && "${PIPESTATUS[1]}" -eq 0 &&
"${PIPESTATUS[2]}" -eq 1 ]]
warn_if_bad "$?" "${archive}: bad bzipped tarball" || return 1
rm -rf "${install_path}/${repo_id}"
rm -rf "${install_path:-${GO_XCAT_DEFAULT_INSTALL_PATH}}/${repo_id}"
bzip2 -d -c "${archive}" | ( cd "${install_path}" && tar -x -f - )
;;
*".txz"|*".tar.xz")
Expand All @@ -1303,15 +1306,15 @@ function extract_archive()
[[ "${PIPESTATUS[0]}" -eq 0 && "${PIPESTATUS[1]}" -eq 0 &&
"${PIPESTATUS[2]}" -eq 1 ]]
warn_if_bad "$?" "${archive}: bad xzed tarball" || return 1
rm -rf "${install_path}/${repo_id}"
rm -rf "${install_path:-${GO_XCAT_DEFAULT_INSTALL_PATH}}/${repo_id}"
xz -d -c "${archive}" | ( cd "${install_path}" && tar -x -f - )
;;
*".tar")
check_executes tar grep || return 1
tar -t -f "${archive}" | grep -v "^${repo_id}/"
[[ "${PIPESTATUS[0]}" -eq 0 && "${PIPESTATUS[1]}" -eq 1 ]]
warn_if_bad "$?" "${archive}: bad tarball" || return 1
rm -rf "${install_path}/${repo_id}"
rm -rf "${install_path:-${GO_XCAT_DEFAULT_INSTALL_PATH}}/${repo_id}"
( cd "${install_path}" && tar -x -f - ) <"${archive}"
;;
*)
Expand Down Expand Up @@ -1416,8 +1419,7 @@ function add_repo_by_url_apt()
local repo_id="$2"
local tmp=""
local install_path="${GO_XCAT_DEFAULT_INSTALL_PATH}"
local codename="$(source /etc/lsb-release >/dev/null 2>&1 &&
echo "${DISTRIB_CODENAME}")"
local -r codename="$(awk -F= '/^DISTRIB_CODENAME=/{print $2}' /etc/lsb-release 2>/dev/null)"
[[ -n "${codename}" ]]
warn_if_bad "$?" "unknown debian/ubuntu codename" || return 1
case "${url%%://*}" in
Expand Down Expand Up @@ -1467,7 +1469,7 @@ function add_repo_by_url_apt()
function add_repo_by_url()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
# $1 repo id
Expand All @@ -1478,7 +1480,7 @@ function remove_repo_yum()
# This deleting method is not good enough. Since there could be more
# than one repository definitions in a single repo file.
# This is a quick and dirty method.
rm -f $(grep -l "^\[${repo_id}\]$" "/etc/yum.repos.d/"*".repo" 2>/dev/null)
grep -l "^\[${repo_id}\]$" "/etc/yum.repos.d/"*".repo" 2>/dev/null | xargs -r rm -f
case "${repo_id}" in
"xcat-core")
mv /etc/yum.repos.d/xCAT-core.repo{,.nouse} 2>/dev/null
Expand Down Expand Up @@ -1518,7 +1520,7 @@ function remove_repo_apt()
function remove_repo()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
# $1 URL
Expand Down Expand Up @@ -1584,7 +1586,7 @@ function add_xcat_core_repo_apt()
function add_xcat_core_repo()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
function add_xcat_dep_repo_yum_or_zypper()
Expand Down Expand Up @@ -1675,7 +1677,7 @@ function add_xcat_dep_repo_apt()
function add_xcat_dep_repo()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
function update_repo_dnf()
Expand Down Expand Up @@ -1709,7 +1711,7 @@ function update_repo_apt()
function update_repo()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
function install_packages_dnf()
Expand Down Expand Up @@ -1819,7 +1821,7 @@ function install_packages_apt()
function install_packages()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
function remove_package_dnf()
Expand Down Expand Up @@ -1870,7 +1872,7 @@ function remove_package_apt()
function remove_package()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
# $1 -y
Expand All @@ -1895,7 +1897,7 @@ function purge_package_others()
# $1 -y
function purge_package()
{
function_dispatch "${FUNCNAME}" "$@"
function_dispatch "${FUNCNAME[0]}" "$@"
}
# $1 -y
Expand Down Expand Up @@ -2004,7 +2006,8 @@ function list_xcat_packages()
[ "${#GO_XCAT_DEP_PACKAGE_LIST[@]}" -gt "0" ]
warn_if_bad "$?" "Failed to get package list from repository \`xcat-dep'." || return 1
local -i cols="$(type tput >/dev/null 2>&1 && tput cols)"
local -i cols
cols="$(type tput >/dev/null 2>&1 && tput cols)"
[[ "${cols}" -lt 80 ]] && cols=80
[[ "${cols}" -gt 90 ]] && cols=90
[[ -t 1 ]] || cols=90
Expand Down Expand Up @@ -2147,7 +2150,7 @@ function test_case_001_xcatd()
# Check if command lsdef can be run
function test_case_002_lsdef()
{
(source /etc/profile.d/xcat.sh && lsdef) >/dev/null 2>&1
bash -c "source /etc/profile.d/xcat.sh && lsdef" >/dev/null 2>&1
warn_if_bad "$?" "Attempt of run \`lsdef' failed"
}
Expand Down

0 comments on commit 628007a

Please sign in to comment.