setup 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. getValFromAdminConf() {
  125. cattr=$1
  126. cfile=$2
  127. rval=`grep -i $cattr $sroot/admin-serv/config/$cfile | awk '{print $2}'`
  128. echo $rval
  129. }
  130. logfile=`doMktmp log`
  131. myargs=
  132. silent=
  133. inffile=
  134. tmpinffile=
  135. nextisinffile=
  136. keepinffile=
  137. for arg in "$@" ; do
  138. if [ "$arg" = "-s" ]; then
  139. silent=1
  140. elif [ "$arg" = "-k" ]; then
  141. keepinffile=1
  142. elif [ "$arg" = "-f" ]; then
  143. nextisinffile=1
  144. elif [ $nextisinffile ]; then
  145. inffile="$arg"
  146. nextisinffile=
  147. else
  148. myargs="$myargs $arg"
  149. fi
  150. done
  151. # figure out where we are and make sure we cd to the serverroot dir
  152. setupdir=`dirname $0`
  153. sroot=`dirname $setupdir`
  154. cd $sroot
  155. currentdir=`pwd`
  156. if [ "$currentdir" != "$sroot" ]; then
  157. # running setup using a relative path
  158. bname=`basename $setupdir`
  159. if [ "$bname" = "." ]; then
  160. setupdir=$currentdir
  161. else
  162. setupdir=`echo $currentdir/$bname`
  163. fi
  164. sroot=`dirname $setupdir`
  165. cd $sroot
  166. fi
  167. rm -f $sroot/setup/install.inf
  168. echo "INFO Begin Setup . . ." | tee -a $logfile
  169. # cat LICENSE.txt
  170. if ! [ $silent ]; then
  171. echo "" | tee -a $logfile
  172. echo "" | tee -a $logfile
  173. echo "" | tee -a $logfile
  174. cat LICENSE.txt | tee -a $logfile
  175. askYN "Do you accept the license terms?"
  176. fi
  177. # cat README.txt
  178. if ! [ $silent ]; then
  179. cat README.txt | tee -a $logfile
  180. askYN "Continue?"
  181. fi
  182. # check whether it is an in-place installation
  183. if [ -f $sroot/admin-serv/config/adm.conf ]; then
  184. dsinst=`getValFromAdminConf "ldapStart:" "adm.conf" | awk -F/ '{print $1}'`
  185. if [ -f $sroot/$dsinst/config/dse.ldif ]; then
  186. # it is an in=place installation
  187. ldaphost=`getValFromAdminConf "ldapHost:" "adm.conf"`
  188. ldapport=`getValFromAdminConf "ldapPort:" "adm.conf"`
  189. adminport=`getValFromAdminConf "\<port:" "adm.conf"`
  190. siepid=`getValFromAdminConf "siepid:" "adm.conf"`
  191. sysuser=`getValFromAdminConf "nsSuiteSpotUser:" "local.conf"`
  192. suitespotuser=`ls -l $sroot/$dsinst/config/dse.ldif | awk '{print $3}'`
  193. suitespotgroup=`ls -l $sroot/$dsinst/config/dse.ldif | awk '{print $4}'`
  194. admindomain=`echo $ldaphost | awk -F. '{print $5 ? $2 "." $3 "." $4 "." $5: $4 ? $2 "." $3 "." $4 : $3 ? $2 "." $3 : $2 ? $2 : ""}'`
  195. if [ "$admindomain" = "" ]; then
  196. admindomain=`domainname`
  197. fi
  198. echo "In order to reconfigure your installation, the Configuration Directory"
  199. echo "Administrator password is required. Here is your current information:"
  200. echo ""
  201. echo "Configuration Directory: ldap://$ldaphost:$ldapport/o=NetscapeRoot"
  202. echo "Configuration Administrator ID: $siepid"
  203. echo ""
  204. echo "At the prompt, please enter the password for the Configuration Administrator."
  205. echo ""
  206. echo "administrator ID: $siepid"
  207. siepasswd=""
  208. while [ "$siepasswd" = "" ]; do
  209. printf "Password: "
  210. read siepasswd
  211. done
  212. inffile=$sroot/setup/myinstall.inf
  213. echo "[General]" > $inffile
  214. echo "FullMachineName= $ldaphost" >> $inffile
  215. echo "SuiteSpotUserID= $suitespotuser" >> $inffile
  216. echo "SuitespotGroup= $suitespotgroup" >> $inffile
  217. echo "ServerRoot= $sroot" >> $inffile
  218. echo "ConfigDirectoryLdapURL= ldap://$ldaphost:$ldapport/o=NetscapeRoot" >> $inffile
  219. echo "ConfigDirectoryAdminID= $siepid" >> $inffile
  220. echo "AdminDomain= $admindomain" >> $inffile
  221. echo "ConfigDirectoryAdminPwd= $siepasswd" >> $inffile
  222. echo "" >> $inffile
  223. echo "[admin]" >> $inffile
  224. echo "ServerAdminID= $siepid" >> $inffile
  225. echo "ServerAdminPwd= $siepasswd" >> $inffile
  226. echo "SysUser= $sysuser" >> $inffile
  227. echo "Port= $adminport" >> $inffile
  228. echo "ServerIpAddress=" >> $inffile
  229. # set silent mode
  230. silent=1
  231. fi
  232. fi
  233. # dsktune
  234. if ! [ $silent ]; then
  235. bin/slapd/server/dsktune | tee -a $logfile
  236. askYN "Continue?"
  237. fi
  238. # install mode
  239. if ! [ $silent ]; then
  240. echo ""
  241. echo "Please select the install mode:"
  242. echo " 1 - Express - minimal questions"
  243. echo " 2 - Typical - some customization (default)"
  244. echo " 3 - Custom - lots of customization"
  245. ask123 "2" "Please select 1, 2, or 3 (default: 2) "
  246. installmode=$?
  247. fi
  248. # if silent mode, do not run the pre-installer programs
  249. # otherwise, create a temp file for their use
  250. if ! [ $silent ]; then
  251. inffile=`doMktmp setup`
  252. tmpinffile=1
  253. # put some common answers in the file
  254. hostname=`getFQDN`
  255. if ! [ $hostname ] ; then
  256. hostname=localhost.localdomain
  257. fi
  258. echo "" | tee -a $logfile
  259. echo -n "Hostname to use (default: $hostname) " | tee -a $logfile
  260. read ans
  261. echo $ans >> $logfile
  262. if [ "$ans" ]; then
  263. hostname="$ans"
  264. fi
  265. user=nobody
  266. group=nobody
  267. echo ""
  268. echo -n "Server user ID to use (default: $user) " | tee -a $logfile
  269. read ans
  270. echo $ans >> $logfile
  271. if [ "$ans" ]; then
  272. user="$ans"
  273. fi
  274. echo ""
  275. echo -n "Server group ID to use (default: $group) " | tee -a $logfile
  276. read ans
  277. echo $ans >> $logfile
  278. if [ "$ans" ]; then
  279. group="$ans"
  280. fi
  281. echo '[General]' >> $inffile
  282. echo "FullMachineName = $hostname" >> $inffile
  283. echo "SuiteSpotUserID = $user" >> $inffile
  284. echo "SuiteSpotGroup = $group" >> $inffile
  285. echo ServerRoot = `pwd` >> $inffile
  286. # check if ds instance directory exists or not
  287. # if it does, run ns-config with the reconfigure option
  288. doreconfig=""
  289. ls -d slapd-* > /dev/null 2>&1
  290. if [ $? -eq 0 ]; then
  291. doreconfig="-r"
  292. fi
  293. # first, run ds
  294. cd bin/slapd/admin/bin
  295. ./ns-config -f $inffile -l $logfile -m $installmode $doreconfig || doExit
  296. cd ../../../..
  297. # next, run admin
  298. cd bin/admin
  299. ./ns-config -f $inffile -l $logfile -m $installmode $doreconfig || doExit
  300. cd ../..
  301. fi
  302. # do the post installers
  303. silentarg=""
  304. if ! [ $silent ] ; then
  305. silentarg="-s"
  306. fi
  307. `pwd`/bin/slapd/admin/bin/ns-update $silentarg $myargs -f $inffile | tee -a $logfile || doExit
  308. `pwd`/bin/admin/ns-update $doreconfig $silentarg $myargs -f $inffile | tee -a $logfile || doExit
  309. echo "INFO Finished with setup, logfile is setup/setup.log" | tee -a $logfile
  310. if [ -f setup/setup.log ] ; then
  311. cat $logfile >> setup/setup.log
  312. else
  313. cp $logfile setup/setup.log
  314. fi
  315. rm -f $logfile
  316. if [ $tmpinffile ]; then
  317. if [ $keepinffile ]; then
  318. if [ -f setup/install.inf ]; then
  319. cat $inffile >> setup/install.inf
  320. else
  321. cp $inffile setup/install.inf
  322. fi
  323. chmod 600 setup/install.inf
  324. fi
  325. rm -f $inffile
  326. fi
  327. exit 0