Skip to content

Instantly share code, notes, and snippets.

@crystoll
Last active March 19, 2018 07:01
Show Gist options
  • Save crystoll/990e274ef1f7beefe261aa8ea390e75c to your computer and use it in GitHub Desktop.
Save crystoll/990e274ef1f7beefe261aa8ea390e75c to your computer and use it in GitHub Desktop.
#!/bin/bash -xe
if [ "$#" -ne 2 ]; then
echo "No arguments supplied. Supply two arguments, password for SYS role to use when creating the database, and database name."
exit 1
fi
DB_PASSWORD=$1
DB_NAME=$2
cat <<EOF >> /home/oracle/.bashrc
export ORACLE_SID=$DB_NAME
EOF
cat <<EOF >> /home/oracle/create-db.sh
lsnrctl start
dbca -silent \
-createDatabase \
-templateName General_Purpose.dbc \
-gdbname $DB_NAME \
-sid $DB_NAME \
-responseFile NO_VALUE \
-characterSet AL32UTF8 \
-sysPassword $DB_PASSWORD \
-systemPassword $DB_PASSWORD \
-databaseType MULTIPURPOSE \
-automaticMemoryManagement false \
-storageType FS \
-ignorePreReqs
sqlplus -s /nolog <<EOF2
CONNECT system/$DB_PASSWORD;
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
CREATE USER sem_repo IDENTIFIED BY sem_repo
DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP;
GRANT CONNECT, RESOURCE TO sem_repo;
-- The following command should be used for Oracle 12c and above
GRANT UNLIMITED TABLESPACE TO sem_repo;
exit;
EOF2
EOF
chown oracle /home/oracle/create-db.sh
chmod o+x /home/oracle/create-db.sh
sudo su - oracle "/home/oracle/create-db.sh"
# Autostart Oracle DB
#Edit /etc/oratab, change default N to Y:
sed -i.bak 's/dbhome_1:N/dbhome_1:Y/g' /etc/oratab
# Create dbora init script
cat <<'EOF' >> /etc/init.d/dbora
#!/bin/sh
# chkconfig: 345 99 10
# Description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to $ORACLE_HOME.
ORA_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
ORA_OWNER=oracle
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the Oracle sign-in
# will not prompt the user for any values.
# Remove "&" if you don't want startup as a background process.
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME" &
touch /var/lock/subsys/dbora
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the Oracle sign-in
# will not prompt the user for any values.
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME" &
rm -f /var/lock/subsys/dbora
;;
esac
EOF
chgrp dba /etc/init.d/dbora
chmod 750 /etc/init.d/dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment