updated on Wed Jan 25 16:08:47 UTC 2012
[aur-mirror.git] / oracle-xe / oraconfig.sh
blob7707893af6ad47b652fcd798b42af0d71b806d64
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=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
14 ORACLE_OWNER=oracle
15 ORACLE_SID=XE
16 LSNR=$ORACLE_HOME/bin/lsnrctl
17 SQLPLUS=$ORACLE_HOME/bin/sqlplus
18 SU=/bin/su
19 export ORACLE_HOME
20 export ORACLE_SID
21 export PATH=$ORACLE_HOME/bin:$PATH
22 LOG="$ORACLE_HOME_LISTNER/listener.log"
24 export LC_ALL=C
26 if [ $(id -u) != "0" ]
27 then
28 echo "You must be root to run the configure script. Login as root and then run the configure script."
29 exit 1
32 CONFIG_NAME=oracle-xe
33 CONFIGURATION="/etc/sysconfig/$CONFIG_NAME"
35 if [ -f /etc/arch-release ]
36 then
38 init_status() {
39 return 0
41 exit_status() {
42 exit $?
44 success_status() {
45 success
46 echo
48 failure_status() {
49 failure $?
50 echo
54 success () {
55 echo " [OK]"
58 failure () {
59 echo " [FAILED]"
62 # Source configuration
64 [ -f "$CONFIGURATION" ] && . "$CONFIGURATION"
66 init_status
69 # if_fail()
71 # Evaluates return codes. If 0, prints "OK", if 1, prints "Failed"
72 # and exits. If 2, status is "already done" and nothing is printed.
73 # The rest of the functions in here all honor this convention.
75 if_fail() {
76 RC="$1"
77 REASON="$2"
78 if [ "$RC" = "0" ]
79 then
80 return
81 elif [ "$RC" = "2" ]
82 then
83 return
85 failure_status "${REASON}"
86 exit 1
91 # write_sysconfig()
93 # Writes the system configuration
95 write_sysconfig()
97 cat >"$CONFIGURATION" <<EOF
99 #This is a configuration file for automatic starting of the Oracle
100 #Database and listener at system startup.It is generated By running
101 #'/etc/init.d/oracle-xe configure'.Please use that method to modify this
102 #file
104 # ORACLE_DBENABLED:'true' means to load the Database at system boot.
105 ORACLE_DBENABLED=${ORACLE_DBENABLED:-false}
107 # LISTENER_PORT: Database listener
108 LISTENER_PORT=${LISTENER_PORT}
110 # HTTP_PORT : HTTP port for Oracle Application Express
111 HTTP_PORT=${HTTP_PORT}
113 # Configuration : Check whether configure has been done or not
114 CONFIGURE_RUN=${CONFIGURE_RUN}
118 if [ $? != 0 ]
119 then
120 return 1
122 return 0
128 # configure_perform()
130 # Instantantiate listener.ora,tnsnames.ora,and create the database,
131 # sets the password,start the listener,and adds database to inittab
132 # if necessary
134 configure_perform() {
136 sed -i "s/%sga_target%/$SGA_SIZE/g" $ORACLE_HOME/config/scripts/init.ora
137 sed -i "s/%pga_aggregate_target%/$PGA_SIZE/g" $ORACLE_HOME/config/scripts/init.ora
138 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/init.ora
140 sed -i "s/%sga_target%/$SGA_SIZE/g" $ORACLE_HOME/config/scripts/initXETemp.ora
141 sed -i "s/%pga_aggregate_target%/$PGA_SIZE/g" $ORACLE_HOME/config/scripts/initXETemp.ora
142 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/initXETemp.ora
144 sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/network/admin/listener.ora
145 sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/network/admin/listener.ora
146 /bin/chown oracle:dba $ORACLE_HOME/network/admin/listener.ora
148 sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/network/admin/tnsnames.ora
149 sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/network/admin/tnsnames.ora
150 /bin/chown oracle:dba $ORACLE_HOME/network/admin/tnsnames.ora
152 sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/postDBCreation.sql
153 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/postDBCreation.sql
155 if test $LISTENER_PORT -ne 1521
156 then
157 if [ -f /tmp/local_listener ]
158 then
159 cat >/tmp/local_listener$$ <<EOF
160 ###########################################
161 # Registration of instance with listsner
162 ###########################################
163 local_listener="(ADDRESS = (PROTOCOL=TCP) (HOST=%hostname%) (PORT=%port%))"
165 /bin/chmod 664 /tmp/local_listener$$
166 cat /tmp/local_listener$$ >> $ORACLE_HOME/config/scripts/init.ora
167 else
168 cat >/tmp/local_listener <<EOF
169 ###########################################
170 # Registration of instance with listsner
171 ###########################################
172 local_listener="(ADDRESS = (PROTOCOL=TCP) (HOST=%hostname%) (PORT=%port%))"
174 /bin/chmod 664 /tmp/local_listener
175 cat /tmp/local_listener >> $ORACLE_HOME/config/scripts/init.ora
178 if test -f /tmp/local_listener
179 then
180 rm -fr /tmp/local_listener
181 elif test -f /tmp/local_listener$$
182 then
183 rm -fr /tmp/local_listener$$
186 sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/config/scripts/init.ora
187 sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/config/scripts/init.ora
188 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/init.ora
192 sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/DatabaseHomePage.sh
193 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/DatabaseHomePage.sh
195 sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/readonlinehelp.sh
196 /bin/chown oracle:dba $ORACLE_HOME/config/scripts/readonlinehelp.sh
198 homedir=`echo $HOME`
199 if [ "$homedir" = "/root" ]
200 then
201 homedir=`sh -c "echo ~$USER"`
204 if [ -f $homedir/.gnome-desktop/oraclexe-gettingstarteddesktop.desktop ]
205 then
206 /bin/chown oracle:dba $homedir/.gnome-desktop/oraclexe-gettingstarteddesktop.desktop
207 /bin/chmod 664 $homedir/.gnome-desktop/oraclexe-gettingstarteddesktop.desktop
209 if [ -f $homedir/Desktop/oraclexe-gettingstarteddesktop.desktop ]
210 then
211 /bin/chown oracle:dba $homedir/Desktop/oraclexe-gettingstarteddesktop.desktop
212 /bin/chmod 664 $homedir/Desktop/oraclexe-gettingstarteddesktop.desktop
215 if [ -f $ORACLE_HOME/bin/tnslsnr ]
216 then
217 echo -n "Starting Oracle Net Listener..."
218 $SU -s /bin/bash $ORACLE_OWNER -c "$LSNR start" ## > /dev/null 2>&1
219 echo "Done"
222 echo -n "Configuring Database..."
223 $SU -s /bin/bash $ORACLE_OWNER -c "$ORACLE_HOME/config/scripts/XE.sh" ## > /dev/null 2>&1
224 err=`grep "ORA-44410" $ORACLE_HOME/config/log/*.log`
225 if test "$err" != ""
226 then
227 echo "Database Configuration failed. Look into $ORACLE_HOME/config/log for details"
228 exit 1
230 echo alter user sys identified by \"$ORACLE_PASSWORD\"\; | $SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s / as sysdba" ## > /dev/null 2>&1
231 echo alter user system identified by \"$ORACLE_PASSWORD\"\; | $SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s / as sysdba" ## > /dev/null 2>&1
232 echo "Done"
234 /bin/chmod -R 640 /usr/lib/oracle/xe/oradata/XE
235 /bin/chmod 750 /usr/lib/oracle/xe/oradata/XE
236 rm -fr $ORACLE_HOME/config/seeddb
238 if [ -f /etc/oratab ]
239 then
240 echo "XE:$ORACLE_HOME:N" >> /etc/oratab
241 else
242 echo "XE:$ORACLE_HOME:N" >> /etc/oratab
243 /bin/chown oracle:dba /etc/oratab
244 /bin/chmod 644 /etc/oratab
247 echo -n "Starting Oracle Database 10g Express Edition Instance..."
248 pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | grep -v grep`
250 if [ "$pmon" = "" ];
251 then
252 $SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog @$ORACLE_HOME/config/scripts/startdb.sql" ## > /dev/null 2>&1
254 echo "Done"
256 echo "Installation Completed Successfully."
259 return 0
263 #configure_ask()
265 # Ask configuration questions,setting the variables.
268 configure_ask() {
269 cat <<EOF
271 Oracle Database 10g Express Edition Configuration
272 -------------------------------------------------
273 This will configure on-boot properties of Oracle Database 10g Express
274 Edition. The following questions will determine whether the database should
275 be starting upon system boot, the ports it will use, and the passwords that
276 will be used for database accounts. Press <Enter> to accept the defaults.
277 Ctrl-C will abort.
281 #get the http port value
282 while :
284 while [ 1 ]
286 echo -n Specify the HTTP port that will be used for Oracle Application Express [8080]:
287 read LINE
288 if [ -z $LINE ]
289 then
290 LINE=8080
292 port=`netstat -n --tcp --listen | grep :$LINE | awk '{print $4}' | cut -d':' -f2`
293 if [ "$port" = "$LINE" ]
294 then
295 echo Port $port appears to be in use by another application.\
296 Please specify a different port.
297 else
298 break;
300 done
302 case "$LINE" in
304 break
306 *[^0-9]*)
307 echo "Invalid http port: $LINE"
310 HTTP_PORT=$LINE
311 break
313 esac
314 done
316 #get the listener port value
317 while :
319 echo
320 while [ 1 ]
322 echo -n Specify a port that will be used for the database listener [1521]:
323 read LINE
324 if [ -z $LINE ]
325 then
326 LINE=1521
328 echo
329 port=`netstat -n --tcp --listen | grep :$LINE | awk '{print $4}' | cut -d':' -f2`
330 if [ "$port" = "$LINE" ]
331 then
332 echo Port $port appears to be in use by another application.\
333 Please specify a different port.
334 else
335 break;
337 done
339 case "$LINE" in
341 break
343 *[^0-9]*)
344 echo "Invalid port: $LINE" >&2
347 if [ "$HTTP_PORT" != "$LINE" ]
348 then
349 LISTENER_PORT=$LINE
350 break
351 else
352 echo Database listener cannot be configured on the same port as Oracle Application Express.
355 esac
356 done
358 #get the sga size
359 while :
361 echo
362 while [ 1 ]
364 echo -n Specify your sga size [128M]:
365 read LINE
366 if [ -z $LINE ]
367 then
368 LINE="128M"
370 break;
371 done
373 case "$LINE" in
375 break
380 SGA_SIZE=$LINE
381 break
383 esac
384 done
386 #get the pga_aggregate_target size
387 while :
389 echo
390 while [ 1 ]
392 echo -n Specify your pga size [96M]:
393 read LINE
394 if [ -z $LINE ]
395 then
396 LINE="96M"
398 break;
399 done
401 case "$LINE" in
403 break
408 PGA_SIZE=$LINE
409 break
411 esac
412 done
414 #get the database password
415 while :
417 echo -n "Specify a password to be used for database accounts. Note that the same
418 password will be used for SYS and SYSTEM. Oracle recommends the use of
419 different passwords for each database account. This can be done after
420 initial configuration:"
421 while [ 1 ]
423 /bin/stty -echo ## > /dev/null 2>&1
424 temp=`echo $IFS`
425 export IFS="\n"
426 while [ 1 ]
428 read LINE
429 while [ -z "$LINE" ]
431 echo
432 echo -n "Password can't be null. Enter password:"
433 read LINE
434 done
436 result=`expr index "$LINE" [\'\"]`
437 if [ $result != 0 ];
438 then
439 echo
440 echo -n "The password you entered contains invalid characters. Enter password:"
441 else
442 break
444 done
445 echo
446 echo -n "Confirm the password:"
447 read LINE1
448 echo
449 if [ "$LINE" != "$LINE1" ];
450 then
451 echo
452 echo -n "Passwords do not match. Enter the password:"
453 else
454 break
456 done
457 /bin/stty echo ## > /dev/null 2>&1
458 ORACLE_PASSWORD=$LINE
459 export IFS=$temp
460 break;
461 done
463 if [ "$ORACLE_DBENABLED" = "true" ]
464 then
465 CUR=y
466 else
467 CUR=n
470 ORACLE_DBENABLED=true
475 configure() {
476 configure_ask
477 configure_perform
478 CONFIGURE_RUN=true
479 write_sysconfig
480 echo To access the Database Home Page go to \"http://127.0.0.1:$HTTP_PORT/apex\"
483 configure