mirror of
https://github.com/joglomedia/LEMPer.git
synced 2026-04-11 23:48:19 +00:00
Improve cli command
This commit is contained in:
@@ -172,6 +172,8 @@ These are common ${PROG_NAME} commands used in various situations:
|
||||
For help with each command run:
|
||||
${PROG_NAME} <command> -h | --help
|
||||
EOL
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
##
|
||||
@@ -179,6 +181,7 @@ EOL
|
||||
##
|
||||
function cmd_version() {
|
||||
echo "${PROG_NAME} version ${PROG_VERSION}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
##
|
||||
@@ -193,11 +196,9 @@ function init_lemper_cli() {
|
||||
case "${CMD}" in
|
||||
help | -h | --help)
|
||||
cmd_help
|
||||
exit 0
|
||||
;;
|
||||
version | -v | --version)
|
||||
cmd_version
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
if [[ -x "${CLI_PLUGINS_DIR}/lemper-${CMD}" ]]; then
|
||||
|
||||
@@ -906,15 +906,15 @@ function init_lemper_create() {
|
||||
if [[ "${MAIN_ARGS}" -ge 1 ]]; then
|
||||
# Additional Check - ensure that Nginx's configuration meets the requirements.
|
||||
if [[ ! -d /etc/nginx/sites-available && ! -d /etc/nginx/vhost ]]; then
|
||||
fail "It seems that your Nginx installation doesn't meet LEMPer requirements. Aborting..."
|
||||
fail "Your Nginx installation does not meet the LEMPer stack requirements. The installation has been aborted."
|
||||
fi
|
||||
|
||||
# Check domain parameter.
|
||||
if [[ -z "${SERVERNAME}" ]]; then
|
||||
fail -e "Domain name parameter shouldn't be empty.\n -d or --domain-name parameter is required!"
|
||||
fail -e "The domain name parameter should not be empty. \n -d or --domain-name parameter is required!"
|
||||
else
|
||||
if [[ $(validate_fqdn "${SERVERNAME}") == false ]]; then
|
||||
fail "Your Domain name is not valid 'Fully Qualified Domain Name (FQDN)' format!"
|
||||
fail "Invalid input: '${SERVERNAME}' is not a valid FQDN. Expected format: example.com."
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -928,17 +928,17 @@ function init_lemper_create() {
|
||||
|
||||
# Check if vhost not exists.
|
||||
if [[ ! -f "${VHOST_FILE}" ]]; then
|
||||
echo "Add new domain name '${SERVERNAME}' to virtual host."
|
||||
echo "Adding domain ${SERVERNAME} to the Nginx virtual host configuration."
|
||||
|
||||
# Check for username.
|
||||
if [[ -z "${USERNAME}" ]]; then
|
||||
info "Username parameter is empty. Attempt to use default '${LEMPER_USERNAME}' account."
|
||||
info "Username parameter is empty. Using default account: '${LEMPER_USERNAME}'."
|
||||
USERNAME=${LEMPER_USERNAME:-"lemper"}
|
||||
fi
|
||||
|
||||
# Additional Check - are user account exist?
|
||||
if [[ -z $(getent passwd "${USERNAME}") ]]; then
|
||||
fail "User account '${USERNAME}' does not exist. Please add new account first! Aborting..."
|
||||
fial "User account '${USERNAME}' does not exist. Create the account first. Aborting..."
|
||||
fi
|
||||
|
||||
# Check PHP runtime version is exists.
|
||||
@@ -949,8 +949,8 @@ function init_lemper_create() {
|
||||
|
||||
# Additional check - if FPM user's pool doesn't exist.
|
||||
if [[ ! -f "/etc/php/${PHP_VERSION}/fpm/pool.d/${USERNAME}.conf" ]]; then
|
||||
info "The PHP${PHP_VERSION} FPM pool configuration for user ${USERNAME} doesn't exist."
|
||||
echo "Creating new PHP-FPM pool '${USERNAME}' configuration..."
|
||||
info "PHP ${PHP_VERSION} FPM pool configuration for user '${USERNAME}' does not exist."
|
||||
echo "Creating new PHP ${PHP_VERSION} FPM pool configuration for '${USERNAME}'..."
|
||||
|
||||
# Create PHP FPM pool conf.
|
||||
create_fpm_pool_conf "${USERNAME}" "${PHP_VERSION}" > "/etc/php/${PHP_VERSION}/fpm/pool.d/${USERNAME}.conf"
|
||||
@@ -969,25 +969,23 @@ function init_lemper_create() {
|
||||
run chown -hR "${USERNAME}:${USERNAME}" "/home/${USERNAME}/.lemper" "/home/${USERNAME}/cgi-bin" "/home/${USERNAME}/logs"
|
||||
|
||||
# Restart PHP FPM.
|
||||
echo "Restart php${PHP_VERSION}-fpm configuration..."
|
||||
|
||||
echo "Restarting php${PHP_VERSION}-fpm configuration..."
|
||||
run systemctl restart "php${PHP_VERSION}-fpm"
|
||||
|
||||
success "New php${PHP_VERSION}-fpm pool [${USERNAME}] has been created."
|
||||
success "PHP ${PHP_VERSION} FPM pool '[${USERNAME}]' has been created."
|
||||
fi
|
||||
else
|
||||
fail "Oops, PHP ${PHP_VERSION} runtime not found. Please install it first! Aborting..."
|
||||
fail "PHP ${PHP_VERSION} is not installed. Install it before proceeding. Aborting..."
|
||||
fi
|
||||
|
||||
# Check web root parameter.
|
||||
if [[ -z "${WEBROOT}" ]]; then
|
||||
WEBROOT="/home/${USERNAME}/webapps/${SERVERNAME}"
|
||||
info "Webroot parameter is empty. Set to default web root '${WEBROOT}'."
|
||||
info "Web root path parameter is empty. Using default path: '${WEBROOT}'."
|
||||
fi
|
||||
|
||||
# Creates document root.
|
||||
if [[ ! -d "${WEBROOT}" ]]; then
|
||||
echo "Creating web root directory '${WEBROOT}'..."
|
||||
echo "Creating web root directory: '${WEBROOT}'."
|
||||
|
||||
run mkdir -p "${WEBROOT}" && \
|
||||
run chown -hR "${USERNAME}:${USERNAME}" "${WEBROOT}" && \
|
||||
@@ -1006,10 +1004,10 @@ function init_lemper_create() {
|
||||
# Check framework parameter.
|
||||
if [[ -z "${FRAMEWORK}" ]]; then
|
||||
FRAMEWORK="default"
|
||||
info "Framework parameter is empty. Set to default framework '${FRAMEWORK}'."
|
||||
info "Framework parameter is empty. Using default: '${FRAMEWORK}'."
|
||||
fi
|
||||
|
||||
echo "Selecting '${FRAMEWORK^}' framework..."
|
||||
echo "Configuring '${FRAMEWORK^}' framework..."
|
||||
|
||||
# Ugly hacks for custom framework-specific configs + Skeleton auto installer.
|
||||
case "${FRAMEWORK}" in
|
||||
|
||||
@@ -82,10 +82,13 @@ These are common ${CMD_PARENT} ${CMD_NAME} account subcommands used in various s
|
||||
For help with each command run:
|
||||
${CMD_PARENT} ${CMD_NAME} account <command> -h|--help
|
||||
EOL
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
function cmd_account_version() {
|
||||
echo "${CMD_PARENT} ${CMD_NAME} account version ${PROG_VERSION}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Grant access privileges.
|
||||
@@ -105,10 +108,11 @@ function cmd_account_access() {
|
||||
if "${MYSQLCLI}" -u root -p"${MYSQL_ROOT_PASSWORD}" -e "SHOW DATABASES;" | grep -qwE "${DBNAME}"; then
|
||||
echo "Grants database '${DBNAME}' privileges to '${DBUSER}'@'${DBHOST}'"
|
||||
run "${MYSQLCLI}" -u root -p"${MYSQL_ROOT_PASSWORD}" -e "GRANT ${DBPRIVILEGES} ON ${DBNAME}.* TO '${DBUSER}'@'${DBHOST}'; FLUSH PRIVILEGES;"
|
||||
exit 0
|
||||
else
|
||||
fail "The specified database '${DBNAME}' does not exist."
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Creates a new account.
|
||||
@@ -127,12 +131,17 @@ function cmd_account_create() {
|
||||
|
||||
if "${MYSQLCLI}" -u root -p"${MYSQL_ROOT_PASSWORD}" -e "SELECT User FROM mysql.user WHERE user='${DBUSER}';" | grep -qwE "${DBUSER}"; then
|
||||
success "MySQL account ${DBUSER} has been created."
|
||||
[[ ${VERBOSE} == true ]] && echo -e "Below the account details:\nUsername: ${DBUSER}\nPassword: ${DBPASS}\nHost: ${DBHOST}"
|
||||
|
||||
if [[ ${VERBOSE} == true ]]; then
|
||||
echo -e "Below the account details:\nUsername: ${DBUSER}\nPassword: ${DBPASS}\nHost: ${DBHOST}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
fail "Root user is already exist. Please use another one!"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Deletes an existing account.
|
||||
@@ -156,6 +165,8 @@ function cmd_account_delete() {
|
||||
info "SQL query: \"${SQL_QUERY}\""
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Update password.
|
||||
@@ -183,6 +194,8 @@ function cmd_account_passwd() {
|
||||
else
|
||||
info "SQL query: \"${SQL_QUERY}\""
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Rename an existing account.
|
||||
@@ -216,6 +229,8 @@ function cmd_account_rename() {
|
||||
else
|
||||
info "SQL query: \"${SQL_QUERY}\""
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# List all database users
|
||||
@@ -227,6 +242,8 @@ function cmd_account_users() {
|
||||
echo "List all existing database users."
|
||||
|
||||
run "${MYSQLCLI}" -u "${DBUSER}" -p"${DBPASS}" -e "SELECT user,host FROM mysql.user;"
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Aliases to create.
|
||||
@@ -255,11 +272,9 @@ function init_cmd_account() {
|
||||
case "${SUBCOMMAND}" in
|
||||
help | -h | --help)
|
||||
cmd_account_help
|
||||
exit 0
|
||||
;;
|
||||
version | -v | --version)
|
||||
cmd_account_version
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
if declare -F "cmd_account_${SUBCOMMAND}" &>/dev/null; then
|
||||
@@ -473,11 +488,12 @@ function db_operations() {
|
||||
run "${MYSQLCLI}" -u root -p"${DBPASS}" -e "${SQL_QUERY}"
|
||||
|
||||
if "${MYSQLCLI}" -u root -p"${DBPASS}" -e "SHOW DATABASES LIKE '${DBNAME}';" | grep -qwE "${DBNAME}"; then
|
||||
success "MySQL database '${DBNAME}' has been created."
|
||||
exit 0
|
||||
success "MySQL database '${DBNAME}' has been created and granted to '${DBUSER}'@'${DBHOST}'."
|
||||
else
|
||||
fail "Failed creating database '${DBNAME}'."
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
|
||||
# List all databases.
|
||||
@@ -500,7 +516,7 @@ function db_operations() {
|
||||
DBS=(${DATABASES})
|
||||
IFS=${SAVEIFS} # Restore IFS
|
||||
|
||||
echo "There are ${#DBS[@]} databases granted to '${DBUSER}'."
|
||||
success "There are ${#DBS[@]} databases granted to '${DBUSER}'."
|
||||
echo "+-------------------------------------+"
|
||||
echo "| 'database'@'host' |"
|
||||
echo "+-------------------------------------+"
|
||||
@@ -513,8 +529,10 @@ function db_operations() {
|
||||
|
||||
echo "+-------------------------------------+"
|
||||
else
|
||||
echo "No database found."
|
||||
info "There is no database granted to '${DBUSER}'."
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
|
||||
# Drope / delete database.
|
||||
@@ -535,11 +553,13 @@ function db_operations() {
|
||||
if ! "${MYSQLCLI}" -u root -p"${DBPASS}" -e "SHOW DATABASES LIKE '${DBNAME}';" | grep -qwE "${DBNAME}"; then
|
||||
success "Database '${DBNAME}' has been dropped."
|
||||
else
|
||||
fail "Failed deleting database '${DBNAME}'."
|
||||
fail "Failed deropping database '${DBNAME}'."
|
||||
fi
|
||||
else
|
||||
fail "The specified database '${DBNAME}' does not exist."
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
|
||||
# Export / dump database to file.
|
||||
@@ -572,6 +592,8 @@ function db_operations() {
|
||||
else
|
||||
fial "Mysqldump is required to export database, but it is not available in your current stack. Please install it first."
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
|
||||
# Import database from file.
|
||||
@@ -590,13 +612,15 @@ function db_operations() {
|
||||
|
||||
if "${MYSQLCLI}" -u "${DBUSER}" -p"${DBPASS}" -e "SHOW DATABASES;" | grep -qwE "${DBNAME}"; then
|
||||
run "${MYSQLCLI}" -u "${DBUSER}" -p"${DBPASS}" "${DBNAME}" < "${DBFILE}"
|
||||
echo "Database file '${DBFILE}' has been successfully imported to '${DBNAME}'."
|
||||
success "Database file '${DBFILE}' has been successfully imported to '${DBNAME}'."
|
||||
else
|
||||
fail "The specified database '${DBNAME}' does not exist."
|
||||
fi
|
||||
else
|
||||
fail "Please specifiy the database file (.sql) to import using --dbfile parameter."
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
|
||||
# Perform SQL query.
|
||||
@@ -622,6 +646,8 @@ function db_operations() {
|
||||
else
|
||||
info "SQL query: \"${SQL_QUERY}\""
|
||||
fi
|
||||
|
||||
exit 0
|
||||
;;
|
||||
|
||||
*)
|
||||
@@ -797,10 +823,13 @@ Example:
|
||||
For help with each command run:
|
||||
${CMD_PARENT} ${CMD_NAME} <command> -h|--help
|
||||
EOL
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
function cmd_version() {
|
||||
echo "${CMD_PARENT} ${CMD_NAME} version ${PROG_VERSION}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
##
|
||||
@@ -815,11 +844,9 @@ function init_lemper_db() {
|
||||
case ${SUBCMD} in
|
||||
help | -h | --help)
|
||||
cmd_help
|
||||
exit 0
|
||||
;;
|
||||
version | -v | --version)
|
||||
cmd_version
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
if declare -F "cmd_${SUBCMD}" &>/dev/null; then
|
||||
|
||||
Reference in New Issue
Block a user