Skip to content

Commit

Permalink
Rename the flag function, add a flag_is_unset and update the scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
JF Le Fillâtre committed Jul 20, 2016
1 parent bf38676 commit 0f5b68a
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 32 deletions.
42 changes: 30 additions & 12 deletions configuration/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,27 +246,45 @@ typeset -fx store_password
# Due to the sheer amount of acceptables values for a flag enabled or disabled,
# better have some functions for that.

# Returns a single 0/1 value for the state of a variable used as a flag
# A flag is OFF when either of these conditions is met:
# - it is unset
# - it is set to "0", "n" or "no" (in small or capital letters)
# In all other cases, it's ON.
# Return a single 0/1 value for the state of a variable used as a flag, and a
# -1 if there weren't enough parameters.

# Syntax: flag_on variable_name
# A flag is UNSET or OFF when any of these conditions is met:
# - the variable is unset
# - the variable is set to "0", "n" or "no" (in small or capital letters)
# In all other cases, it's SET or ON.

function flag_on {
# Syntax: flag_is_set variable_name
# flag_is_unset variable_name

function flag_is_set {

# always return false if we don't have the right arguments
if (( $# != 1 )) ; then
echo_warn 'flag_on: wrong number of arguments.'
return 1
echo_warn 'flag_is_set: wrong number of arguments.'
return 254
fi

name="$1"
value="${!name}"

[[ ! -v "$name" || "${value,,}" =~ 0|n|no ]] && return 1 || return 0
[[ -v "$name" && ! "${value,,}" =~ 0|n|no ]]
}

typeset -fx flag_on

function flag_is_unset {

if (( $# != 1 )) ; then
echo_warn 'flag_is_unset: wrong number of arguments.'
return 254
fi

name="$1"
value="${!name}"

[[ ! -v "$name" || "${value,,}" =~ 0|n|no ]]
}


typeset -fx flag_is_set
typeset -fx flag_is_unset

2 changes: 1 addition & 1 deletion configuration/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function run_one_script {

ret=0

if ! flag_on SKIPPKGLIST ; then
if flag_is_unset SKIPPKGLIST ; then

# Start with installing the packages if we have a list
if [[ -r "$POST_PKGLIST" ]] ; then
Expand Down
2 changes: 1 addition & 1 deletion configuration/controller/additional-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
source "$POST_CONFIG"

systemctl enable haveged
flag_on CHROOT_INSTALL || systemctl restart haveged
flag_is_unset CHROOT_INSTALL && systemctl restart haveged

20 changes: 11 additions & 9 deletions configuration/controller/chronyd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "$POST_CONFIG"
modified=0


if [[ "$CHRONY_UPSTREAM" ]] ; then
if flag_is_set CHRONY_UPSTREAM ; then

echo_info 'Setting up upstream time servers'

Expand All @@ -22,7 +22,7 @@ if [[ "$CHRONY_UPSTREAM" ]] ; then
fi


if [[ "$CHRONY_SERVER" ]] && ! [[ "$CHRONY_SERVER" == 0 ]] ; then
if flag_is_set CHRONY_SERVER ; then

echo_info 'Enabling client access'

Expand All @@ -38,12 +38,14 @@ if [[ "$CHRONY_SERVER" ]] && ! [[ "$CHRONY_SERVER" == 0 ]] ; then
fi


if (( $modified )) && ! flag_on CHROOT_INSTALL ; then

echo_info 'Restarting the service'
systemctl restart chronyd
else

echo_warn 'No change requested'
if flag_is_unset CHROOT_INSTALL ; then
if (( $modified )) ; then

echo_info 'Restarting the service'
systemctl restart chronyd
else

echo_warn 'No change requested'
fi
fi

2 changes: 1 addition & 1 deletion configuration/controller/environment-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source /etc/trinity.sh
source "$POST_CONFIG"


if ! flag_on CHROOT_INSTALL ; then
if flag_is_unset CHROOT_INSTALL ; then

echo_info 'Creating the shared modules directories'

Expand Down
4 changes: 2 additions & 2 deletions configuration/controller/local-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ echo_info 'Copying packages and setting up the local repositories'
# On a node, those are made available via bind mount at installation time, and
# NFS later.

if ! flag_on CHROOT_INSTALL ; then
if flag_is_unset CHROOT_INSTALL ; then
# Copy the whole tree with all local repos
mkdir -p "${TRIX_ROOT}/shared"
cp -r "${POST_TOPDIR}/packages" "${TRIX_ROOT}/shared"
Expand All @@ -41,7 +41,7 @@ done

# Disable remote repositories if requested

if flag_on REPOS_DISABLE_REMOTE ; then
if flag_is_set REPOS_DISABLE_REMOTE ; then

echo_info 'Disabling all remote repositories'

Expand Down
2 changes: 1 addition & 1 deletion configuration/controller/rdma-centos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ echo_info 'Enabling and starting the RDMA service'

systemctl enable rdma
# The restart fails but the start behaves like a restart, so...
flag_on CHROOT_INSTALL || systemctl start rdma
flag_is_unset CHROOT_INSTALL && systemctl start rdma

2 changes: 1 addition & 1 deletion configuration/controller/yum-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ store_system_variable /etc/yum.conf keepcache 1

# Do we need to clear everything first?

if flag_on YUM_CLEAR_CACHE ; then
if flag_is_set YUM_CLEAR_CACHE ; then

echo_info 'Clearing the yum cache'

Expand Down
6 changes: 3 additions & 3 deletions configuration/images/create-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ DIRTMPLIST=( \

# Add the host repos and yum cache only if requested

if flag_on NODE_HOST_REPOS ; then
if flag_is_set NODE_HOST_REPOS ; then
DIRLIST+=( /var/cache/yum )
DIRTMPLIST+=( /etc/yum.repos.d )
fi
Expand Down Expand Up @@ -158,7 +158,7 @@ fi
# This is the big block for image configuration. Better read the comments
# carefully before changing anything.

if flag_on NODE_IMG_CONFIG ; then
if flag_is_set NODE_IMG_CONFIG ; then

echo_info 'Creating the /etc/trinity.sh symlink in the image'

Expand Down Expand Up @@ -191,7 +191,7 @@ if flag_on NODE_IMG_CONFIG ; then
[[ -v longlist ]] && yum --installroot="$TARGET" -y install $longlist
)

if flag_on NODE_YUM_UPDATE ; then
if flag_is_set NODE_YUM_UPDATE ; then
echo_info 'Running yum update in the image'
yum --installroot="$TARGET" -y update
fi
Expand Down
2 changes: 1 addition & 1 deletion configuration/images/standard-configuration-nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ source "$POST_CONFIG"

#---------------------------------------

if flag_on STDCFG_SSHROOT ; then
if flag_is_set STDCFG_SSHROOT ; then
echo_info "Allowing SSH login as root"
sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
else
Expand Down

0 comments on commit 0f5b68a

Please sign in to comment.