randomize database password (fixes)

This commit is contained in:
nachoparker 2017-07-29 11:12:12 +02:00
parent 558e3a5029
commit 530e3a1e06
6 changed files with 15 additions and 13 deletions

View File

@ -24,17 +24,15 @@ DBBACKUP=nextcloud-sqlbkp_`date +"%Y%m%d"`.bak
configure()
{
local DBPASSWD=$( cat /root/.dbpass )
cd $BASEDIR_/nextcloud
sudo -u www-data php occ maintenance:mode --on
cd $BASEDIR_
echo -e "backup database..."
mysqldump -u root -p$DBPASSWD --single-transaction nextcloud > $DBBACKUP
mysqldump -u root --single-transaction nextcloud > $DBBACKUP
echo -e "backup files..."
mkdir -p $DESTDIR
mkdir -p $DESTDIR_
tar -cf $DESTFILE $DBBACKUP nextcloud/ && \
echo -e "backup $DESTFILE generated" || \
echo -e "error generating backup"

View File

@ -34,8 +34,6 @@ show_info()
configure()
{
local DBPASSWD=$( cat /root/.dbpass )
## RE-CREATE DATABASE TABLE
echo "Setting up database..."
@ -49,6 +47,7 @@ configure()
done
# workaround to emulate DROP USER IF EXISTS ..;)
local DBPASSWD=$( grep password /root/.my.cnf | cut -d= -f2 )
mysql -u root -p$DBPASSWD <<EOF
DROP DATABASE IF EXISTS nextcloud;
CREATE DATABASE nextcloud

View File

@ -45,7 +45,6 @@ install() { :; }
configure()
{
local DBPASSWD=$( cat /root/.dbpass )
## RE-CREATE DATABASE TABLE
echo "Starting mariaDB"
@ -62,7 +61,9 @@ configure()
done
echo "Setting up database..."
# workaround to emulate DROP USER IF EXISTS ..;)
local DBPASSWD=$( grep password /root/.my.cnf | cut -d= -f2 )
mysql -u root -p$DBPASSWD <<EOF
DROP DATABASE IF EXISTS nextcloud;
CREATE DATABASE nextcloud

View File

@ -39,8 +39,6 @@ You can use nc-backup " \
configure()
{
local DBPASSWD=$( cat /root/.dbpass )
[ -f $BACKUPFILE_ ] || { echo -e "$BACKUPFILE_ not found"; return 1; }
[ -d $BASEDIR_ ] || { echo -e "$BASEDIR_ not found"; return 1; }
[ -d $BASEDIR_/nextcloud ] && { echo -e "WARNING: overwriting old instance"; }
@ -55,6 +53,7 @@ configure()
tar -xf $BACKUPFILE_ || return 1
# RE-CREATE DATABASE TABLE
local DBPASSWD=$( grep password /root/.my.cnf | cut -d= -f2 )
echo -e "restore database..."
mysql -u root -p$DBPASSWD <<EOF
DROP DATABASE IF EXISTS nextcloud;

View File

@ -47,9 +47,9 @@ EOF
# Randomize mariaDB password
# Suggested by @enoch85 and taken from the nextcloud vm ( https://github.com/nextcloud/vm/blob/master/lib.sh#L46 )
$DBPASSWD=$(tr -dc "a-zA-Z0-9@#*=" < /dev/urandom | fold -w "$(shuf -i 30-35 -n 1)" | head -n 1)
echo $DBPASSWD > /root/.dbpass
chmod 600 /root/.dbpass
DBPASSWD=$(tr -dc "a-zA-Z0-9@#*=" < /dev/urandom | fold -w "$(shuf -i 30-35 -n 1)" | head -n 1)
echo -e "[client]\npassword=$DBPASSWD" > /root/.my.cnf
chmod 600 /root/.my.cnf
debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password password $DBPASSWD"
debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password_again password $DBPASSWD"

View File

@ -50,10 +50,15 @@ cp -r ncp-web /var/www/
chown www-data:www-data /var/www/ncp-web
chmod 770 /var/www/ncp-web
# force-fix unattended-upgrades for old image users
## BACKWARD FIXES ( for older images )
# force-fix unattended-upgrades
cd /usr/local/etc/nextcloudpi-config.d/
activate_script unattended-upgrades.sh
# for old image users, save default password
test -f /root/.my.cnf || echo -e "[client]\npassword=ownyourbits" > /root/.my.cnf
# License
#
# This script is free software; you can redistribute it and/or modify it