| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Copyright (c) 2015, 2026, Oracle and/or its affiliates. |
| 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 designed to work 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 either included with |
| 15 |
# the program or referenced in the documentation. |
| 16 |
# |
| 17 |
# This program is distributed in the hope that it will be useful, |
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 |
# GNU General Public License, version 2.0, for more details. |
| 21 |
# |
| 22 |
# You should have received a copy of the GNU General Public License |
| 23 |
# along with this program; if not, write to the Free Software |
| 24 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
. /usr/share/debconf/confmodule |
| 27 |
|
| 28 |
# Router versions prior to 8.0.20 were using non-persisted directory |
| 29 |
# as a default for data_directory. Here we want to fix the existing |
| 30 |
# configuration if it is affected by this bug. |
| 31 |
fix_datadir_path() { |
| 32 |
CONFIGFILE=/etc/mysqlrouter/mysqlrouter.conf |
| 33 |
INVALID_DATA_DIR=/run/mysqlrouter |
| 34 |
CORRECT_DATA_DIR=/var/lib/mysqlrouter |
| 35 |
MASTER_KEYRING_FILE=/etc/mysqlrouter/mysqlrouter.key |
| 36 |
|
| 37 |
if [ ! -f $CONFIGFILE ]; then |
| 38 |
return 0 |
| 39 |
fi |
| 40 |
|
| 41 |
# we don't want the grep not being able to find the pattern to fail the script |
| 42 |
set +e |
| 43 |
has_invalid_keyring_path=$(grep "^keyring_path=$INVALID_DATA_DIR/keyring$" $CONFIGFILE) |
| 44 |
has_invalid_statefile_path=$(grep "^dynamic_state=$INVALID_DATA_DIR/state.json$" $CONFIGFILE) |
| 45 |
set -e |
| 46 |
|
| 47 |
if [ -z "$has_invalid_keyring_path" ] && [ -z "$has_invalid_statefile_path" ]; then |
| 48 |
return 0 |
| 49 |
fi |
| 50 |
|
| 51 |
# make a copy of the config file before modifying it |
| 52 |
cp -p $CONFIGFILE $CONFIGFILE.tmp |
| 53 |
|
| 54 |
# fix the keyring location if needed |
| 55 |
if [ ! -z "$has_invalid_keyring_path" ]; then |
| 56 |
sed -i "s|^keyring_path=$INVALID_DATA_DIR/keyring$|keyring_path=$CORRECT_DATA_DIR/keyring|" \ |
| 57 |
$CONFIGFILE.tmp |
| 58 |
|
| 59 |
# make a copy of the master keyring file before modifying it |
| 60 |
cp -p $MASTER_KEYRING_FILE $MASTER_KEYRING_FILE.tmp |
| 61 |
mysqlrouter_keyring master-rename --master-key-file \ |
| 62 |
$MASTER_KEYRING_FILE.tmp $INVALID_DATA_DIR/keyring $CORRECT_DATA_DIR/keyring |
| 63 |
fi |
| 64 |
|
| 65 |
# fix the dynamic state file location if needed |
| 66 |
if [ ! -z "$has_invalid_statefile_path" ]; then |
| 67 |
sed -i "s|^dynamic_state=$INVALID_DATA_DIR/state.json$|dynamic_state=$CORRECT_DATA_DIR/state.json|" \ |
| 68 |
$CONFIGFILE.tmp |
| 69 |
fi |
| 70 |
|
| 71 |
# files modifications went ok, now move them to proper locations and clean up |
| 72 |
if [ ! -z "$has_invalid_keyring_path" ]; then |
| 73 |
cp -np $INVALID_DATA_DIR/keyring $CORRECT_DATA_DIR |
| 74 |
cp -p $MASTER_KEYRING_FILE.tmp $MASTER_KEYRING_FILE |
| 75 |
|
| 76 |
rm $INVALID_DATA_DIR/keyring $MASTER_KEYRING_FILE.tmp |
| 77 |
fi |
| 78 |
|
| 79 |
if [ ! -z "$has_invalid_statefile_path" ]; then |
| 80 |
cp -np $INVALID_DATA_DIR/state.json $CORRECT_DATA_DIR |
| 81 |
rm $INVALID_DATA_DIR/state.json |
| 82 |
fi |
| 83 |
|
| 84 |
cp -p $CONFIGFILE.tmp $CONFIGFILE |
| 85 |
rm $CONFIGFILE.tmp |
| 86 |
} |
| 87 |
|
| 88 |
case "$1" in |
| 89 |
configure) |
| 90 |
set -e |
| 91 |
ldconfig |
| 92 |
if dpkg --compare-versions "$2" le "8.0.20"; then |
| 93 |
echo "Fixing the data files location (if needed)" |
| 94 |
fix_datadir_path |
| 95 |
fi |
| 96 |
set +e |
| 97 |
;; |
| 98 |
|
| 99 |
abort-remove) |
| 100 |
;; |
| 101 |
|
| 102 |
abort-upgrade|abort-configure) |
| 103 |
;; |
| 104 |
esac |
| 105 |
|
| 106 |
#DEBHELPER# |
| 107 |
|
| 108 |
exit 0 |