github.com/Cloud-Foundations/Dominator@v0.3.4/scripts/install.lib (about)

     1  # This file should be sourced by installer scripts.
     2  
     3  echo=
     4  
     5  readonly service_tool='/usr/sbin/service'
     6  service_is_initscripts='false'
     7  
     8  if [ -s "$service_tool" ] && [ -x "$service_tool" ]; then
     9      if [ "$(dd if=$service_tool bs=1 count=2 2> /dev/null)" == "#!" ]; then
    10  	if ! fgrep -q systemctl "$service_tool"; then
    11  	    service_is_initscripts='true'
    12  	fi
    13      fi
    14  fi
    15  
    16  get_init_system ()
    17  {
    18      if [ -x /bin/systemctl -a -d /lib/systemd/system ]; then
    19  	if [ "$service_is_initscripts" != "true" ]; then
    20  	    readonly init='systemd'
    21  	    readonly destdir='/lib/systemd/system'
    22  	    return 0
    23  	fi
    24      fi
    25      if [ -x /usr/bin/systemctl -a -d /usr/lib/systemd/system ]; then
    26  	if [ "$service_is_initscripts" != "true" ]; then
    27  	    readonly init='systemd'
    28  	    readonly destdir='/usr/lib/systemd/system'
    29  	    return 0
    30  	fi
    31      fi
    32      if [ -x /usr/sbin/update-rc.d ]; then
    33  	readonly init='update-rc.d'
    34  	if [ -d /etc/init.d ]; then
    35  	    readonly destdir='/etc/init.d'
    36  	elif [ -d /etc/rc.d/init.d ]; then
    37  	    readonly destdir='/etc/rc.d/init.d'
    38  	fi
    39  	return 0
    40      fi
    41      if [ -x /sbin/chkconfig ]; then
    42  	readonly init='chkconfig'
    43  	if [ -d /etc/init.d ]; then
    44  	    readonly destdir='/etc/init.d'
    45  	elif [ -d /etc/rc.d/init.d ]; then
    46  	    readonly destdir='/etc/rc.d/init.d'
    47  	fi
    48  	return 0
    49      fi
    50      echo 'Unknown init system' 2>&1
    51      exit 1
    52  }
    53  
    54  get_os ()
    55  {
    56      if [ -r /etc/lsb-release ]; then
    57  	DISTRIB_ID=
    58  	DISTRIB_RELEASE=
    59  	. /etc/lsb-release
    60  	if [ -n "$DISTRIB_ID" ] && [ -n "$DISTRIB_RELEASE" ]; then
    61  	    echo "$DISTRIB_ID-$DISTRIB_RELEASE"
    62  	    return
    63  	fi
    64      fi
    65      if [ -r /etc/redhat-release ]; then
    66  	if fgrep -q 'CentOS release 6.' /etc/redhat-release; then
    67  	    echo 'CentOS-6'
    68  	    return
    69  	fi
    70      fi
    71      if [ -r /etc/debian_version ]; then
    72  	echo "Debian-$(cut -d . -f 1 /etc/debian_version)"
    73  	return
    74      fi
    75      echo 'Unknown OS' 2>&1
    76      exit 1
    77  }
    78  
    79  install_service ()
    80  {
    81      local -r service="$1"
    82  
    83      if [ "$init" = 'systemd' ]; then
    84  	$echo cp -p "init.d/${service}.service" "$destdir" || return
    85  	$echo systemctl enable "$service" || return
    86      elif [ "$init" = 'update-rc.d' ]; then
    87  	$echo cp -p "init.d/${service}.$(get_os)" "$destdir/$service" || return
    88  	$echo update-rc.d "$service" defaults || return
    89      elif [ "$init" = 'chkconfig' ]; then
    90  	$echo cp -p "init.d/${service}.$(get_os)" "$destdir/$service" || return
    91  	$echo chkconfig --add "$service" || return
    92  	$echo chkconfig "$service" on || return
    93      else
    94  	echo 'Unknown init system' 2>&1
    95  	exit 1
    96      fi
    97  }
    98  
    99  install_all ()
   100  {
   101      local -r service="$1"
   102  
   103      $echo mkdir -p /etc/ssl/$service || exit
   104      $echo cp -p ssl/*CA*.pem /etc/ssl || exit
   105      $echo cp -p ssl/$service/*.pem /etc/ssl/$service
   106      $echo mkdir -p /usr/local/sbin || exit
   107      $echo cp -p bin/* /usr/local/sbin || exit
   108      $echo mkdir -p /etc/health-agent/tests.d
   109      $echo cp -p health-check.yml "/etc/health-agent/tests.d/$service.yml" || exit
   110      install_service $service || exit
   111  }
   112  
   113  # Run get_init_system only once because it defines read-only variables.
   114  get_init_system