Skip to content

Commit

Permalink
enhance lemper cli
Browse files Browse the repository at this point in the history
  • Loading branch information
joglomedia committed Sep 3, 2019
1 parent 6f2ac43 commit 7f60c24
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
31 changes: 18 additions & 13 deletions bin/lemper-cli.sh
Expand Up @@ -18,25 +18,30 @@
set -e

# Version control
ProgName=$(basename "$0")
ProgVersion="1.2.0-dev"
APP_NAME=$(basename "$0")
APP_VERSION="1.3.0"

LibDir="/usr/local/lib/lemper"

function cmd_help() {
echo "Usage: $ProgName [--version] [--help]"
echo " <command> [<options>]"
echo ""
echo "These are common $ProgName commands used in various situations:"
echo " create Create new virtual host"
echo " manage Enable, disable, delete existing virtual host"
echo ""
echo "For help with each command run:"
echo "$ProgName <command> -h|--help"
cat <<- _EOF_
${APP_NAME^} ${APP_VERSION}
Command line management tool for LEMPer stack.
Usage: $APP_NAME [--version] [--help]
<command> [<options>]
These are common $APP_NAME commands used in various situations:
create Create new virtual host
manage Enable, disable, delete existing virtual host
For help with each command run:
$APP_NAME <command> -h|--help
_EOF_
}

function cmd_version() {
echo "$ProgName version $ProgVersion"
echo "$APP_NAME version $APP_VERSION"
}

function cmd_create() {
Expand Down Expand Up @@ -73,7 +78,7 @@ case ${SubCommand} in
"cmd_${SubCommand}" "$@"
else
echo "Error: '${SubCommand}' is not a known command." >&2
echo " Run '${ProgName} --help' for a list of known commands." >&2
echo " Run '${APP_NAME} --help' for a list of known commands." >&2
exit 1
fi
;;
Expand Down
2 changes: 1 addition & 1 deletion lib/lemper-create.sh
Expand Up @@ -20,7 +20,7 @@ set -e

# Version Control.
APP_NAME=$(basename "$0")
APP_VERSION="1.2.0"
APP_VERSION="1.3.0"
CMD_PARENT="lemper-cli"
CMD_NAME="create"

Expand Down
16 changes: 8 additions & 8 deletions lib/lemper-manage.sh
Expand Up @@ -19,7 +19,7 @@ set -e

# Version control
APP_NAME=$(basename "$0")
APP_VERSION="1.2.0"
APP_VERSION="1.3.0"
CMD_PARENT="lemper-cli"
CMD_NAME="manage"

Expand Down Expand Up @@ -104,8 +104,8 @@ fi
function show_usage() {
cat <<- _EOF_
${APP_NAME^} ${APP_VERSION}
Simple NGiNX virtual host (vHost) manager
enable/disable/remove NGiNX vHost config file on Debian/Ubuntu Server.
Simple NGiNX virtual host (vHost) manager,
enable/disable/remove NGiNX vHost on Debian/Ubuntu Server.
Requirements:
* LEMP stack setup uses [LEMPer](https://github.com/joglomedia/LEMPer)
Expand Down Expand Up @@ -198,10 +198,6 @@ function remove_vhost() {
echo "Removing virtual host is not reversible."
read -t 30 -rp "Press [Enter] to continue..." </dev/tty

# Get web root path from vhost config.
# shellcheck disable=SC2154
WEBROOT=$(grep -wE "set\ $root_path" "/etc/nginx/sites-available/${1}.conf" | awk '{print $3}' | cut -d"'" -f2)

# Remove Nginx's vhost config.
if [ -f "/etc/nginx/sites-enabled/${1}.conf" ]; then
run unlink "/etc/nginx/sites-enabled/${1}.conf"
Expand All @@ -214,13 +210,17 @@ function remove_vhost() {
# Remove vhost root directory.
read -rp "Do you want to delete website root directory? [y/n]: " -e DELETE_DIR
if [[ "${DELETE_DIR}" == Y* || "${DELETE_DIR}" == y* ]]; then
# Get web root path from vhost config.

local WEBROOT && \
WEBROOT=$(grep -wE "set\ \$root_path" "/etc/nginx/sites-available/${1}.conf" | awk '{print $3}' | cut -d"'" -f2)

if [[ ! -d "${WEBROOT}" ]]; then
read -rp "Enter real path to website root directory: " -e WEBROOT
fi

if [ -d "${WEBROOT}" ]; then
run rm -fr "${WEBROOT}"
#run rm -fr "${WEBROOT}"
status "Virtual host root directory removed."
else
warning "Sorry, directory couldn't be found. Skipped..."
Expand Down

0 comments on commit 7f60c24

Please sign in to comment.