Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(install): create centreon sudoer file if not exist (#5890)
Browse files Browse the repository at this point in the history
* fix(install): add mandatory params to create user

* fix(install): add function to create file with question

* fix(install): create centreon sudoer file if not exist
  • Loading branch information
lpinsivy authored and loiclau committed Nov 27, 2017
1 parent 31c4a1d commit 166db88
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions libinstall/functions
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,50 @@ function answer_with_createdir() {
return 0
}

#----
## print a message, create file if file not exists
## Loop if not a valid file
## @param message
## @param default value (use "NO_DEFAULT" if not default value)
## @param global variable to set a result
## @return 0 end
#----
function answer_with_createfile() {
local message=$1
local default=$2
local var_ref=$3
local res="not_define"
local first=0
while [ ! -f "$res" ] ; do
[ $first -eq 1 ] && echo_passed "$(gettext "File $res does not exists.")" "$critical"
echo -e "\n$message"
[ "$default" != "NO_DEFAULT" ] && echo -e "$(gettext "default to") [$default]"
echo -en "> "
read res
if [ -z "$res" ] ; then
[ "$default" != "NO_DEFAULT" ] && res=$default
fi
if [ -z "${res#/}" -o "$yes" = "$res" -o "$no" = "$res" ] ; then
echo_passed "$(gettext "You select slash...")"
res="not_define"
else
first=1
[ -f "$res" ] && break
yes_no_default "$(gettext "Do you want me to create this file ?") [$res]"
if [ $? -eq 0 ] ; then
touch $res
if [ $? -ne 0 ] ; then
echo_passed "$(gettext "Could not create file.")" "$critical"
#continue
fi
log "INFO" "$(gettext "Creating") : $res"
fi
fi
done
eval $var_ref=$res
return 0
}

#----
## print a message, test if file exists
## Loop if not a valid file
Expand Down Expand Up @@ -935,7 +979,7 @@ function locate_centreontrapd_bindir() {
#----
function locate_sudo() {
if [ -z "$SUDO_FILE" ] ; then
answer_with_testfile "$(gettext "Where is sudo configuration file")" "$DEFAULT_SUDO_FILE" "SUDO_FILE"
answer_with_createfile "$(gettext "Where is sudo configuration file")" "$DEFAULT_SUDO_FILE" "SUDO_FILE"
echo_success "$SUDO_FILE" "$ok"
fi
SUDO_FILE=`trim ${SUDO_FILE%/}`
Expand Down Expand Up @@ -1837,7 +1881,7 @@ function check_centreon_user()
fi
fi
if [ -z "$CENTREON_USER" ] ; then
answer_with_createuser "$(gettext "What is the Centreon user ?") [$DEFAULT_CENTREON_USER]" "$DEFAULT_CENTREON_USER" "CENTREON_USER"
answer_with_createuser "$(gettext "What is the Centreon user ?") [$DEFAULT_CENTREON_USER]" "$DEFAULT_CENTREON_USER" "CENTREON_USER" "$groups" "$description" "$home"
fi
log "INFO" "$(gettext "Centreon user") : $CENTREON_USER"
return 0
Expand Down

0 comments on commit 166db88

Please sign in to comment.