Merge pull request #7715 from vpeter4/mariadb-11

mariadb: include mariadb-upgrade and mariadb-check and update addon (1)
This commit is contained in:
mglae 2023-03-30 17:54:25 +02:00 committed by GitHub
commit 9bd74cef15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 24 deletions

View File

@ -1 +1,3 @@
initial release
1
- include mariadb-upgrade and mariadb-check
copy mariadb* binaries and make symbolic links to mysql*

View File

@ -3,7 +3,7 @@
PKG_NAME="mariadb"
PKG_VERSION="10.11.2"
PKG_REV="0"
PKG_REV="1"
PKG_SHA256="1c89dee0caed0f68bc2a1d203eb98a123150e6a179f6ee0f1fc0ba3f08dc71dc"
PKG_LICENSE="GPL2"
PKG_SITE="https://mariadb.org"
@ -89,13 +89,15 @@ addon() {
mkdir -p ${ADDON}/config
cp ${MARIADB}/bin/mariadbd \
${MARIADB}/bin/mysql \
${MARIADB}/bin/mysqladmin \
${MARIADB}/bin/mysqldump \
${MARIADB}/bin/mysql_secure_installation \
${MARIADB}/bin/mariadb \
${MARIADB}/bin/mariadb-admin \
${MARIADB}/bin/mariadb-check \
${MARIADB}/bin/mariadb-dump \
${MARIADB}/bin/mariadb-secure-installation \
${MARIADB}/bin/mariadb-upgrade \
${MARIADB}/bin/my_print_defaults \
${MARIADB}/bin/resolveip \
${MARIADB}/scripts/mysql_install_db \
${MARIADB}/scripts/mariadb-install-db \
${ADDON}/bin
cp -PR ${MARIADB}/share ${ADDON}

View File

@ -3,6 +3,10 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)
_create_bin_link() {
[ ! -L ${ADDON_DIR}/bin/${2} ] && ln -sfn ${1} ${ADDON_DIR}/bin/${2}
}
. /etc/profile
oe_setup_addon service.mariadb
@ -11,49 +15,57 @@ mkdir -p /run/mysqld
# exit if already running
PID=$(ps aux | awk '/\/bin\/mariadbd/ {print $1; exit 0}')
if [ -n "$PID" ]; then
if [ -n "${PID}" ]; then
echo "MariaDB server is already running"
exit 0
fi
# create symbolic links
_create_bin_link mariadb mysql
_create_bin_link mariadb-admin mysqladmin
_create_bin_link mariadb-dump mysqldump
_create_bin_link mariadb-secure-installation mysql_secure_installation
_create_bin_link mariadb-upgrade mysql_upgrade
_create_bin_link mariadb-install-db mysql_install_db
# copy config file
if [ ! -f $ADDON_HOME/my.cnf ]; then
cp $ADDON_DIR/config/my.cnf $ADDON_HOME
if [ ! -f ${ADDON_HOME}/my.cnf ]; then
cp ${ADDON_DIR}/config/my.cnf ${ADDON_HOME}
fi
# install database
if [ ! -d "$ADDON_HOME/data/mysql" ]; then
mkdir -p $ADDON_HOME/data
if [ ! -d "${ADDON_HOME}/data/mysql" ]; then
mkdir -p ${ADDON_HOME}/data
echo "Installing database"
$ADDON_DIR/bin/mysql_install_db --basedir=$ADDON_DIR --datadir=$ADDON_HOME/data
${ADDON_DIR}/bin/mariadb-install-db --basedir=${ADDON_DIR} --datadir=${ADDON_HOME}/data
fi
# check for first run and generate passwords
if grep -q "@MYSQL_ROOT_PASS@" $ADDON_HOME/settings.xml; then
if grep -q "@MYSQL_ROOT_PASS@" ${ADDON_HOME}/settings.xml; then
MYSQL_ROOT_PASS="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8)"
MYSQL_KODI_PASS="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8)"
sed -e "s|@MYSQL_ROOT_PASS@|$MYSQL_ROOT_PASS|g" \
-e "s|@MYSQL_KODI_PASS@|$MYSQL_KODI_PASS|g" \
-i $ADDON_HOME/settings.xml
sed -e "s|@MYSQL_ROOT_PASS@|${MYSQL_ROOT_PASS}|g" \
-e "s|@MYSQL_KODI_PASS@|${MYSQL_KODI_PASS}|g" \
-i ${ADDON_HOME}/settings.xml
fi
# init script to create user kodi and change passwords
init_file=""
if [[ ! -f $ADDON_HOME/set_mysql_passwords.sql ]] || [[ $ADDON_HOME/settings.xml -nt $ADDON_HOME/set_mysql_passwords.sql ]]; then
cat << SQL_DATA > $ADDON_HOME/set_mysql_passwords.sql
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('$MYSQL_ROOT_PASS');
if [[ ! -f ${ADDON_HOME}/set_mysql_passwords.sql ]] || [[ ${ADDON_HOME}/settings.xml -nt ${ADDON_HOME}/set_mysql_passwords.sql ]]; then
cat << SQL_DATA > ${ADDON_HOME}/set_mysql_passwords.sql
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('${MYSQL_ROOT_PASS}');
CREATE USER IF NOT EXISTS 'kodi';
CREATE USER IF NOT EXISTS 'kodi'@'localhost';
SET PASSWORD FOR 'kodi'=PASSWORD('$MYSQL_KODI_PASS');
SET PASSWORD FOR 'kodi'@'localhost'=PASSWORD('$MYSQL_KODI_PASS');
SET PASSWORD FOR 'kodi'=PASSWORD('${MYSQL_KODI_PASS}');
SET PASSWORD FOR 'kodi'@'localhost'=PASSWORD('${MYSQL_KODI_PASS}');
GRANT ALL ON *.* TO 'kodi';
GRANT ALL ON *.* TO 'kodi'@'localhost';
flush privileges;
SQL_DATA
init_file="--init-file=$ADDON_HOME/set_mysql_passwords.sql"
init_file="--init-file=${ADDON_HOME}/set_mysql_passwords.sql"
fi
echo "Starting mariadbd"
MYSQL_HOME="$ADDON_HOME" exec $ADDON_DIR/bin/mariadbd $init_file &
MYSQL_HOME="${ADDON_HOME}" exec ${ADDON_DIR}/bin/mariadbd ${init_file} &