-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathinstall.11202.sh
executable file
·728 lines (582 loc) · 23.6 KB
/
install.11202.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
#!/bin/bash
# Since: January, 2021
# Author: gvenzl
# Name: install.11202.sh
# Description: Install script for Oracle DB XE 11.2.0.2
#
# Copyright 2021 Gerald Venzl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Exit on errors
# Great explanation on https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -Eeuo pipefail
echo "BUILDER: started"
# Build mode ("SLIM", "REGULAR", "FULL")
BUILD_MODE=${1:-"REGULAR"}
echo "BUILDER: BUILD_MODE=${BUILD_MODE}"
# Set data file sizes
SYSTEM_SIZE=353
SYSAUX_SIZE=610
if [ "${BUILD_MODE}" == "REGULAR" ]; then
REDO_SIZE=20
USERS_SIZE=10
elif [ "${BUILD_MODE}" == "SLIM" ]; then
REDO_SIZE=10
USERS_SIZE=2
fi;
echo "BUILDER: Installing OS dependencies"
# Install installation dependencies
microdnf -y install bc procps-ng util-linux net-tools findutils
# Install runtime dependencies
microdnf -y install libaio libnsl xz
# Install container runtime specific packages
# (used by the entrypoint script, not the database itself)
# TODO: replace with 7zip
microdnf -y install unzip gzip
# Install 7zip
mkdir /tmp/7z
cd /tmp/7z
curl -s -L -k -O "https://7zip.org/a/7z2408-linux-x64.tar.xz"
tar xf 7z*xz
mv 7zzs /usr/bin/
mv License.txt /usr/share/
cd - 1> /dev/null
rm -rf /tmp/7z
# Install GCC and other packages for full installation
if [ "${BUILD_MODE}" == "FULL" ]; then
microdnf -y install glibc make binutils gcc
fi;
# Fake 2 GB swap configuration
free() { echo "Swap: 0 0 2048"; }
export -f free
################################
###### Install Database ########
################################
echo "BUILDER: installing database binaries"
# Install Oracle DB binaries
rpm -iv /install/oracle-xe-11.2.0-1.0.x86_64.rpm
# Remove fake 2 GB swap configuration
unset -f cat free
# Change installation directory to /opt/oracle
# Move $ORACLE_BASE under the new $ORACLE_BASE parent directory (i.e. /opt/ for /opt/oracle)
#mv /u01/app/oracle "${ORACLE_BASE%%/oracle}"
#chown -R oracle:dba /u01
# Symlink /u01/app/oracle --> /opt/oracle
# This is so that the hard coded shared libraries paths in the binaries (sqlplus, etc.) can be resolved (check 'ldd sqlplus')
#ln -s "${ORACLE_BASE}" /u01/app/
# Replace absolute path with $ORACLE_BASE variable for /etc/init.d/oracle-xe (used to configure DB later on)
#sed -i "s|/u01/app/oracle|\${ORACLE_BASE}|g" /etc/init.d/oracle-xe
# SQL*Plus and other files (.ora, etc) don't do variable expansion, replace absolute path /u01/app/oracle with value of $ORACLE_BASE
#for file in $(grep -rIl "/u01/app/oracle" "${ORACLE_HOME}"); do
# sed -i "s|/u01/app/oracle|${ORACLE_BASE}|g" "${file}"
#done;
# Oracle DB directories need to be recreated:
#DATA_PUMP_DIR /u01/app/oracle/admin/XE/dpdump/
#XMLDIR /u01/app/oracle/product/11.2.0/xe/rdbms/xml
# Remove memory_target parameter (not supported by default in containers)
sed -i "/memory_target/d" "${ORACLE_HOME}"/config/scripts/init.ora
sed -i "/memory_target/d" "${ORACLE_HOME}"/config/scripts/init"${ORACLE_SID}"Temp.ora
# Add SGA_TARGET and PGA_AGGREGATE_TARGET to pfile
sed -i "$ a sga_target=768m" "${ORACLE_HOME}"/config/scripts/init.ora
sed -i "$ a sga_target=768m" "${ORACLE_HOME}"/config/scripts/init"${ORACLE_SID}"Temp.ora
sed -i "$ a pga_aggregate_target=256m" "${ORACLE_HOME}"/config/scripts/init.ora
sed -i "$ a pga_aggregate_target=256m" "${ORACLE_HOME}"/config/scripts/init"${ORACLE_SID}"Temp.ora
# Add CPU_COUNT to pfile
sed -i "$ a cpu_count=1" "${ORACLE_HOME}"/config/scripts/init.ora
sed -i "$ a cpu_count=1" "${ORACLE_HOME}"/config/scripts/init"${ORACLE_SID}"Temp.ora
# Set random password
ORACLE_PASSWORD=$(date '+%s' | sha256sum | base64 | head -c 8)
sed -i "s/###ORACLE_PASSWORD###/${ORACLE_PASSWORD}/g" /install/xe.11202.rsp
echo "BUILDER: configuring database"
# Configure database
/etc/init.d/oracle-xe configure responseFile=/install/xe.11202.rsp
echo "BUILDER: post config database steps"
############################
### Create network files ###
############################
echo "BUILDER: creating network files"
# listener.ora
echo \
"SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = ${ORACLE_HOME})
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_${ORACLE_SID}))
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = (${ORACLE_SID})" > "${ORACLE_HOME}"/network/admin/listener.ora
# tnsnames.ora
echo \
"${ORACLE_SID} =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ${ORACLE_SID})
)
)
FREE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = FREE)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_${ORACLE_SID}))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
" > "${ORACLE_HOME}/network/admin/tnsnames.ora"
# sqlnet.ora
echo "NAMES.DIRECTORY_PATH = (EZCONNECT, TNSNAMES)" > "${ORACLE_HOME}"/network/admin/sqlnet.ora
chown -R oracle:dba "${ORACLE_HOME}"/network/admin
####################
### bash_profile ###
####################
# Create .bash_profile for oracle user
echo "BUILDER: creating .bash_profile"
echo \
"export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_BASE_CONFIG=${ORACLE_BASE_CONFIG}
export ORACLE_BASE_HOME=${ORACLE_BASE_HOME}
export ORACLE_HOME=${ORACLE_HOME}
export ORACLE_SID=XE
export PATH=\${PATH}:\${ORACLE_HOME}/bin:\${ORACLE_BASE}
# Use UTF-8 by default
export NLS_LANG=.AL32UTF8
" >> "${ORACLE_BASE}"/.bash_profile
chown oracle:dba "${ORACLE_BASE}"/.bash_profile
# Create entrypoint folders (#108)
#
# Certain tools like GitLab CI do not allow for volumes, instead a user has to copy
# files into the folders. However, as these folders are under / and the container user
# is `oracle`, they can no longer create these folders.
# Instead we provide them here already so that these folks can start putting files into
# them directly, if they have to.
mkdir /container-entrypoint-initdb.d
mkdir /container-entrypoint-startdb.d
chown oracle:dba /container-entrypoint*
# Perform further Database setup operations
echo "BUILDER: changing database configuration and parameters for all images"
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Enable remote HTTP access
EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);
-- Setup healthcheck user
CREATE USER OPS\$ORACLE IDENTIFIED EXTERNALLY;
GRANT CONNECT, SELECT_CATALOG_ROLE TO OPS\$ORACLE;
-- Remove original redo logs from fast_recovery_area and create new ones
ALTER DATABASE ADD LOGFILE GROUP 3 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo03.log') SIZE 50m;
ALTER DATABASE ADD LOGFILE GROUP 4 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo04.log') SIZE 50m;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM CHECKPOINT;
ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 2;
ALTER DATABASE ADD LOGFILE GROUP 1 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo01.log') SIZE 50m;
ALTER DATABASE ADD LOGFILE GROUP 2 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo02.log') SIZE 50m;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM CHECKPOINT;
ALTER DATABASE DROP LOGFILE GROUP 3;
ALTER DATABASE DROP LOGFILE GROUP 4;
-- Remove fast recovery area
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST='';
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE=1;
HOST rm -r "${ORACLE_BASE}"/fast_recovery_area
-- Non-managed (OMF) redo logs aren't deleted automatically (REDO GROUP 3 and 4 above)
-- Need to be deleted manually
HOST rm "${ORACLE_BASE}"/oradata/"${ORACLE_SID}"/redo03.log
HOST rm "${ORACLE_BASE}"/oradata/"${ORACLE_SID}"/redo04.log
-- Enable new service name FREE for upwards compatibility with FREE.
ALTER SYSTEM SET SERVICE_NAMES=XE,FREE;
exit;
EOF
###################################
######## FULL INSTALL DONE ########
###################################
# If not building the FULL image, remove and shrink additional components
if [ "${BUILD_MODE}" == "REGULAR" ] || [ "${BUILD_MODE}" == "SLIM" ]; then
echo "BUILDER: further optimizations for REGULAR and SLIM image"
echo "BUILDER: changing database configuration and parameters for REGULAR and SLIM images"
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Disable shared servers (enables faster shutdown)
ALTER SYSTEM SET SHARED_SERVERS=0;
-- Disable password profile checks
ALTER PROFILE DEFAULT LIMIT FAILED_LOGIN_ATTEMPTS UNLIMITED PASSWORD_LIFE_TIME UNLIMITED;
---------------------------
------- Remove APEX -------
---------------------------
@${ORACLE_HOME}/apex/apxremov.sql
DROP PUBLIC SYNONYM HTMLDB_SYSTEM;
DROP PACKAGE HTMLDB_SYSTEM;
---------------------------
---- Remove HR schema -----
---------------------------
DROP USER HR cascade;
exit;
EOF
# Uninstall components
if [ "${BUILD_MODE}" == "SLIM" ]; then
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Do not exit on error because of expected error in catmet2.sql
-- WHENEVER SQLERROR EXIT SQL.SQLCODE
SHUTDOWN IMMEDIATE;
STARTUP UPGRADE;
---------------------------
------- Remove XDB --------
---------------------------
-- Remove XS components manually
drop index xdb.sc_xidx;
drop index xdb.prin_xidx;
drop public synonym XS\$CACHE_DELETE;
drop public synonym XS\$CACHE_ACTIONS;
drop public synonym DBA_NETWORK_ACLS;
drop public synonym DBA_NETWORK_ACL_PRIVILEGES;
drop public synonym DBA_WALLET_ACLS;
drop public synonym DBA_XDS_OBJECTS;
drop public synonym ALL_XDS_OBJECTS;
drop public synonym USER_XDS_OBJECTS;
drop public synonym DBA_XDS_INSTANCE_SETS;
drop public synonym ALL_XDS_INSTANCE_SETS;
drop public synonym USER_XDS_INSTANCE_SETS;
drop public synonym DBA_XDS_ATTRIBUTE_SECS;
drop public synonym ALL_XDS_ATTRIBUTE_SECS;
drop public synonym USER_XDS_ATTRIBUTE_SECS;
drop public synonym DOCUMENT_LINKS2;
drop public synonym ALL_XSC_SECURITY_CLASS;
drop public synonym ALL_XSC_SECURITY_CLASS_STATUS;
drop public synonym ALL_XSC_SECURITY_CLASS_DEP;
drop public synonym ALL_XSC_PRIVILEGE;
drop public synonym ALL_XSC_AGGREGATE_PRIVILEGE;
drop public synonym XS_SESSION_ROLES;
drop public synonym V\$XS_SESSION;
drop public synonym V\$XS_SESSION_ROLE;
drop public synonym V\$XS_SESSION_ATTRIBUTE;
drop public synonym USER_NETWORK_ACL_PRIVILEGES;
drop public synonym dbms_network_acl_utility;
drop public synonym dbms_network_acl_admin;
drop public synonym DBMS_XS_MTCACHE;
drop public synonym DBMS_XS_UTIL;
drop view DBA_NETWORK_ACLS;
drop view DBA_NETWORK_ACL_PRIVILEGES;
drop view DBA_WALLET_ACLS;
drop view DBA_XDS_OBJECTS;
drop view ALL_XDS_OBJECTS;
drop view USER_XDS_OBJECTS;
drop view DBA_XDS_INSTANCE_SETS;
drop view ALL_XDS_INSTANCE_SETS;
drop view USER_XDS_INSTANCE_SETS;
drop view DBA_XDS_ATTRIBUTE_SECS;
drop view ALL_XDS_ATTRIBUTE_SECS;
drop view USER_XDS_ATTRIBUTE_SECS;
drop view XDB.DOCUMENT_LINKS2;
drop view ALL_XSC_SECURITY_CLASS;
drop view ALL_XSC_SECURITY_CLASS_STATUS;
drop view ALL_XSC_SECURITY_CLASS_DEP;
drop view ALL_XSC_PRIVILEGE;
drop view ALL_XSC_AGGREGATE_PRIVILEGE;
drop view V\$XS_SESSION;
drop view V\$XS_SESSION_ROLE;
drop view V\$XS_SESSION_ATTRIBUTE;
drop view USER_NETWORK_ACL_PRIVILEGES;
drop table XDB.XS\$CACHE_ACTIONS;
drop table XDB.XS\$CACHE_DELETE;
drop table NET\$_ACL;
drop table WALLET\$_ACL;
drop package XS\$CATVIEW_UTIL;
drop package DBMS_XS_PRINCIPALS;
drop package DBMS_XS_PRINCIPALS_INT;
drop package DBMS_XS_ROLESET_EVENTS_INT;
drop package DBMS_XS_PRINCIPAL_EVENTS_INT;
drop package DBMS_XS_DATA_SECURITY_EVENTS;
drop package DBMS_XS_SECCLASS_EVENTS;
drop package DBMS_XS_MTCACHE;
drop package DBMS_XS_MTCACHE_FFI;
drop package XS_UTIL;
drop package dbms_network_acl_admin;
drop package dbms_network_acl_utility;
drop user XS\$NULL cascade;
-- XDB removal script
@${ORACLE_HOME}/rdbms/admin/catnoqm.sql
-- Update Data Pump and related objects and KU$_ views
@${ORACLE_HOME}/rdbms/admin/catxdbdv.sql
@${ORACLE_HOME}/rdbms/admin/dbmsmeta.sql
@${ORACLE_HOME}/rdbms/admin/dbmsmeti.sql
@${ORACLE_HOME}/rdbms/admin/dbmsmetu.sql
@${ORACLE_HOME}/rdbms/admin/dbmsmetb.sql
@${ORACLE_HOME}/rdbms/admin/dbmsmetd.sql
@${ORACLE_HOME}/rdbms/admin/dbmsmet2.sql
@${ORACLE_HOME}/rdbms/admin/catmeta.sql
@${ORACLE_HOME}/rdbms/admin/prvtmeta.plb
@${ORACLE_HOME}/rdbms/admin/prvtmeti.plb
@${ORACLE_HOME}/rdbms/admin/prvtmetu.plb
@${ORACLE_HOME}/rdbms/admin/prvtmetb.plb
@${ORACLE_HOME}/rdbms/admin/prvtmetd.plb
@${ORACLE_HOME}/rdbms/admin/prvtmet2.plb
@${ORACLE_HOME}/rdbms/admin/catmet2.sql
---------------------------
------- Remove Text -------
---------------------------
@${ORACLE_HOME}/ctx/admin/catnoctx.sql
drop procedure sys.validate_context;
---------------------------
----- Remove Spatial ------
---------------------------
-- Drop Spatial user
DROP USER MDSYS CASCADE;
-- Drop all public synonyms related to spatial
BEGIN
FOR cur IN (SELECT 'drop public synonym "' || synonym_name || '"' AS cmd
FROM dba_synonyms WHERE table_owner = 'MDSYS')
LOOP
EXECUTE IMMEDIATE cur.cmd;
END LOOP;
END;
/
---------------------------
--- Recompile database ----
---------------------------
@${ORACLE_HOME}/rdbms/admin/utlrp.sql
-- Restart DB in normal mode
shutdown immediate;
startup;
EOF
fi;
# Shrink datafiles
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
---------------------------
-- Shrink SYSAUX tablespace
---------------------------
-- Create new temporary SYSAUX tablespace
--CREATE TABLESPACE SYSAUX_TEMP DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/sysaux_temp.dbf'
--SIZE 250M AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED;
-- Move tables to temporary SYSAUX tablespace
--#TODO
--BEGIN
-- FOR cur IN (SELECT owner || '.' || table_name AS name FROM all_tables WHERE tablespace_name = 'SYSAUX') LOOP
-- EXECUTE IMMEDIATE 'ALTER TABLE ' || cur.name || ' MOVE TABLESPACE SYSAUX_TEMP';
-- END LOOP;
--END;
--/
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/sysaux.dbf' RESIZE ${SYSAUX_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/sysaux.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
---------------------------
-- Shrink SYSTEM tablespace
---------------------------
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/system.dbf' RESIZE ${SYSTEM_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/system.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-------------------------
-- Shrink TEMP tablespace
-------------------------
ALTER TABLESPACE TEMP SHRINK SPACE;
ALTER DATABASE TEMPFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/temp.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
--------------------------
-- Shrink USERS tablespace
--------------------------
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/users.dbf' RESIZE ${USERS_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/users.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-------------------------
-- Shrink UNDO tablespace
-------------------------
-- Create new temporary UNDO tablespace
CREATE UNDO TABLESPACE UNDO_TMP DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/undotbs_tmp.dbf'
SIZE 1M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-- Use new temporary UNDO tablespace (so that old one can be deleted)
ALTER SYSTEM SET UNDO_TABLESPACE='UNDO_TMP';
-- Delete old UNDO tablespace
DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES;
-- Recreate old UNDO tablespace with 1M size and AUTOEXTEND
CREATE UNDO TABLESPACE UNDOTBS1 DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/undotbs1.dbf'
SIZE 1M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-- Use newly created UNDO tablespace
ALTER SYSTEM SET UNDO_TABLESPACE='UNDOTBS1';
-- Drop temporary UNDO tablespace
DROP TABLESPACE UNDO_TMP INCLUDING CONTENTS AND DATAFILES;
---------------------------------
-- Shrink REDO log files
---------------------------------
-- Remove original redo logs from fast_recovery_area and create new ones
ALTER DATABASE ADD LOGFILE GROUP 3 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo03.log') SIZE ${REDO_SIZE}m;
ALTER DATABASE ADD LOGFILE GROUP 4 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo04.log') SIZE ${REDO_SIZE}m;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM CHECKPOINT;
ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 2;
ALTER DATABASE ADD LOGFILE GROUP 1 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo01.log') SIZE ${REDO_SIZE}m REUSE;
ALTER DATABASE ADD LOGFILE GROUP 2 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo02.log') SIZE ${REDO_SIZE}m REUSE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM CHECKPOINT;
ALTER DATABASE DROP LOGFILE GROUP 3;
ALTER DATABASE DROP LOGFILE GROUP 4;
-- Non-managed (OMF) redo logs aren't deleted automatically (REDO GROUP 3 and 4 above)
-- Need to be deleted manually
HOST rm "${ORACLE_BASE}"/oradata/"${ORACLE_SID}"/redo03.log
HOST rm "${ORACLE_BASE}"/oradata/"${ORACLE_SID}"/redo04.log
exit;
EOF
#TODO: create or replace directory XMLDIR as '${ORACLE_HOME}/rdbms/xml';
fi;
###################################
########### DB SHUTDOWN ###########
###################################
echo "BUILDER: graceful database shutdown"
# Shutdown database gracefully (listener is not yet running)
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Shutdown database gracefully
shutdown immediate;
exit;
EOF
###############################
### Compress Database files ###
###############################
echo "BUILDER: compressing database data files"
cd "${ORACLE_BASE}"/oradata
7zzs a "${ORACLE_SID}".7z "${ORACLE_SID}"
chown oracle:dba "${ORACLE_SID}".7z
mv "${ORACLE_SID}".7z "${ORACLE_BASE}"/
# Delete database files but not directory structure,
# that way external mount can mount just a sub directory
find "${ORACLE_SID}" -type f -exec rm "{}" \;
cd - 1> /dev/null
########################
### Install run file ###
########################
echo "BUILDER: installing operational files"
# Move operational files to ${ORACLE_BASE}
mv /install/*.sh "${ORACLE_BASE}"/
mv /install/resetPassword "${ORACLE_BASE}"/
mv /install/createAppUser "${ORACLE_BASE}"/
################################
### Setting file permissions ###
################################
echo "BUILDER: setting file permissions"
chown oracle:dba "${ORACLE_BASE}"/*.sh \
"${ORACLE_BASE}"/resetPassword \
"${ORACLE_BASE}"/createAppUser
chmod u+x "${ORACLE_BASE}"/*.sh \
"${ORACLE_BASE}"/resetPassword \
"${ORACLE_BASE}"/createAppUser
# Setting permissions for all folders so that they can be mounted on tmpfs
# (see https://github.com/gvenzl/oci-oracle-xe/issues/202)
chmod a+rwx -R "${ORACLE_BASE}"/oradata
#########################
####### Cleanup #########
#########################
echo "BUILDER: cleanup"
# Remove install directory
rm -r /install
# Cleanup XE files not needed for being in a container but were installed by the rpm
rm -r /etc/kde/xdg/menus/OracleXE
rm -r /usr/share/applications/oraclexe*
rm -r /usr/share/desktop-menu-files/oraclexe*
rm -r /usr/share/gnome/vfolders/oraclexe*
rm -r /usr/share/pixmaps/oraclexe*
/sbin/chkconfig --del oracle-xe
rm /etc/init.d/oracle-xe
rm -r /var/tmp/oradiag_oracle
# Remove SYS audit files created during install
rm "${ORACLE_BASE}"/admin/"${ORACLE_SID}"/adump/*.aud
# Remove Data Pump log file
rm "${ORACLE_BASE}"/admin/"${ORACLE_SID}"/dpdump/dp.log
# Remove Oracle DB install logs
rm "${ORACLE_HOME}"/config/log/*
# Remove diag files
rm "${ORACLE_BASE}"/diag/rdbms/xe/"${ORACLE_SID}"/lck/*
rm "${ORACLE_BASE}"/diag/rdbms/xe/"${ORACLE_SID}"/metadata/*
rm "${ORACLE_BASE}"/diag/rdbms/xe/"${ORACLE_SID}"/trace/"${ORACLE_SID}"_*
rm -r "${ORACLE_BASE}"/diag/tnslsnr/*
rm -r "${ORACLE_BASE}"/oradiag_oracle/*
# Remove additional files for REGULAR and SLIM builds
if [ "${BUILD_MODE}" == "REGULAR" ] || [ "${BUILD_MODE}" == "SLIM" ]; then
echo "BUILDER: further cleanup for REGULAR and SLIM image"
# Remove APEX directory
rm -r "${ORACLE_HOME}"/apex
# Remove JDBC drivers
rm -r "${ORACLE_HOME}"/jdbc
rm -r "${ORACLE_HOME}"/jlib
# Remove components from ORACLE_HOME
if [ "${BUILD_MODE}" == "SLIM" ]; then
echo "BUILDER: further cleanup for SLIM image"
# Remove Oracle Text directory
rm -r "${ORACLE_HOME}"/ctx
# Remove XDK
rm -r "${ORACLE_HOME}"/xdk
# Remove Oracle Spatial directory
rm -r "${ORACLE_HOME}"/md
# Remove demo directory
rm -r "${ORACLE_HOME}"/demo
# Remove ODBC samples
rm -r "${ORACLE_HOME}"/odbc
# Remove TNS samples
rm -r "${ORACLE_HOME}"/network/admin/samples
# Remove NLS demo
rm -r "${ORACLE_HOME}"/nls/demo
# Remove hs directory
rm -r "${ORACLE_HOME}"/hs
# Remove ldap directory
rm -r "${ORACLE_HOME}"/ldap
# Remove precomp directory
rm -r "${ORACLE_HOME}"/precomp
# Remove rdbms/demo directory
rm -r "${ORACLE_HOME}"/rdbms/demo
# Remove rdbms/jlib directory
rm -r "${ORACLE_HOME}"/rdbms/jlib
# Remove rdbms/public directory
rm -r "${ORACLE_HOME}"/rdbms/public
# Remove rdbms/jlib directory
rm -r "${ORACLE_HOME}"/rdbms/xml
# TODO
fi;
fi;
# Remove build packages
# Unfortunately microdnf does not automatically uninstall dependencies that have been
# installed with a package, so if you were to uninstall just util-linux, for example,
# it does not automatically also remove gzip again.
rpm -e --nodeps acl bc cryptsetup-libs dbus dbus-common dbus-daemon dbus-libs \
dbus-tools device-mapper device-mapper-libs \
elfutils-default-yama-scope elfutils-libs kmod-libs libfdisk \
libseccomp libutempter net-tools procps-ng \
systemd systemd-pam util-linux findutils
# Remove dnf cache
microdnf clean all
# Clean lastlog
echo "" > /var/log/lastlog