1#!/bin/sh
2#
3# Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License, version 2.0,
7# as published by the Free Software Foundation.
8#
9# This program is also distributed with certain software (including
10# but not limited to OpenSSL) that is licensed under separate terms,
11# as designated in a particular file or component or in included license
12# documentation.  The authors of MySQL hereby grant you an additional
13# permission to link the program and your derivative works with the
14# separately licensed software that they have included with MySQL.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19# GNU General Public License, version 2.0, for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
24#
25# Solaris post install script
26#
27
28#if [ /usr/man/bin/makewhatis ] ; then
29#  /usr/man/bin/makewhatis "$BASEDIR/mysql/man"
30#fi
31
32mygroup=mysql
33myuser=mysql
34mydatadir=/var/lib/mysql
35basedir=@@basedir@@
36mysecurefiledir=/var/lib/mysql-files
37
38if [ -n "$BASEDIR" ] ; then
39  basedir="$BASEDIR"
40fi
41
42# What MySQL calls "basedir" and what pkgadd tools calls "basedir"
43# is not the same thing. The default pkgadd base directory is /opt/mysql,
44# the MySQL one "/opt/mysql/mysql".
45
46mybasedir="$basedir/@@instdir@@"
47mystart1="$mybasedir/support-files/mysql.server"
48myinstdb="$mybasedir/scripts/mysql_install_db"
49mystart=/etc/init.d/mysql
50
51# Check: Is this a first installation, or an upgrade ?
52
53if [ -d "$mydatadir/mysql" ] ; then
54  :   # If the directory for system table files exists, we assume an upgrade.
55else
56  INSTALL=new  # This is a new installation, the directory will soon be created.
57fi
58
59# Create data directory if needed
60
61[ -d "$mydatadir"       ] || mkdir -p -m 755 "$mydatadir" || exit 1
62[ -d "$mydatadir/mysql" ] || mkdir "$mydatadir/mysql"     || exit 1
63[ -d "$mydatadir/test"  ] || mkdir "$mydatadir/test"      || exit 1
64
65# Set the data directory to the right user/group
66
67chown -R $myuser:$mygroup $mydatadir
68
69# Create securefile directory
70[ -d "$mysecurefiledir"  ] || mkdir -p -m 770 "$mysecurefiledir"      || exit 1
71chown -R $myuser:$mygroup $mysecurefiledir
72
73# Solaris patch 119255 (somewhere around revision 42) changes the behaviour
74# of pkgadd to set TMPDIR internally to a root-owned install directory.  This
75# has the unfortunate side effect of breaking running mysql_install_db with
76# the --user=mysql argument as mysqld uses TMPDIR if set, and is unable to
77# write temporary tables to that directory.  To work around this issue, we
78# create a subdirectory inside TMPDIR (if set) for mysqld to write to.
79#
80# Idea from Ben Hekster <heksterb@gmail.com> in bug#31164
81
82if [ -n "$TMPDIR" ] ; then
83  savetmpdir="$TMPDIR"
84  TMPDIR="$TMPDIR/mysql.$$"
85  export TMPDIR
86  mkdir "$TMPDIR"
87  chown $myuser:$mygroup "$TMPDIR"
88fi
89
90if [ -n "$INSTALL" ] ; then
91  # We install/update the system tables
92  (
93    cd "$mybasedir"
94    scripts/mysql_install_db \
95	  --rpm \
96	  --random-passwords \
97	  --user=mysql \
98	  --basedir="$mybasedir" \
99	  --datadir=$mydatadir
100  )
101fi
102
103if [ -n "$savetmpdir" ] ; then
104  TMPDIR="$savetmpdir"
105fi
106
107# ----------------------------------------------------------------------
108
109# Handle situation there is old start script installed already
110
111# If old start script is a soft link, we just remove it
112[ -h "$mystart" ] && rm -f "$mystart"
113
114# If old start script is a file, we rename it
115[ -f "$mystart" ] && mv -f "$mystart" "$mystart.old.$$"
116
117# ----------------------------------------------------------------------
118
119# We create a copy of an unmodified start script,
120# as a reference for the one maybe modifying it
121
122cp -f "$mystart1.in" "$mystart.in" || exit 1
123
124# We rewrite some scripts
125
126for script in "$mystart" "$mystart1" "$myinstdb" ; do
127  script_in="$script.in"
128  sed -e "s,@basedir@,$mybasedir,g" \
129      -e "s,@datadir@,$mydatadir,g" "$script_in" > "$script"
130  chmod u+x $script
131done
132
133rm -f "$mystart.in"
134
135exit 0
136
137