#!/bin/bash # # mkhost v0.1: add a /etc/hosts entry # feedback: rhatto at riseup.net | gpl # # Mkhost is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or any later version. # # Mkhost is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place - Suite 330, Boston, MA 02111-1307, USA # TMP="/tmp" CONF="/etc/mksite/mksite.conf" LOCKFILE="$TMP/mkhost.lock" MESSAGES="/usr/share/mksite/mksite.messages" HELPER_FUNCTIONS="/usr/libexec/mksite/mksite-helper" HOSTS_FILE="/etc/hosts" if [ -f "$HELPER_FUNCTIONS" ]; then source $HELPER_FUNCTIONS mksite_checks else echo Fatal error: function file not found, aborting. echo Erro fatal: arquivo de funcoes nao encontrado, abortando. exit 1 fi mksite_create_lockfile $LOCKFILE function usage { echo "usage: `basename $0` " } if [ ! -f "$1" ]; then echo $MESSAGE_CONFIG_NOT_FOUND $1 elif [ ! -f "$2" ]; then echo $MESSAGE_CONFIG_NOT_FOUND $2 else USER="`basename $1`" USER_CONFIG="$1" INSTANCE_CONFIG="$2" fi mksite_check_configuration DOMAIN="`mksite_eval_param $USER_CONFIG DOCROOT`" SERVER_ALIAS="`mksite_eval_param $USER_CONFIG SERVER_ALIAS`" INSTANCE_IP="`mksite_eval_param $INSTANCE_CONFIG IP`" if [ -z "$DOMAIN" ] || [ -z "$INSTANCE_IP" ]; then echo $MESSAGE_CONFIG_ERROR mksite_safe_exit 1 fi if [ ! -z "$SERVER_ALIAS" ]; then for alias in $SERVER_ALIAS; do if ! grep -qe "$alias" $HOSTS_FILE; then echo $MESSAGE_UPDATING_HOSTS echo " " echo "$INSTANCE_IP $alias" | tee -a $HOSTS_FILE echo " " fi done fi if ! grep -qe "$USER.$DOMAIN" $HOSTS_FILE; then echo $MESSAGE_UPDATING_HOSTS echo " " echo "$INSTANCE_IP $USER.$DOMAIN" | tee -a $HOSTS_FILE echo " " fi mksite_safe_exit 0