1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 12:10:11 +01:00

shellcheck: fix usse -n instead of ! -z (SC2236 SC2237)

- https://www.shellcheck.net/wiki/SC2236 -- Use -n instead of ! -z.
 - https://www.shellcheck.net/wiki/SC2237 -- Use [ -n .. ] instead of ! [ -z ....

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2020-02-16 20:07:37 +01:00
parent e8cf225046
commit ad32739860
5 changed files with 26 additions and 23 deletions

View File

@ -97,7 +97,7 @@ If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"
FILTRON_TARGET : ${FILTRON_TARGET} FILTRON_TARGET : ${FILTRON_TARGET}
EOF EOF
[ ! -z "${1+x}" ] && err_msg "$1" [[ -n ${1} ]] && err_msg "$1"
} }
main() { main() {

View File

@ -57,7 +57,7 @@ required_commands() {
# usage: requires_commands [cmd1 ...] # usage: requires_commands [cmd1 ...]
local exit_val=0 local exit_val=0
while [ ! -z "$1" ]; do while [ -n "$1" ]; do
if ! command -v "$1" &>/dev/null; then if ! command -v "$1" &>/dev/null; then
err_msg "missing command $1" err_msg "missing command $1"
@ -125,7 +125,7 @@ rst_title() {
rst_para() { rst_para() {
# usage: RST_INDENT=1 rst_para "lorem ipsum ..." # usage: RST_INDENT=1 rst_para "lorem ipsum ..."
local prefix='' local prefix=''
if ! [[ -z $RST_INDENT ]] && [[ $RST_INDENT -gt 0 ]]; then if [[ -n $RST_INDENT ]] && [[ $RST_INDENT -gt 0 ]]; then
prefix="$(for i in $(seq 1 "$RST_INDENT"); do printf " "; done)" prefix="$(for i in $(seq 1 "$RST_INDENT"); do printf " "; done)"
echo -en "\n$*\n" | $FMT | prefix_stdout "$prefix" echo -en "\n$*\n" | $FMT | prefix_stdout "$prefix"
else else
@ -151,8 +151,8 @@ wait_key(){
local msg="${MSG}" local msg="${MSG}"
[[ -z "$msg" ]] && msg="${_Green}** press any [${_BCyan}KEY${_Green}] to continue **${_creset}" [[ -z "$msg" ]] && msg="${_Green}** press any [${_BCyan}KEY${_Green}] to continue **${_creset}"
[[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
[[ ! -z $_t ]] && _t="-t $_t" [[ -n $_t ]] && _t="-t $_t"
printf "$msg" printf "$msg"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
read -r -s -n1 $_t read -r -s -n1 $_t
@ -167,8 +167,8 @@ ask_yn() {
local EXIT_NO=1 # exit status 1 --> error code local EXIT_NO=1 # exit status 1 --> error code
local _t=$3 local _t=$3
[[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
[[ ! -z $_t ]] && _t="-t $_t" [[ -n $_t ]] && _t="-t $_t"
case "${FORCE_SELECTION:-${2}}" in case "${FORCE_SELECTION:-${2}}" in
Y) return ${EXIT_YES} ;; Y) return ${EXIT_YES} ;;
N) return ${EXIT_NO} ;; N) return ${EXIT_NO} ;;
@ -218,7 +218,7 @@ tee_stderr () {
# hello # hello
local _t="0"; local _t="0";
if [[ ! -z $1 ]] ; then _t="$1"; fi if [[ -n $1 ]] ; then _t="$1"; fi
(while read -r line; do (while read -r line; do
# shellcheck disable=SC2086 # shellcheck disable=SC2086
@ -233,7 +233,7 @@ prefix_stdout () {
local prefix="${_BYellow}-->|${_creset}" local prefix="${_BYellow}-->|${_creset}"
if [[ ! -z $1 ]] ; then prefix="${_BYellow}$1${_creset}"; fi if [[ -n $1 ]] ; then prefix="${_BYellow}$1${_creset}"; fi
# shellcheck disable=SC2162 # shellcheck disable=SC2162
(while IFS= read line; do (while IFS= read line; do
@ -260,7 +260,7 @@ cache_download() {
local exit_value=0 local exit_value=0
if [[ ! -z ${SUDO_USER} ]]; then if [[ -n ${SUDO_USER} ]]; then
sudo -u "${SUDO_USER}" mkdir -p "${CACHE}" sudo -u "${SUDO_USER}" mkdir -p "${CACHE}"
else else
mkdir -p "${CACHE}" mkdir -p "${CACHE}"
@ -274,7 +274,7 @@ cache_download() {
if [[ ! -f "${CACHE}/$2" ]]; then if [[ ! -f "${CACHE}/$2" ]]; then
info_msg "caching: $1" info_msg "caching: $1"
info_msg " --> ${CACHE}/$2" info_msg " --> ${CACHE}/$2"
if [[ ! -z ${SUDO_USER} ]]; then if [[ -n ${SUDO_USER} ]]; then
sudo -u "${SUDO_USER}" wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$? sudo -u "${SUDO_USER}" wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
else else
wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$? wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
@ -298,8 +298,8 @@ choose_one() {
local choice=$1; local choice=$1;
local max="${#@}" local max="${#@}"
local _t local _t
[[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
[[ ! -z $_t ]] && _t="-t $_t" [[ -n $_t ]] && _t="-t $_t"
list=("$@") list=("$@")
echo -e "${_BGreen}Menu::${_creset}" echo -e "${_BGreen}Menu::${_creset}"
@ -374,7 +374,7 @@ install_template() {
local chmod="${pos_args[4]-644}" local chmod="${pos_args[4]-644}"
info_msg "install (eval=$do_eval): ${dst}" info_msg "install (eval=$do_eval): ${dst}"
[[ ! -z $variant ]] && info_msg "variant: ${variant}" [[ -n $variant ]] && info_msg "variant: ${variant}"
if [[ ! -f "${template_origin}" ]] ; then if [[ ! -f "${template_origin}" ]] ; then
err_msg "${template_origin} does not exists" err_msg "${template_origin} does not exists"
@ -386,14 +386,14 @@ install_template() {
if [[ "$do_eval" == "1" ]]; then if [[ "$do_eval" == "1" ]]; then
template_file="${CACHE}${dst}${variant}" template_file="${CACHE}${dst}${variant}"
info_msg "BUILD template ${template_file}" info_msg "BUILD template ${template_file}"
if [[ ! -z ${SUDO_USER} ]]; then if [[ -n ${SUDO_USER} ]]; then
sudo -u "${SUDO_USER}" mkdir -p "$(dirname "${template_file}")" sudo -u "${SUDO_USER}" mkdir -p "$(dirname "${template_file}")"
else else
mkdir -p "$(dirname "${template_file}")" mkdir -p "$(dirname "${template_file}")"
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
eval "echo \"$(cat ${template_origin})\"" > "${template_file}" eval "echo \"$(cat ${template_origin})\"" > "${template_file}"
if [[ ! -z ${SUDO_USER} ]]; then if [[ -n ${SUDO_USER} ]]; then
chown "${SUDO_USER}:${SUDO_USER}" "${template_file}" chown "${SUDO_USER}:${SUDO_USER}" "${template_file}"
fi fi
else else
@ -856,8 +856,8 @@ git_clone() {
fi fi
[[ -z $branch ]] && branch=master [[ -z $branch ]] && branch=master
[[ -z $user ]] && [[ ! -z "${SUDO_USER}" ]] && user="${SUDO_USER}" [[ -z $user ]] && [[ -n "${SUDO_USER}" ]] && user="${SUDO_USER}"
[[ ! -z $user ]] && bash_cmd="sudo -H -u $user -i" [[ -n $user ]] && bash_cmd="sudo -H -u $user -i"
if [[ -d "${dest}" ]] ; then if [[ -d "${dest}" ]] ; then
info_msg "already cloned: $dest" info_msg "already cloned: $dest"

View File

@ -31,6 +31,7 @@ ubu1804_boilerplate="
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
apt-get install -y git curl wget apt-get install -y git curl wget
" "
# shellcheck disable=SC2034
ubu1904_boilerplate="$ubu1804_boilerplate" ubu1904_boilerplate="$ubu1804_boilerplate"
REMOTE_IMAGES=() REMOTE_IMAGES=()
@ -75,7 +76,7 @@ all LXC containers:
${LOCAL_IMAGES[@]} ${LOCAL_IMAGES[@]}
EOF EOF
[ ! -z "${1+x}" ] && err_msg "$1" [ -n "${1+x}" ] && err_msg "$1"
} }
lxd_info() { lxd_info() {
@ -255,7 +256,7 @@ lxc_boilerplate_containers() {
lxc start -q "${HOST_PREFIX}-${shortname}" &>/dev/null lxc start -q "${HOST_PREFIX}-${shortname}" &>/dev/null
boilerplate_script="${shortname}_boilerplate" boilerplate_script="${shortname}_boilerplate"
boilerplate_script="${!boilerplate_script}" boilerplate_script="${!boilerplate_script}"
if [[ ! -z "${boilerplate_script}" ]]; then if [[ -n "${boilerplate_script}" ]]; then
echo "$boilerplate_script" \ echo "$boilerplate_script" \
| lxc exec "${HOST_PREFIX}-${shortname}" -- bash \ | lxc exec "${HOST_PREFIX}-${shortname}" -- bash \
| prefix_stdout " ${HOST_PREFIX}-${shortname} | " | prefix_stdout " ${HOST_PREFIX}-${shortname} | "
@ -305,11 +306,13 @@ add_subordinate_ids() {
del_subordinate_ids() { del_subordinate_ids() {
local out local out
local exit_value
if grep "root:${HOST_USER_ID}:1" /etc/subuid -qs; then if grep "root:${HOST_USER_ID}:1" /etc/subuid -qs; then
# TODO: root user is always in use by process 1, how can we remove subordinates? # TODO: root user is always in use by process 1, how can we remove subordinates?
info_msg "remove lxd permission to map ${HOST_USER_ID}'s user/group id through" info_msg "remove lxd permission to map ${HOST_USER_ID}'s user/group id through"
out=$(usermod --del-subuids "${HOST_USER_ID}-${HOST_USER_ID}" --del-subgids "${HOST_GROUP_ID}-${HOST_GROUP_ID}" root 2>&1) out=$(usermod --del-subuids "${HOST_USER_ID}-${HOST_USER_ID}" --del-subgids "${HOST_GROUP_ID}-${HOST_GROUP_ID}" root 2>&1)
if [ ! -z $? ]; then exit_val=$?
if [ $exit_val -ne 0 ]; then
err_msg "$out" err_msg "$out"
fi fi
else else

View File

@ -84,7 +84,7 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file::
SERVICE_USER : ${SERVICE_USER} SERVICE_USER : ${SERVICE_USER}
EOF EOF
info_searx info_searx
[ ! -z "${1+x}" ] && err_msg "$1" [[ -n ${1} ]] && err_msg "$1"
} }
info_searx() { info_searx() {

View File

@ -110,7 +110,7 @@ If needed, set PUBLIC_URL of your WEB service in the '${DOT_CONFIG#"$REPO_ROOT/"
SERVICE_USER : ${SERVICE_USER} SERVICE_USER : ${SERVICE_USER}
EOF EOF
[ ! -z "${1+x}" ] && err_msg "$1" [[ -n ${1} ]] && err_msg "$1"
} }
main() { main() {