[Groonga-commit] droonga/droonga-http-server at 83e0b0b [master] Detect host name by the "hostname" command.

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Sep 16 18:09:26 JST 2014


YUKI Hiroshi	2014-09-16 18:09:26 +0900 (Tue, 16 Sep 2014)

  New Revision: 83e0b0b5697a9e2c203606052e871aaa42b4f2ca
  https://github.com/droonga/droonga-http-server/commit/83e0b0b5697a9e2c203606052e871aaa42b4f2ca

  Message:
    Detect host name by the "hostname" command.

  Modified files:
    install.sh

  Modified: install.sh (+26 -41)
===================================================================
--- install.sh    2014-09-16 16:33:08 +0900 (a2b9e57)
+++ install.sh    2014-09-16 18:09:26 +0900 (a7a9c76)
@@ -95,8 +95,7 @@ setup_configuration_directory() {
 
     [ "$HOST" = "Auto Detect" ] &&
       determine_hostname \
-        "If this node has a global host name or a global IP address, then choose \"Manual Input\" and type it. Otherwise, choose a preferred IP address which can be accessed from the droonga-engine node." \
-        "Enter a global host name or a global IP address for this node" &&
+        "Enter a host name or an IP address which is accessible from the droonga-engine node" &&
       HOST=$DETERMINED_HOSTNAME
 
     curl -o $config_file.template $SCRIPT_URL/$PLATFORM/$NAME.yaml
@@ -111,55 +110,41 @@ setup_configuration_directory() {
 }
 
 
-get_addresses_with_interface() {
-  if exist_command ip; then
-    ip addr | grep "inet " | \
-      $sed -e "s/^ *inet ([0-9\.]+).+ ([^ ]+)\$/\1 \2/"
-    return 0
-  fi
-
-  if exist_command ifconfig; then
-    interfaces=$(ifconfig -s | cut -d " " -f 1 | tail -n +2)
-    for interface in $interfaces; do
-      address=$(LANG=C ifconfig $interface | grep "inet addr" | \
-                $sed -e "s/^ *inet addr:([0-9\.]+).+\$/\1/")
-      if [ "$address" != "" ]; then
-        echo $address $interface
-      fi
-    done
-    return 0
+guess_global_hostname() {
+  if hostname -d > /dev/null 2>&1; then
+    domain=$(hostname -d)
+    hostname=$(hostname)
+    if [ "$domain" != "" ]; then
+      echo "$hostname.$domain"
+      return 0
+    fi
   fi
-
-  echo "127.0.0.1 lo"
-  return 0
+  echo ""
+  return 1
 }
 
 determine_hostname() {
-  prompt_for_suggestions="$1"
-  prompt_for_manual_input="$2"
+  prompt_for_manual_input="$1"
 
-  if [ $(get_addresses_with_interface | wc -l) -eq 1 ]; then
-    DETERMINED_HOSTNAME=$(get_addresses_with_interface | cut -d " " -f 1)
+  global_hostname=$(guess_global_hostname)
+  if [ "$global_hostname" != "" ]; then
+    DETERMINED_HOSTNAME="$global_hostname"
     return 0
   fi
 
-  PS3="$prompt_for_suggestions: "
-  select chosen in $(get_addresses_with_interface | \
-                     $sed -e "s/ (.+)\$/(\1)/") "Manual Input"
-  do
-    if [ -z "$chosen" ]; then
-      continue
-    else
-      DETERMINED_HOSTNAME=$(echo $chosen | cut -d "(" -f 1)
-      break
-    fi
-  done
-
-  if [ "$DETERMINED_HOSTNAME" = "Manual Input" ]; then
-    input_hostname "$prompt_for_manual_input" &&
-      DETERMINED_HOSTNAME="$TYPED_HOSTNAME"
+  address=$(hostname -i | \
+            $sed -e "s/127\.[0-9]+\.[0-9]+\.[0-9]+//g" \
+                 -e "s/  +/ /g" \
+                 -e "s/^ +| +\$//g" |\
+            cut -d " " -f 1)
+  if [ "$address" != "" ]; then
+    DETERMINED_HOSTNAME="$address"
+    return 0
   fi
 
+  input_hostname "$prompt_for_manual_input" &&
+    DETERMINED_HOSTNAME="$TYPED_HOSTNAME"
+
   return 0
 }
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index