setup 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. #!/bin/sh
  2. #
  3. # BEGIN COPYRIGHT BLOCK
  4. # This Program is free software; you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation; version 2 of the License.
  7. #
  8. # This Program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  14. # Place, Suite 330, Boston, MA 02111-1307 USA.
  15. #
  16. # In addition, as a special exception, Red Hat, Inc. gives You the additional
  17. # right to link the code of this Program with code not covered under the GNU
  18. # General Public License ("Non-GPL Code") and to distribute linked combinations
  19. # including the two, subject to the limitations in this paragraph. Non-GPL Code
  20. # permitted under this exception must only link to the code of this Program
  21. # through those well defined interfaces identified in the file named EXCEPTION
  22. # found in the source code files (the "Approved Interfaces"). The files of
  23. # Non-GPL Code may instantiate templates or use macros or inline functions from
  24. # the Approved Interfaces without causing the resulting work to be covered by
  25. # the GNU General Public License. Only Red Hat, Inc. may make changes or
  26. # additions to the list of Approved Interfaces. You must obey the GNU General
  27. # Public License in all respects for all of the Program code and other code used
  28. # in conjunction with the Program except the Non-GPL Code covered by this
  29. # exception. If you modify this file, you may extend this exception to your
  30. # version of the file, but you are not obligated to do so. If you do not wish to
  31. # provide this exception without modification, you must delete this exception
  32. # statement from your version and license this file solely under the GPL without
  33. # exception.
  34. #
  35. #
  36. # Copyright (C) 2005 Red Hat, Inc.
  37. # All rights reserved.
  38. # END COPYRIGHT BLOCK
  39. #
  40. ###########################
  41. #
  42. # This shell script provides a way to set up a new installation after
  43. # the binaries have already been extracted. This is typically after
  44. # using native packaging support to install the package e.g. RPM,
  45. # pkgadd, depot, etc. This script will show the license, readme,
  46. # dsktune, then run the usual setup pre and post installers. This
  47. # script should be run from the server root directory since it uses
  48. # pwd to get the server root directory.
  49. #
  50. ##########################
  51. # get command line arguments
  52. # see if silent mode
  53. counter=0
  54. doMktmp() {
  55. tmpfile=`mktemp /tmp/${1}XXXXXX 2> /dev/null`
  56. if ! [ $tmpfile ] ; then
  57. tmpfile=/tmp/$1.$counter.$$
  58. counter=`expr $counter + 1`
  59. fi
  60. echo $tmpfile
  61. }
  62. doExit() {
  63. echo "ERROR Exiting . . ." | tee -a $logfile
  64. if [ $tmpinffile ]; then
  65. rm -f $inffile
  66. fi
  67. echo "Log file is $logfile"
  68. exit 1
  69. }
  70. askYN() {
  71. prompt="$1"
  72. finished=
  73. while ! [ $finished ]; do
  74. echo ""
  75. echo -n "$prompt (yes/no) " | tee -a $logfile
  76. read ans
  77. echo $ans >> $logfile
  78. case "$ans" in
  79. y*|Y*) finished=1 ;;
  80. n*|N*) exit 1 ;;
  81. *) echo "Please answer yes or no" | tee -a $logfile ;;
  82. esac
  83. done
  84. }
  85. ask123() {
  86. prompt=$2
  87. default=$1
  88. finished=
  89. ans=
  90. while ! [ $finished ]; do
  91. echo -n ""
  92. echo ""
  93. echo -n $prompt "" | tee -a $logfile
  94. read ans
  95. echo $ans >> $logfile
  96. if ! [ $ans ]; then
  97. return $default
  98. fi
  99. case "$ans" in
  100. 1|2|3) finished=1 ;;
  101. *) echo "Please answer 1, 2, or 3" | tee -a $logfile ;;
  102. esac
  103. done
  104. return $ans
  105. }
  106. getFQDN() {
  107. max=0
  108. maxhost=
  109. defhost=`hostname`
  110. echo "getFQDN: hostname = $defhost" >> $logfile
  111. hosthost=`host $defhost | grep -v "not found" | awk '{print $1}'`
  112. echo "getFQDN: host $defhost = $hosthost" >> $logfile
  113. for host in $defhost $hosthost `hostname -f` `hostname -a` ; do
  114. len=`echo $host | wc -c`
  115. echo "getFQDN: host $host has length $len" >> $logfile
  116. if [ $len -gt $max ]; then
  117. max=$len
  118. maxhost=$host
  119. echo "getFQDN: new max host $host has length $max" >> $logfile
  120. fi
  121. done
  122. echo $maxhost
  123. }
  124. logfile=`doMktmp log`
  125. myargs=
  126. silent=
  127. inffile=
  128. tmpinffile=
  129. nextisinffile=
  130. keepinffile=
  131. for arg in "$@" ; do
  132. if [ "$arg" = "-s" ]; then
  133. silent=1
  134. elif [ "$arg" = "-k" ]; then
  135. keepinffile=1
  136. elif [ "$arg" = "-f" ]; then
  137. nextisinffile=1
  138. elif [ $nextisinffile ]; then
  139. inffile="$arg"
  140. nextisinffile=
  141. else
  142. myargs="$myargs $arg"
  143. fi
  144. done
  145. # figure out where we are and make sure we cd to the serverroot dir
  146. setupdir=`dirname $0`
  147. sroot=`dirname $setupdir`
  148. cd $sroot
  149. currentdir=`pwd`
  150. if [ "$currentdir" != "$sroot" ]; then
  151. # running setup using a relative path
  152. bname=`basename $setupdir`
  153. if [ "$bname" = "." ]; then
  154. setupdir=$currentdir
  155. else
  156. setupdir=`echo $currentdir/$bname`
  157. fi
  158. sroot=`dirname $setupdir`
  159. cd $sroot
  160. fi
  161. rm -f $sroot/setup/install.inf
  162. echo "INFO Begin Setup . . ." | tee -a $logfile
  163. # cat LICENSE.txt
  164. if ! [ $silent ]; then
  165. echo "" | tee -a $logfile
  166. echo "" | tee -a $logfile
  167. echo "" | tee -a $logfile
  168. cat LICENSE.txt | tee -a $logfile
  169. askYN "Do you accept the license terms?"
  170. fi
  171. # cat README.txt
  172. if ! [ $silent ]; then
  173. cat README.txt | tee -a $logfile
  174. askYN "Continue?"
  175. fi
  176. # dsktune
  177. if ! [ $silent ]; then
  178. bin/slapd/server/dsktune | tee -a $logfile
  179. askYN "Continue?"
  180. fi
  181. # install mode
  182. if ! [ $silent ]; then
  183. echo ""
  184. echo "Please select the install mode:"
  185. echo " 1 - Express - minimal questions"
  186. echo " 2 - Typical - some customization (default)"
  187. echo " 3 - Custom - lots of customization"
  188. ask123 "2" "Please select 1, 2, or 3 (default: 2) "
  189. installmode=$?
  190. fi
  191. # if silent mode, do not run the pre-installer programs
  192. # otherwise, create a temp file for their use
  193. if ! [ $silent ]; then
  194. inffile=`doMktmp setup`
  195. tmpinffile=1
  196. # put some common answers in the file
  197. hostname=`getFQDN`
  198. if ! [ $hostname ] ; then
  199. hostname=localhost.localdomain
  200. fi
  201. echo "" | tee -a $logfile
  202. echo -n "Hostname to use (default: $hostname) " | tee -a $logfile
  203. read ans
  204. echo $ans >> $logfile
  205. if [ "$ans" ]; then
  206. hostname="$ans"
  207. fi
  208. user=nobody
  209. group=nobody
  210. echo ""
  211. echo -n "Server user ID to use (default: $user) " | tee -a $logfile
  212. read ans
  213. echo $ans >> $logfile
  214. if [ "$ans" ]; then
  215. user="$ans"
  216. fi
  217. echo ""
  218. echo -n "Server group ID to use (default: $group) " | tee -a $logfile
  219. read ans
  220. echo $ans >> $logfile
  221. if [ "$ans" ]; then
  222. group="$ans"
  223. fi
  224. echo '[General]' >> $inffile
  225. echo "FullMachineName = $hostname" >> $inffile
  226. echo "SuiteSpotUserID = $user" >> $inffile
  227. echo "SuiteSpotGroup = $group" >> $inffile
  228. echo ServerRoot = `pwd` >> $inffile
  229. # first, run ds
  230. cd bin/slapd/admin/bin
  231. ./ns-config -f $inffile -l $logfile -m $installmode || doExit
  232. cd ../../../..
  233. # next, run admin
  234. cd bin/admin
  235. ./ns-config -f $inffile -l $logfile -m $installmode || doExit
  236. cd ../..
  237. fi
  238. # do the post installers
  239. silentarg=""
  240. if ! [ $silent ] ; then
  241. silentarg="-s"
  242. fi
  243. `pwd`/bin/slapd/admin/bin/ns-update $silentarg $myargs -f $inffile | tee -a $logfile || doExit
  244. `pwd`/bin/admin/ns-update $silentarg $myargs -f $inffile | tee -a $logfile || doExit
  245. echo "INFO Finished with setup, logfile is setup/setup.log" | tee -a $logfile
  246. if [ -f setup/setup.log ] ; then
  247. cat $logfile >> setup/setup.log
  248. else
  249. cp $logfile setup/setup.log
  250. fi
  251. rm -f $logfile
  252. if [ $tmpinffile ]; then
  253. if [ $keepinffile ]; then
  254. if [ -f setup/install.inf ]; then
  255. cat $inffile >> setup/install.inf
  256. else
  257. cp $inffile setup/install.inf
  258. fi
  259. chmod 600 setup/install.inf
  260. fi
  261. rm -f $inffile
  262. fi
  263. exit 0