Create webmail database before restoring from backup

This commit is contained in:
Bob Mottram 2016-07-25 20:35:13 +01:00
parent 2acf8f67ce
commit cb7374a8c5
2 changed files with 181 additions and 178 deletions

View File

@ -38,203 +38,222 @@ WEBMAIL_ADMIN_PASSWORD=
WEB_PATH=/var/www
WEBMAIL_PATH=$WEB_PATH/webmail
function get_mariadb_webmail_admin_password {
if [ -f /home/$MY_USERNAME/README ]; then
if grep -q "MariaDB webmail admin password" /home/$MY_USERNAME/README; then
WEBMAIL_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "MariaDB webmail admin password" | awk -F ':' '{print $2}' | sed 's/^ *//')
fi
fi
}
function webmail_create_database {
function_check get_mariadb_webmail_admin_password
get_mariadb_webmail_admin_password
if [ ! $WEBMAIL_ADMIN_PASSWORD ]; then
if [ -f $IMAGE_PASSWORD_FILE ]; then
WEBMAIL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
else
WEBMAIL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
fi
fi
if [ ! $WEBMAIL_ADMIN_PASSWORD ]; then
return
fi
function_check create_database
create_database webmail "$WEBMAIL_ADMIN_PASSWORD"
}
function reconfigure_webmail {
echo -n ''
echo -n ''
}
function upgrade_webmail {
if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
return
fi
function_check set_repo_commit
set_repo_commit $WEBMAIL_PATH "Webmail commit" "$WEBMAIL_COMMIT" $WEBMAIL_REPO
if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
return
fi
function_check set_repo_commit
set_repo_commit $WEBMAIL_PATH "Webmail commit" "$WEBMAIL_COMMIT" $WEBMAIL_REPO
}
function backup_local_webmail {
if ! grep -q "install_webmail" $COMPLETION_FILE; then
return
fi
echo $"Backing up webmail"
if ! grep -q "install_webmail" $COMPLETION_FILE; then
return
fi
echo $"Backing up webmail"
function_check backup_database_to_usb
backup_database_to_usb webmail
function_check backup_database_to_usb
backup_database_to_usb webmail
echo $"Backing up webmail complete"
echo $"Backing up webmail complete"
}
function restore_local_webmail {
if ! grep -q "install_webmail" $COMPLETION_FILE; then
return
fi
echo $"Restoring webmail"
if ! grep -q "install_webmail" $COMPLETION_FILE; then
return
fi
echo $"Restoring webmail"
function_check restore_database
restore_database webmail
function_check webmail_create_database
webmail_create_database
echo $"Restore of webmail complete"
function_check restore_database
restore_database webmail
echo $"Restore of webmail complete"
}
function backup_remote_webmail {
echo -n ''
echo -n ''
}
function restore_remote_webmail {
echo -n ''
echo -n ''
}
function remove_webmail {
if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
return
fi
nginx_dissite webmail
if [ -f /etc/nginx/sites-available/webmail ]; then
rm /etc/nginx/sites-available/webmail
fi
function_check remove_onion_service
remove_onion_service webmail ${WEBMAIL_ONION_PORT}
function_check drop_database
drop_database webmail
if [ -d $WEB_PATH/webmail ]; then
rm -rf $WEB_PATH/webmail
fi
sed -i '/Webmail /d' $COMPLETION_FILE
sed -i '/install_webmail/d' $COMPLETION_FILE
if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
return
fi
nginx_dissite webmail
if [ -f /etc/nginx/sites-available/webmail ]; then
rm /etc/nginx/sites-available/webmail
fi
function_check remove_onion_service
remove_onion_service webmail ${WEBMAIL_ONION_PORT}
function_check drop_database
drop_database webmail
if [ -d $WEB_PATH/webmail ]; then
rm -rf $WEB_PATH/webmail
fi
sed -i '/Webmail /d' $COMPLETION_FILE
sed -i '/install_webmail/d' $COMPLETION_FILE
}
function install_webmail {
if grep -Fxq "install_webmail" $COMPLETION_FILE; then
return
fi
if [ -d /etc/apache2 ]; then
rm -rf /etc/apache2
echo $'Removed Apache installation after Dokuwiki install'
fi
function_check install_mariadb
install_mariadb
function_check get_mariadb_password
get_mariadb_password
function_check repair_databases_script
repair_databases_script
apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
apt-get -y install php5-dev imagemagick php5-imagick php5-sqlite php-auth-sasl php-net-smtp php-mime-type
apt-get -y install php-mail-mime php-mail-mimedecode php-net-ldap3 php5-pspell
pear install Net_IDNA2
if [ ! -f $WEBMAIL_PATH/index.php ]; then
cd $WEB_PATH
git_clone $WEBMAIL_REPO webmail
cd $WEBMAIL_PATH
git checkout $WEBMAIL_COMMIT -b $WEBMAIL_COMMIT
if ! grep -q "Webmail commit" $COMPLETION_FILE; then
echo "Webmail commit:$WEBMAIL_COMMIT" >> $COMPLETION_FILE
else
sed -i "s/Webmail commit.*/Webmail commit:$WEBMAIL_COMMIT/g" $COMPLETION_FILE
if grep -Fxq "install_webmail" $COMPLETION_FILE; then
return
fi
fi
if [ ! -f $WEBMAIL_PATH/index.php ]; then
echo $'Did not clone webmail repo'
exit 52825
fi
WEBMAIL_ONION_HOSTNAME=$(add_onion_service webmail 80 ${WEBMAIL_ONION_PORT})
echo "Webmail onion domain:${WEBMAIL_ONION_HOSTNAME}" >> $COMPLETION_FILE
function_check get_mariadb_webmail_admin_password
get_mariadb_webmail_admin_password
if [ ! $WEBMAIL_ADMIN_PASSWORD ]; then
if [ -f $IMAGE_PASSWORD_FILE ]; then
WEBMAIL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
else
WEBMAIL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
if [ -d /etc/apache2 ]; then
rm -rf /etc/apache2
echo $'Removed Apache installation after Dokuwiki install'
fi
fi
function_check create_database
create_database webmail "$WEBMAIL_ADMIN_PASSWORD"
mysql -u root --password="$MARIADB_PASSWORD" -D webmail < $WEBMAIL_PATH/SQL/mysql.initial.sql
if [ ! -d /var/www/$DEFAULT_DOMAIN_NAME/htdocs ]; then
mkdir -p /var/www/$DEFAULT_DOMAIN_NAME/htdocs
fi
ln -s $WEBMAIL_PATH /var/www/$DEFAULT_DOMAIN_NAME/htdocs/webmail
function_check install_mariadb
install_mariadb
if [ ! -f /var/www/webmail/config/config.inc.php ]; then
# generate the configuration
echo '<?php' > /var/www/webmail/config/config.inc.php
echo "\$config['db_dsnw'] = 'mysql://root:${MARIADB_PASSWORD}@localhost/webmail';" >> /var/www/webmail/config/config.inc.php
echo "\$config['default_host'] = 'localhost';" >> /var/www/webmail/config/config.inc.php
echo "\$config['support_url'] = '';" >> /var/www/webmail/config/config.inc.php
WEBMAIL_DES_KEY="$(create_password 25)"
echo "\$config['des_key'] = '${WEBMAIL_DES_KEY}';" >> /var/www/webmail/config/config.inc.php
echo "\$config['product_name'] = '${PROJECT_NAME}';" >> /var/www/webmail/config/config.inc.php
echo "\$config['plugins'] = array('enigma');" >> /var/www/webmail/config/config.inc.php
echo "\$config['mime_param_folding'] = 0;" >> /var/www/webmail/config/config.inc.php
echo "\$config['enable_installer'] = false;" >> /var/www/webmail/config/config.inc.php
fi
function_check get_mariadb_password
get_mariadb_password
chown -R www-data:www-data $WEBMAIL_PATH
function_check repair_databases_script
repair_databases_script
echo 'server {' > /etc/nginx/sites-available/webmail
echo " listen 127.0.0.1:$WEBMAIL_ONION_PORT default_server;" >> /etc/nginx/sites-available/webmail
echo " server_name $WEBMAIL_ONION_HOSTNAME;" >> /etc/nginx/sites-available/webmail
echo " root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
echo ' index index.php index.html index.htm;' >> /etc/nginx/sites-available/webmail
echo ' access_log off;' >> /etc/nginx/sites-available/webmail
echo ' error_log off;' >> /etc/nginx/sites-available/webmail
echo ' location / {' >> /etc/nginx/sites-available/webmail
echo ' try_files $uri $uri/ /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' error_page 404 /404.html;' >> /etc/nginx/sites-available/webmail
echo ' error_page 500 502 503 504 /50x.html;' >> /etc/nginx/sites-available/webmail
echo ' location = /50x.html {' >> /etc/nginx/sites-available/webmail
echo " root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {' >> /etc/nginx/sites-available/webmail
echo ' deny all;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' location ~ ^/(config|temp|logs)/ {' >> /etc/nginx/sites-available/webmail
echo ' deny all;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' location ~ /\. {' >> /etc/nginx/sites-available/webmail
echo ' deny all;' >> /etc/nginx/sites-available/webmail
echo ' access_log off;' >> /etc/nginx/sites-available/webmail
echo ' log_not_found off;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' location ~ \.php$ {' >> /etc/nginx/sites-available/webmail
echo ' try_files $uri =404;' >> /etc/nginx/sites-available/webmail
echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/webmail
echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/webmail
echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/webmail
echo ' include fastcgi_params;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/webmail
echo ' add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/webmail
echo ' client_max_body_size 15m;' >> /etc/nginx/sites-available/webmail
echo '}' >> /etc/nginx/sites-available/webmail
apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
apt-get -y install php5-dev imagemagick php5-imagick php5-sqlite php-auth-sasl php-net-smtp php-mime-type
apt-get -y install php-mail-mime php-mail-mimedecode php-net-ldap3 php5-pspell
pear install Net_IDNA2
nginx_ensite webmail
systemctl restart php5-fpm
systemctl restart nginx
if ! grep -q "Webmail" /home/$MY_USERNAME/README; then
echo '' >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README
echo 'Webmail' >> /home/$MY_USERNAME/README
echo '=======' >> /home/$MY_USERNAME/README
if [[ $ONION_ONLY == 'no' ]]; then
echo $"Open https://$DEFAULT_DOMAIN_NAME/webmail/index.php" >> /home/$MY_USERNAME/README
else
echo $"Open http://$WEBMAIL_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
if [ ! -f $WEBMAIL_PATH/index.php ]; then
cd $WEB_PATH
git_clone $WEBMAIL_REPO webmail
cd $WEBMAIL_PATH
git checkout $WEBMAIL_COMMIT -b $WEBMAIL_COMMIT
if ! grep -q "Webmail commit" $COMPLETION_FILE; then
echo "Webmail commit:$WEBMAIL_COMMIT" >> $COMPLETION_FILE
else
sed -i "s/Webmail commit.*/Webmail commit:$WEBMAIL_COMMIT/g" $COMPLETION_FILE
fi
fi
if [ ! -f $WEBMAIL_PATH/index.php ]; then
echo $'Did not clone webmail repo'
exit 52825
fi
echo $"MariaDB webmail admin password: $WEBMAIL_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
chmod 600 /home/$MY_USERNAME/README
fi
echo 'install_webmail' >> $COMPLETION_FILE
WEBMAIL_ONION_HOSTNAME=$(add_onion_service webmail 80 ${WEBMAIL_ONION_PORT})
echo "Webmail onion domain:${WEBMAIL_ONION_HOSTNAME}" >> $COMPLETION_FILE
webmail_create_database
mysql -u root --password="$MARIADB_PASSWORD" -D webmail < $WEBMAIL_PATH/SQL/mysql.initial.sql
if [ ! -d /var/www/$DEFAULT_DOMAIN_NAME/htdocs ]; then
mkdir -p /var/www/$DEFAULT_DOMAIN_NAME/htdocs
fi
ln -s $WEBMAIL_PATH /var/www/$DEFAULT_DOMAIN_NAME/htdocs/webmail
if [ ! -f /var/www/webmail/config/config.inc.php ]; then
# generate the configuration
echo '<?php' > /var/www/webmail/config/config.inc.php
echo "\$config['db_dsnw'] = 'mysql://root:${MARIADB_PASSWORD}@localhost/webmail';" >> /var/www/webmail/config/config.inc.php
echo "\$config['default_host'] = 'localhost';" >> /var/www/webmail/config/config.inc.php
echo "\$config['support_url'] = '';" >> /var/www/webmail/config/config.inc.php
WEBMAIL_DES_KEY="$(create_password 25)"
echo "\$config['des_key'] = '${WEBMAIL_DES_KEY}';" >> /var/www/webmail/config/config.inc.php
echo "\$config['product_name'] = '${PROJECT_NAME}';" >> /var/www/webmail/config/config.inc.php
echo "\$config['plugins'] = array('enigma');" >> /var/www/webmail/config/config.inc.php
echo "\$config['mime_param_folding'] = 0;" >> /var/www/webmail/config/config.inc.php
echo "\$config['enable_installer'] = false;" >> /var/www/webmail/config/config.inc.php
fi
chown -R www-data:www-data $WEBMAIL_PATH
echo 'server {' > /etc/nginx/sites-available/webmail
echo " listen 127.0.0.1:$WEBMAIL_ONION_PORT default_server;" >> /etc/nginx/sites-available/webmail
echo " server_name $WEBMAIL_ONION_HOSTNAME;" >> /etc/nginx/sites-available/webmail
echo " root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
echo ' index index.php index.html index.htm;' >> /etc/nginx/sites-available/webmail
echo ' access_log off;' >> /etc/nginx/sites-available/webmail
echo ' error_log off;' >> /etc/nginx/sites-available/webmail
echo ' location / {' >> /etc/nginx/sites-available/webmail
echo ' try_files $uri $uri/ /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' error_page 404 /404.html;' >> /etc/nginx/sites-available/webmail
echo ' error_page 500 502 503 504 /50x.html;' >> /etc/nginx/sites-available/webmail
echo ' location = /50x.html {' >> /etc/nginx/sites-available/webmail
echo " root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {' >> /etc/nginx/sites-available/webmail
echo ' deny all;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' location ~ ^/(config|temp|logs)/ {' >> /etc/nginx/sites-available/webmail
echo ' deny all;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' location ~ /\. {' >> /etc/nginx/sites-available/webmail
echo ' deny all;' >> /etc/nginx/sites-available/webmail
echo ' access_log off;' >> /etc/nginx/sites-available/webmail
echo ' log_not_found off;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' location ~ \.php$ {' >> /etc/nginx/sites-available/webmail
echo ' try_files $uri =404;' >> /etc/nginx/sites-available/webmail
echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/webmail
echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/webmail
echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/webmail
echo ' include fastcgi_params;' >> /etc/nginx/sites-available/webmail
echo ' }' >> /etc/nginx/sites-available/webmail
echo ' add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/webmail
echo ' add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/webmail
echo ' client_max_body_size 15m;' >> /etc/nginx/sites-available/webmail
echo '}' >> /etc/nginx/sites-available/webmail
nginx_ensite webmail
systemctl restart php5-fpm
systemctl restart nginx
if ! grep -q "Webmail" /home/$MY_USERNAME/README; then
echo '' >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README
echo 'Webmail' >> /home/$MY_USERNAME/README
echo '=======' >> /home/$MY_USERNAME/README
if [[ $ONION_ONLY == 'no' ]]; then
echo $"Open https://$DEFAULT_DOMAIN_NAME/webmail/index.php" >> /home/$MY_USERNAME/README
else
echo $"Open http://$WEBMAIL_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
fi
echo $"MariaDB webmail admin password: $WEBMAIL_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
chmod 600 /home/$MY_USERNAME/README
fi
echo 'install_webmail' >> $COMPLETION_FILE
}
# NOTE: deliberately no exit 0

View File

@ -116,22 +116,6 @@ function get_mariadb_password {
fi
}
function get_mariadb_media_server_admin_password {
if [ -f /home/$MY_USERNAME/README ]; then
if grep -q "Media server administrator password" /home/$MY_USERNAME/README; then
MEDIA_SERVER_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Media server administrator password" | awk -F ':' '{print $2}' | sed 's/^ *//')
fi
fi
}
function get_mariadb_webmail_admin_password {
if [ -f /home/$MY_USERNAME/README ]; then
if grep -q "MariaDB webmail admin password" /home/$MY_USERNAME/README; then
WEBMAIL_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "MariaDB webmail admin password" | awk -F ':' '{print $2}' | sed 's/^ *//')
fi
fi
}
function install_mariadb {
if grep -Fxq "install_mariadb" $COMPLETION_FILE; then
return