Added system_check function.

This commit is contained in:
Edi Septriyanto
2019-12-26 00:19:25 +07:00
parent 9f987119d9
commit 8ad9264b44
2 changed files with 60 additions and 49 deletions

View File

@@ -50,53 +50,7 @@ fi
requires_root
# Make sure only supported distribution can run this installer script.
export DISTRIB_NAME && DISTRIB_NAME=$(get_distrib_name)
export RELEASE_NAME && RELEASE_NAME=$(get_release_name)
if [[ "${RELEASE_NAME}" == "unsupported" ]]; then
fail "This Linux distribution isn't supported yet. If you'd like it to be, let us know at https://github.com/joglomedia/LEMPer/issues"
else
# Set system architecture.
export ARCH && \
ARCH=$(uname -p)
# Set default timezone.
export TIMEZONE
if [[ -z "${TIMEZONE}" || "${TIMEZONE}" = "none" ]]; then
[ -f /etc/timezone ] && TIMEZONE=$(cat /etc/timezone) || TIMEZONE="UTC"
fi
# Set ethernet interface.
export IFACE && \
IFACE=$(find /sys/class/net -type l | grep -e "enp\|eth0" | cut -d'/' -f5)
# Set server IP.
export SERVER_IP && \
SERVER_IP=${SERVER_IP:-$(get_ip_addr)}
# Set server hostname.
if [ -z "${HOSTNAME}" ]; then
export HOSTNAME && \
HOSTNAME=$(hostname)
fi
# Validate server's hostname for production stack.
if [[ "${ENVIRONMENT}" = "production" ]]; then
# Check if the hostname is valid.
if [[ $(validate_fqdn "${HOSTNAME}") != true ]]; then
error "Your server's hostname is not fully qualified domain name (FQDN)."
echo -e "Please update your hostname to qualify the FQDN format and\nthen points your hostname to this server ip ${SERVER_IP} !"
exit 1
fi
# Check if the hostname is pointed to server IP address.
if [[ $(dig "${HOSTNAME}" +short) != "${SERVER_IP}" ]]; then
error "It seems that your server's hostname is not yet pointed to your server's IP address."
echo -e "Please update your DNS record by adding an A record and point it to your server IP ${SERVER_IP} !"
exit 1
fi
fi
fi
system_check
##

View File

@@ -273,7 +273,9 @@ function validate_fqdn() {
fi
}
##
# Make sure only root can run LEMPer script.
#
function requires_root() {
if [ "$(id -u)" -ne 0 ]; then
error "This command can only be used by root."
@@ -281,6 +283,59 @@ function requires_root() {
fi
}
##
# Make sure only supported distribution can run this installer script.
#
function system_check() {
export DISTRIB_NAME && DISTRIB_NAME=$(get_distrib_name)
export RELEASE_NAME && RELEASE_NAME=$(get_release_name)
if [[ "${RELEASE_NAME}" == "unsupported" ]]; then
fail "This Linux distribution isn't supported yet. If you'd like it to be, let us know at https://github.com/joglomedia/LEMPer/issues"
else
# Set system architecture.
export ARCH && \
ARCH=$(uname -p)
# Set default timezone.
export TIMEZONE
if [[ -z "${TIMEZONE}" || "${TIMEZONE}" = "none" ]]; then
[ -f /etc/timezone ] && TIMEZONE=$(cat /etc/timezone) || TIMEZONE="UTC"
fi
# Set ethernet interface.
export IFACE && \
IFACE=$(find /sys/class/net -type l | grep -e "enp\|eth0" | cut -d'/' -f5)
# Set server IP.
export SERVER_IP && \
SERVER_IP=${SERVER_IP:-$(get_ip_addr)}
# Set server hostname.
if [ -z "${HOSTNAME}" ]; then
export HOSTNAME && \
HOSTNAME=$(hostname)
fi
# Validate server's hostname for production stack.
if [[ "${ENVIRONMENT}" = "production" ]]; then
# Check if the hostname is valid.
if [[ $(validate_fqdn "${HOSTNAME}") != true ]]; then
error "Your server's hostname is not fully qualified domain name (FQDN)."
echo -e "Please update your hostname to qualify the FQDN format and\nthen points your hostname to this server ip ${SERVER_IP} !"
exit 1
fi
# Check if the hostname is pointed to server IP address.
if [[ $(dig "${HOSTNAME}" +short) != "${SERVER_IP}" ]]; then
error "It seems that your server's hostname is not yet pointed to your server's IP address."
echo -e "Please update your DNS record by adding an A record and point it to your server IP ${SERVER_IP} !"
exit 1
fi
fi
fi
}
function delete_if_already_exists() {
if "$DRYRUN"; then return; fi
@@ -572,7 +627,7 @@ function get_ip_addr() {
# Init logging.
function init_log() {
[ ! -e lemper.log ] && touch lemper.log
[ ! -f lemper.log ] && run touch lemper.log
save_log "Initialize LEMPer installation log..."
}
@@ -591,14 +646,16 @@ function save_log() {
function init_config() {
if [ ! -f /etc/lemper/lemper.conf ]; then
run mkdir -p /etc/lemper/
run touch /etc/lemper/lemper.conf
fi
run bash -c "echo -e '# LEMPer configuration.\n# Edit here if you change your password manullay, but do NOT delete!' > /etc/lemper/lemper.conf"
save_log -e "# LEMPer configuration.\n# Edit here if you change your password manually, but do NOT delete!"
}
# Save configuration.
function save_config() {
if ! ${DRYRUN}; then
[ -f /etc/lemper/lemper.conf ] && \
echo "$@" >> /etc/lemper/lemper.conf
fi
}