updated on Mon Jan 23 20:11:11 UTC 2012
[aur-mirror.git] / oracle-xe-11g2-beta / oraconfig.sh
blob2d7615fc699cf1a469194d2f79c29ce35f186ac9
1 #!/bin/bash
3 # Set path if path not set (if called from /etc/rc)
4 case $PATH in
5 "") PATH=/bin:/usr/bin:/sbin:/etc
6 export PATH ;;
7 esac
9 # Save LD_LIBRARY_PATH
10 SAVE_LLP=$LD_LIBRARY_PATH
12 RETVAL=0
13 ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
14 ORACLE_BASE=/u01/app/oracle
15 ORACLE_OWNER=oracle
16 ORACLE_SID=XE
17 LSNR=$ORACLE_HOME/bin/lsnrctl
18 SQLPLUS=$ORACLE_HOME/bin/sqlplus
19 SU=/bin/su
20 export ORACLE_HOME
21 export ORACLE_SID
22 export ORACLE_BASE
23 export PATH=$ORACLE_HOME/bin:$PATH
24 LOG="$ORACLE_HOME_LISTNER/listener.log"
26 export LC_ALL=C
28 if [ $(id -u) != "0" ]
29 then
30 echo "You must be root to run the configure script. Login as root and then run the configure script."
31 exit 1
34 CONFIG_NAME=oracle-xe
35 CONFIGURATION="/etc/sysconfig/$CONFIG_NAME"
37 if [ -f /etc/arch-release ]
38 then
40 init_status() {
41 return 0
43 exit_status() {
44 exit $?
46 success_status() {
47 success
48 echo
50 failure_status() {
51 failure $?
52 echo
56 success () {
57 echo " [OK]"
60 failure () {
61 echo " [FAILED]"
64 # Source configuration
66 [ -f "$CONFIGURATION" ] && . "$CONFIGURATION"
68 init_status
71 # if_fail()
73 # Evaluates return codes. If 0, prints "OK", if 1, prints "Failed"
74 # and exits. If 2, status is "already done" and nothing is printed.
75 # The rest of the functions in here all honor this convention.
77 if_fail() {
78 RC="$1"
79 REASON="$2"
80 if [ "$RC" = "0" ]
81 then
82 return
83 elif [ "$RC" = "2" ]
84 then
85 return
87 failure_status "${REASON}"
88 exit 1
93 # write_sysconfig()
95 # Writes the system configuration
97 write_sysconfig()
99 cat >"$CONFIGURATION" <<EOF
101 #This is a configuration file for automatic starting of the Oracle
102 #Database and listener at system startup.It is generated By running
103 #'/etc/init.d/oracle-xe configure'.Please use that method to modify this
104 #file
106 # ORACLE_DBENABLED:'true' means to load the Database at system boot.
107 ORACLE_DBENABLED=${ORACLE_DBENABLED:-false}
109 # LISTENER_PORT: Database listener
110 LISTENER_PORT=${LISTENER_PORT}
112 # HTTP_PORT : HTTP port for Oracle Application Express
113 HTTP_PORT=${HTTP_PORT}
115 # Configuration : Check whether configure has been done or not
116 CONFIGURE_RUN=${CONFIGURE_RUN}
120 if [ $? != 0 ]
121 then
122 return 1
124 return 0
130 # configure_perform()
132 # Instantantiate listener.ora,tnsnames.ora,and create the database,
133 # sets the password,start the listener,and adds database to inittab
134 # if necessary
136 configure_perform()
139 sed -i "s/%sga_target%/$SGA_SIZE/g" $ORACLE_HOME/config/scripts/init.ora
140 sed -i "s/%pga_aggregate_target%/$PGA_SIZE/g" $ORACLE_HOME/config/scripts/init.ora
141 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/init.ora
143 sed -i "s/%sga_target%/$SGA_SIZE/g" $ORACLE_HOME/config/scripts/initXETemp.ora
144 sed -i "s/%pga_aggregate_target%/$PGA_SIZE/g" $ORACLE_HOME/config/scripts/initXETemp.ora
145 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/initXETemp.ora
147 sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/network/admin/listener.ora
148 sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/network/admin/listener.ora
149 /bin/chown oracle:dba $ORACLE_HOME/network/admin/listener.ora
151 sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/network/admin/tnsnames.ora
152 sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/network/admin/tnsnames.ora
153 /bin/chown oracle:dba $ORACLE_HOME/network/admin/tnsnames.ora
155 sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/postDBCreation.sql
156 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/postDBCreation.sql
158 if test $LISTENER_PORT -ne 1521
159 then
160 if [ -f /tmp/local_listener ]
161 then
162 cat >/tmp/local_listener$$ <<EOF
163 ###########################################
164 # Registration of instance with listsner
165 ###########################################
166 local_listener="(ADDRESS = (PROTOCOL=TCP) (HOST=%hostname%) (PORT=%port%))"
168 /bin/chmod 664 /tmp/local_listener$$
169 cat /tmp/local_listener$$ >> $ORACLE_HOME/config/scripts/init.ora
170 else
171 cat >/tmp/local_listener <<EOF
172 ###########################################
173 # Registration of instance with listsner
174 ###########################################
175 local_listener="(ADDRESS = (PROTOCOL=TCP) (HOST=%hostname%) (PORT=%port%))"
177 /bin/chmod 664 /tmp/local_listener
178 cat /tmp/local_listener >> $ORACLE_HOME/config/scripts/init.ora
181 if test -f /tmp/local_listener
182 then
183 rm -fr /tmp/local_listener
184 elif test -f /tmp/local_listener$$
185 then
186 rm -fr /tmp/local_listener$$
189 sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/config/scripts/init.ora
190 sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/config/scripts/init.ora
191 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/init.ora
195 sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/gettingstarted.sh
196 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/gettingstarted.sh
198 sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/readonlinehelp.sh
199 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/readonlinehelp.sh
201 homedir=`echo $HOME`
202 if [ "$homedir" = "/root" ]
203 then
204 homedir=`sh -c "echo ~$USER"`
207 if [ -f $homedir/.gnome-desktop/oraclexe-gettingstarteddesktop.desktop ]
208 then
209 /bin/chown oracle:dba $homedir/.gnome-desktop/oraclexe-gettingstarteddesktop.desktop
210 /bin/chmod 664 $homedir/.gnome-desktop/oraclexe-gettingstarteddesktop.desktop
212 if [ -f $homedir/Desktop/oraclexe-gettingstarteddesktop.desktop ]
213 then
214 /bin/chown oracle:dba $homedir/Desktop/oraclexe-gettingstarteddesktop.desktop
215 /bin/chmod 664 $homedir/Desktop/oraclexe-gettingstarteddesktop.desktop
218 if [ -f $ORACLE_HOME/bin/tnslsnr ]
219 then
220 echo -n "Starting Oracle Net Listener..."
221 su -s /bin/bash $ORACLE_OWNER -c "$LSNR start" > /dev/null 2>&1
222 echo "Done"
225 echo -n "Configuring database..."
226 su -s /bin/bash $ORACLE_OWNER -c "$ORACLE_HOME/config/scripts/XE.sh" > /dev/null 2>&1
227 if [ -d $ORACLE_HOME/config/log ]
228 then
229 err=`grep "ORA-44410" $ORACLE_HOME/config/log/*.log`
230 out=`grep "ORA-01034" $ORACLE_HOME/config/log/*.log`
231 if [ "$err" != "" ] || [ "$out" != "" ]
232 then
233 echo
234 echo "Database Configuration failed. Look into $ORACLE_HOME/config/log for details"
235 exit 1
239 pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | grep -v grep`
241 if [ "$pmon" = "" ];
242 then
243 echo
244 echo "Database Configuration failed. Look into $ORACLE_HOME/config/log for details"
245 exit 1
248 echo alter user sys identified by \"$ORACLE_PASSWORD\"\; | su -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s / as sysdba" > /dev/null 2>&1
249 echo alter user system identified by \"$ORACLE_PASSWORD\"\; | su -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s / as sysdba" > /dev/null 2>&1
251 echo @$ORACLE_HOME/apex/apxxepwd.sql \"$ORACLE_PASSWORD\"\; | su -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s / as sysdba" > /dev/null 2>&1
252 echo "Done"
254 /bin/chmod -R 640 /u01/app/oracle/oradata/XE
255 /bin/chmod 750 /u01/app/oracle/oradata/XE
256 /bin/chmod -R 775 /u01/app/oracle/diag
257 rm -fr $ORACLE_HOME/config/seeddb
259 if [ -f /etc/oratab ]
260 then
261 echo "XE:$ORACLE_HOME:N" >> /etc/oratab
262 else
263 echo "XE:$ORACLE_HOME:N" >> /etc/oratab
264 /bin/chown oracle:dba /etc/oratab
265 /bin/chmod 664 /etc/oratab
268 echo -n "Starting Oracle Database 11g Express Edition instance..."
269 pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | grep -v grep`
271 if [ "$pmon" = "" ];
272 then
273 su -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog @$ORACLE_HOME/config/scripts/startdb.sql" > /dev/null 2>&1
275 echo "Done"
277 echo "Installation completed successfully."
280 return 0
284 #configure_ask()
286 # Ask configuration questions,setting the variables.
289 configure_ask()
291 cat <<EOF
293 Oracle Database 11g Express Edition Configuration
294 -------------------------------------------------
295 This will configure on-boot properties of Oracle Database 11g Express
296 Edition. The following questions will determine whether the database should
297 be starting upon system boot, the ports it will use, and the passwords that
298 will be used for database accounts. Press <Enter> to accept the defaults.
299 Ctrl-C will abort.
302 #get the http port value
303 while :
305 while [ 1 ]
307 echo -n Specify the HTTP port that will be used for Oracle Application Express [8080]:
308 read LINE
309 if [ -z $LINE ]
310 then
311 LINE=8080
313 echo
314 port=`netstat -n --tcp --listen | grep :$LINE | awk -F: '{print $4}' | sed 's/ //g'`
315 if [ "$port" = "$LINE" ]
316 then
317 if [ ! -z $1 ]
318 then
319 echo
320 echo "Port $LINE appears to be in use by another application. Specify a different
321 port and retry the configuration."
322 trap "rm -fr $1" exit
323 exit
325 echo "Port $port appears to be in use by another application. Specify a different port."
326 else
327 break;
329 done
331 case "$LINE" in
333 break
335 *[^0-9]*)
336 echo "Invalid http port: $LINE"
339 HTTP_PORT=$LINE
340 break
342 esac
343 done
345 #get the listener port value
346 while :
348 while [ 1 ]
350 echo -n Specify a port that will be used for the database listener [1521]:
351 read LINE
352 if [ -z $LINE ]
353 then
354 LINE=1521
356 echo
357 port=`netstat -n --tcp --listen | grep :$LINE | awk -F: '{print $4}' | sed 's/ //g'`
358 if [ "$port" = "$LINE" ]
359 then
360 if [ ! -z $1 ]
361 then
362 echo
363 echo "Port $LISTENER_PORT appears to be in use by another application. Specify a different
364 port and retry the configuration."
365 trap "rm -fr $1" exit
366 exit
368 echo Port $port appears to be in use by another application.\
369 Specify a different port.
370 else
371 break;
373 done
375 case "$LINE" in
377 break
379 *[^0-9]*)
380 echo "Invalid port: $LINE" >&2
383 if [ "$HTTP_PORT" != "$LINE" ]
384 then
385 LISTENER_PORT=$LINE
386 break
387 else
388 echo Database listener cannot be configured on the same port as Oracle Application Express.
391 esac
392 done
394 #get the sga size
395 while :
397 echo
398 while [ 1 ]
400 echo -n Specify your sga size [128M]:
401 read LINE
402 if [ -z $LINE ]
403 then
404 LINE="128M"
406 break;
407 done
409 case "$LINE" in
411 break
416 SGA_SIZE=$LINE
417 break
419 esac
420 done
422 #get the pga_aggregate_target size
423 while :
425 echo
426 while [ 1 ]
428 echo -n Specify your pga size [96M]:
429 read LINE
430 if [ -z $LINE ]
431 then
432 LINE="96M"
434 break;
435 done
437 case "$LINE" in
439 break
444 PGA_SIZE=$LINE
445 break
447 esac
448 done
450 #get the database password
451 while :
453 echo -n "Specify a password to be used for database accounts. Note that the same
454 password will be used for SYS and SYSTEM. Oracle recommends the use of
455 different passwords for each database account. This can be done after
456 initial configuration:"
457 while [ 1 ]
459 /bin/stty -echo > /dev/null 2>&1
460 temp=`echo $IFS`
461 export IFS="\n"
462 while [ 1 ]
464 read LINE
465 while [ -z "$LINE" ]
467 echo
468 echo -n "Password can't be null. Enter password:"
469 read LINE
470 done
472 result=`expr index "$LINE" [\'\"]`
473 if [ $result != 0 ];
474 then
475 echo
476 echo -n "The password you entered contains invalid characters. Enter password:"
477 else
478 break
480 done
481 echo
482 echo -n "Confirm the password:"
483 read LINE1
484 echo
485 if [ "$LINE" != "$LINE1" ];
486 then
487 if [ ! -z $1 ]
488 then
489 echo
490 echo "Passwords do not match. Specify the same password for both ORACLE_PASSSWORD and
491 ORACLE_CONFIRM_PASSWORD, and retry the configuration."
492 trap "rm -fr $1" exit
493 exit
495 echo
496 echo -n "Passwords do not match. Enter the password:"
497 else
498 break
500 done
501 /bin/stty echo > /dev/null 2>&1
502 ORACLE_PASSWORD=$LINE
503 export IFS=$temp
504 break;
505 done
507 while :
509 if [ "$ORACLE_DBENABLED" = "true" ]
510 then
511 CUR=y
512 else
513 CUR=n
515 echo
516 echo -n "Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:"
517 read LINE
518 if [ -z $LINE ]
519 then
520 ORACLE_DBENABLED=true
522 echo
523 case "$LINE" in
524 "")
525 break
527 y|Y)
528 ORACLE_DBENABLED=true
529 break
531 n|N)
532 ORACLE_DBENABLED=false
533 break
536 echo "Invalid response: $LINE " >&2
537 break
538 esac
539 done
542 configure() {
543 if test -f "$CONFIGURATION"
544 then
545 echo "Oracle Database 11g Express Edition is already configured"
546 exit 1
548 configure_ask
549 configure_perform
550 CONFIGURE_RUN=true
551 write_sysconfig
552 echo To access the Database Home Page go to \"http://127.0.0.1:$HTTP_PORT/apex\"
555 configure