pre_install() { # Oracle Group Names and GIDs ORACLE_GIDS=('54321' '54322' '54323' '54324' '54325' '54326' '54330') ORACLE_GROUP_NAMES=('oinstall' 'dba' 'oper' 'backupdba' 'dgdba' 'kmdba' 'racdba') # Check if All the Users and Groups exist if getent passwd oracle || getent passwd 54321;then echo "The user oracle with uid 54321 exists!" >&2 exit 1 fi for ((i = 0; i < ${#ORACLE_GIDS[@]}; ++i));do if getent group ${ORACLE_GROUP_NAMES[i]} || getent group ${ORACLE_GIDS[i]};then echo "The group ${ORACLE_GROUP_NAMES[i]} with gid ${ORACLE_GIDS[i]} exists!" >&2 exit 2 fi done # Create All Required Users and Groups for ((i = 0; i < ${#ORACLE_GIDS[@]}; ++i));do groupadd --system --gid ${ORACLE_GIDS[i]} ${ORACLE_GROUP_NAMES[i]} done useradd --system --uid 54321 --gid 54321 --home-dir /var/lib/oracle \ --groups $(echo ${ORACLE_GROUP_NAMES[@]:1:${#ORACLE_GROUP_NAMES[@]}} | sed 's/ /,/g') oracle } post_install() { # Fix Permissions chown -R oracle:oinstall /opt/oracle /etc/oratab /var/lib/oracle # Create Default Database Listener su -s /bin/bash oracle -c '/opt/oracle/product/18c/dbhomeXE/bin/netca -silent \ -orahome /opt/oracle/product/18c/dbhomeXE -instype typical -inscomp client,oraclenet,javavm,server,ano \ -responseFile /opt/oracle/product/18c/dbhomeXE/network/install/netca_typ.rsp -insprtcl tcp -cfg local \ -authadp NO_VALUE -orahnam OraHomeXE -listenerparameters DEFAULT_SERVICE=XE' # Create Default Pluggable Database cat <<- 'EOF' [Info] Use the following with root command to set password and create default pluggable database: su -s /bin/bash oracle -c '/opt/oracle/product/18c/dbhomeXE/bin/dbca -silent \ -createDatabase -gdbName XE -templateName XE_Database.dbc -characterSet AL32UTF8 \ -createAsContainerDatabase true -numberOfPDBs 1 -sid XE -pdbName XEPDB1 \ -J-Doracle.assistants.dbca.validate.ConfigurationParams=false -emConfiguration DBEXPRESS \ -emExpressPort 5500 -J-Doracle.assistants.dbca.validate.DBCredentials=false -sampleSchema true \ -customScripts /opt/oracle/product/18c/dbhomeXE/assistants/dbca/postdb_creation.sql' EOF } pre_remove() { # Terminate All Processes PIDs=$(ps aux | grep -E '^oracle' | grep -v grep | awk '{print $2}') if [ "$PIDs" ];then kill -SIGKILL $PIDs fi } post_remove() { # Oracle Group Names and GIDs ORACLE_GROUP_NAMES=('oinstall' 'dba' 'oper' 'backupdba' 'dgdba' 'kmdba' 'racdba') # Remove Oracle Users and Groups userdel oracle for gp in ${ORACLE_GROUP_NAMES[@]};do groupdel $gp done # Remove Database Files rm -rf /opt/oracle /var/lib/oracle }