Add "" around variables in test(1) cases to prevent errors when a variable is unset

This commit is contained in:
Lars Engels
2019-12-11 20:35:05 +01:00
parent 3f7573825d
commit 5b11f81a1b
5 changed files with 12 additions and 12 deletions
+6 -6
View File
@@ -69,14 +69,14 @@ fi
bootstrap_network_interfaces() { bootstrap_network_interfaces() {
## test for both options empty ## test for both options empty
if [ -z ${bastille_jail_loopback} ] && [ -z ${bastille_jail_external} ]; then if [ -z "${bastille_jail_loopback}" ] && [ -z "${bastille_jail_external}" ]; then
echo -e "${COLOR_RED}Please set preferred loopback or external interface.${COLOR_RESET}" echo -e "${COLOR_RED}Please set preferred loopback or external interface.${COLOR_RESET}"
echo -e "${COLOR_RED}See bastille.conf.${COLOR_RESET}" echo -e "${COLOR_RED}See bastille.conf.${COLOR_RESET}"
exit 1 exit 1
fi fi
## test for required variables -- external ## test for required variables -- external
if [ -z ${bastille_jail_loopback} ] && [ ! -z ${bastille_jail_external} ]; then if [ -z "${bastille_jail_loopback}" ] && [ ! -z "${bastille_jail_external}" ]; then
## test for existing interface ## test for existing interface
ifconfig ${bastille_jail_external} 2>&1 >/dev/null ifconfig ${bastille_jail_external} 2>&1 >/dev/null
@@ -101,8 +101,8 @@ bootstrap_network_interfaces() {
fi fi
## test for required variables -- loopback ## test for required variables -- loopback
if [ -z ${bastille_jail_external} ] && [ ! -z ${bastille_jail_loopback} ] && \ if [ -z "${bastille_jail_external}" ] && [ ! -z "${bastille_jail_loopback}" ] && \
[ ! -z ${bastille_jail_addr} ]; then [ ! -z "${bastille_jail_addr}" ]; then
echo -e "${COLOR_GREEN}Detecting...${COLOR_RESET}" echo -e "${COLOR_GREEN}Detecting...${COLOR_RESET}"
## test for existing interface ## test for existing interface
@@ -360,11 +360,11 @@ bootstrap_template() {
_template=${bastille_templatesdir}/${_user}/${_repo} _template=${bastille_templatesdir}/${_user}/${_repo}
## support for non-git ## support for non-git
if [ ! -x $(which git) ]; then if [ ! -x "$(which git)" ]; then
echo -e "${COLOR_RED}Git not found.${COLOR_RESET}" echo -e "${COLOR_RED}Git not found.${COLOR_RESET}"
echo -e "${COLOR_RED}Not yet implemented.${COLOR_RESET}" echo -e "${COLOR_RED}Not yet implemented.${COLOR_RESET}"
exit 1 exit 1
elif [ -x $(which git) ]; then elif [ -x "$(which git)" ]; then
if [ ! -d "${_template}/.git" ]; then if [ ! -d "${_template}/.git" ]; then
$(which git) clone "${_url}" "${_template}" ||\ $(which git) clone "${_url}" "${_template}" ||\
echo -e "${COLOR_RED}Clone unsuccessful.${COLOR_RESET}" echo -e "${COLOR_RED}Clone unsuccessful.${COLOR_RESET}"
+3 -3
View File
@@ -140,10 +140,10 @@ create_jail() {
fi fi
if [ ! -f "${bastille_jail_conf}" ]; then if [ ! -f "${bastille_jail_conf}" ]; then
if [ -z ${bastille_jail_loopback} ] && [ ! -z ${bastille_jail_external} ]; then if [ -z "${bastille_jail_loopback}" ] && [ ! -z "${bastille_jail_external}" ]; then
local bastille_jail_conf_interface=${bastille_jail_external} local bastille_jail_conf_interface=${bastille_jail_external}
fi fi
if [ ! -z ${bastille_jail_loopback} ] && [ -z ${bastille_jail_external} ]; then if [ ! -z "${bastille_jail_loopback}" ] && [ -z "${bastille_jail_external}" ]; then
local bastille_jail_conf_interface=${bastille_jail_interface} local bastille_jail_conf_interface=${bastille_jail_interface}
fi fi
if [ ! -z ${INTERFACE} ]; then if [ ! -z ${INTERFACE} ]; then
@@ -374,7 +374,7 @@ if running_jail ${NAME}; then
fi fi
## check if ip address is valid ## check if ip address is valid
if [ ! -z ${IP} ]; then if [ ! -z "${IP}" ]; then
validate_ip validate_ip
else else
usage usage
+1 -1
View File
@@ -68,7 +68,7 @@ for _jail in ${JAILS}; do
jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c ${_jail} jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c ${_jail}
## add ip4.addr to firewall table:jails ## add ip4.addr to firewall table:jails
if [ ! -z ${bastille_jail_loopback} ]; then if [ ! -z "${bastille_jail_loopback}" ]; then
pfctl -q -t jails -T add $(jls -j ${_jail} ip4.addr) pfctl -q -t jails -T add $(jls -j ${_jail} ip4.addr)
fi fi
fi fi
+1 -1
View File
@@ -65,7 +65,7 @@ for _jail in ${JAILS}; do
## test if running ## test if running
elif [ $(jls name | grep -w "${_jail}") ]; then elif [ $(jls name | grep -w "${_jail}") ]; then
## remove ip4.addr from firewall table:jails ## remove ip4.addr from firewall table:jails
if [ ! -z ${bastille_jail_loopback} ]; then if [ ! -z "${bastille_jail_loopback}" ]; then
pfctl -q -t jails -T delete $(jls -j ${_jail} ip4.addr) pfctl -q -t jails -T delete $(jls -j ${_jail} ip4.addr)
fi fi
+1 -1
View File
@@ -56,7 +56,7 @@ verify_template() {
for _hook in TARGET INCLUDE PRE OVERLAY FSTAB PF PKG SYSRC SERVICE CMD; do for _hook in TARGET INCLUDE PRE OVERLAY FSTAB PF PKG SYSRC SERVICE CMD; do
_path=${_template_path}/${_hook} _path=${_template_path}/${_hook}
if [ -s ${_path} ]; then if [ -s "${_path}" ]; then
_hook_validate=$((_hook_validate+1)) _hook_validate=$((_hook_validate+1))
echo -e "${COLOR_GREEN}Detected ${_hook} hook.${COLOR_RESET}" echo -e "${COLOR_GREEN}Detected ${_hook} hook.${COLOR_RESET}"