mirror of
https://github.com/YunoHost-Apps/baikal_ynh.git
synced 2024-09-03 18:16:11 +02:00
[enh] Update the upgrade script which now runs Baikal upgrade
This commit is contained in:
parent
6081c375fb
commit
8cd34fda8e
3 changed files with 156 additions and 79 deletions
|
@ -25,9 +25,9 @@ or from the Web administration:
|
|||
|
||||
## TODO
|
||||
|
||||
* Update the `upgrade` script and test the upgrade from the current
|
||||
official package
|
||||
* Test the upgrade from the current official package
|
||||
* Add `backup` and `remove` scripts
|
||||
* Update `config.php` and `config.system.php` at upgrade
|
||||
|
||||
## Links ##
|
||||
|
||||
|
|
131
scripts/upgrade
131
scripts/upgrade
|
@ -1,90 +1,67 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$(sudo yunohost app setting baikal domain)
|
||||
path=$(sudo yunohost app setting baikal path)
|
||||
password=$(sudo yunohost app setting baikal password)
|
||||
set -u
|
||||
|
||||
# Remove trailing "/" for next commands
|
||||
# Load common variables and helpers
|
||||
. ./_common.sh
|
||||
|
||||
# Set app specific variables
|
||||
app=${!#}
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
|
||||
# Retrieve arguments
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path=${path%/}
|
||||
|
||||
# Check destination directory
|
||||
DESTDIR="/var/www/$app"
|
||||
[[ ! -d $DESTDIR ]] && ynh_die \
|
||||
"The destination directory '$DESTDIR' does not exist.\
|
||||
The app is not correctly installed, you should remove it first."
|
||||
|
||||
# Copy files to the right place
|
||||
final_path=/var/www/baikal
|
||||
# Create tmp directory and fetch new app inside
|
||||
TMPDIR=$(ynh_mkdir_tmp)
|
||||
extract_baikal "$TMPDIR"
|
||||
|
||||
# let's not use a bash variable for this one...
|
||||
sudo rm -rf /var/www/baikal
|
||||
# Get Specific folder from current installation
|
||||
# FIXME: config.php and config.system.php are not updated with possible
|
||||
# new or changed configurations
|
||||
rm -rf "${TMPDIR}/Specific"
|
||||
sudo cp -r "${DESTDIR}/Specific" "$TMPDIR"
|
||||
sudo chown -hR "${USER}" "${TMPDIR}/Specific"
|
||||
|
||||
sudo mkdir -p $final_path
|
||||
sudo cp -a ../sources/* $final_path
|
||||
sudo chown -R www-data: $final_path
|
||||
sudo su -c "curl -sS https://getcomposer.org/installer | php -- --install-dir=$final_path" -s /bin/sh www-data
|
||||
sudo su -c "cd $final_path && php composer.phar install" -s /bin/sh www-data
|
||||
sudo rm $final_path/composer*
|
||||
# Run Baikal upgrade from tmp directory
|
||||
cp -r ../sources/bin "$TMPDIR"
|
||||
php "${TMPDIR}/bin/upgrade.sh" \
|
||||
|| echo "The Baïkal upgrade failed, you should try to go to " \
|
||||
"https://${domain}${path}/admin/install"
|
||||
|
||||
db_pwd=$(sudo yunohost app setting baikal mysqlpwd)
|
||||
db_user=baikal
|
||||
sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/config.php
|
||||
sed -i "s@YNH_ADMIN_PASSWORDHASH@$(echo -n admin:BaikalDAV:$password | md5sum | cut -d ' ' -f 1)@g" ../conf/config.php
|
||||
# Install new app and set permissions
|
||||
sudo rm -rf "$DESTDIR"
|
||||
sudo mv "$TMPDIR" "$DESTDIR"
|
||||
sudo chown -R www-data: "$DESTDIR"
|
||||
|
||||
sed -i "s@YNH_LOCATION@$path@g" ../conf/config.system.php
|
||||
sed -i "s@YNH_DBNAME@$db_user@g" ../conf/config.system.php
|
||||
sed -i "s@YNH_DBUSER@$db_user@g" ../conf/config.system.php
|
||||
sed -i "s@YNH_DBPWD@$db_pwd@g" ../conf/config.system.php
|
||||
encrypt_key=$(sudo yunohost app setting baikal encrypt_key)
|
||||
sed -i "s@YNH_ENCRYPTKEY@$encrypt_key@g" ../conf/config.system.php
|
||||
# Copy and set nginx configuration
|
||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf
|
||||
sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf
|
||||
sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nginx.conf
|
||||
sudo cp ../conf/nginx.conf "$nginx_conf"
|
||||
|
||||
sudo cp ../conf/config.php $final_path/Specific
|
||||
sudo cp ../conf/config.system.php $final_path/Specific
|
||||
# Copy and set php-fpm configuration
|
||||
#phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
||||
#sed -i "s@#POOLNAME#@${app}@g" ../conf/php-fpm.conf
|
||||
#sed -i "s@#DESTDIR#@${DESTDIR}/@g" ../conf/php-fpm.conf
|
||||
#sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
|
||||
#sudo chown root: $phpfpm_conf
|
||||
#sudo chmod 644 $phpfpm_conf
|
||||
|
||||
sudo chown -R root: $final_path
|
||||
sudo chown -R www-data: $final_path/Specific
|
||||
sudo find $final_path -type f | xargs sudo chmod 644
|
||||
sudo find $final_path -type d | xargs sudo chmod 755
|
||||
# Set SSOwat rules
|
||||
ynh_app_setting_set "$app" skipped_uris "/"
|
||||
ynh_app_setting_set "$app" protected_uris "/admin/"
|
||||
|
||||
# Change variables in Baikal configuration
|
||||
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
||||
sed -i "s@ALIASTOCHANGE@$final_path/html@g" ../conf/nginx.conf
|
||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/baikal.conf
|
||||
sudo chown root: /etc/nginx/conf.d/$domain.d/baikal.conf
|
||||
sudo chmod 600 /etc/nginx/conf.d/$domain.d/baikal.conf
|
||||
|
||||
# Reload Nginx and regenerate SSOwat conf
|
||||
sudo service nginx reload
|
||||
sudo yunohost app setting baikal skipped_uris -v "/"
|
||||
sudo yunohost app ssowatconf
|
||||
|
||||
|
||||
#
|
||||
# # Backuping db
|
||||
# backup_path=/var/cache/yunohost/backups/baikal
|
||||
# final_path=/var/www/baikal/
|
||||
#
|
||||
# mkdir -p $backup_path
|
||||
# sudo cp -a $final_path/Specific/* $backup_path
|
||||
#
|
||||
# # Copy files to the right place
|
||||
# sudo mkdir -p $final_path
|
||||
# sudo cp -a ../sources/* $final_path
|
||||
# sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/baikal.conf
|
||||
# sudo chown -R www-data:www-data $final_path
|
||||
# sudo find $final_path -type d -exec chmod 755 {} \;
|
||||
# sudo touch $final_path/Specific/ENABLE_INSTALL
|
||||
# #sudo chmod 755 $final_path/Specific
|
||||
# #sudo chmod 755 $final_path/Specific/db
|
||||
# #sudo chmod 755 $final_path/Specific/db/db.sqlite
|
||||
#
|
||||
# # Change variables in Baikal configuration
|
||||
# sudo sed -i "s@PATHTOCHANGE@$path@g" /etc/nginx/conf.d/$domain.d/baikal.conf
|
||||
# sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" /etc/nginx/conf.d/$domain.d/baikal.conf
|
||||
#
|
||||
# sudo sed -i "s@PROJECT_BASEURI_@\"$path/\"@g" $final_path/Core/Frameworks/Baikal/Model/Config/System.php
|
||||
#
|
||||
# # Restoring backup
|
||||
# sudo cp -a $backup_path/* $final_path/Specific
|
||||
#
|
||||
# # Reload Nginx and regenerate SSOwat conf
|
||||
# sudo service php5-fpm restart
|
||||
# sudo service nginx reload
|
||||
# sudo yunohost app setting baikal skipped_uris -v "/"
|
||||
# sudo yunohost app ssowatconf
|
||||
# Reload services
|
||||
#sudo service php5-fpm restart || true
|
||||
sudo service nginx reload || true
|
||||
|
|
100
sources/bin/upgrade.sh
Executable file
100
sources/bin/upgrade.sh
Executable file
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2013 Jérôme Schneider <mail@jeromeschneider.fr>
|
||||
* All rights reserved
|
||||
*
|
||||
* http://baikal-server.com
|
||||
*
|
||||
* This script is part of the Baïkal Server project. The Baïkal
|
||||
* Server project is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
ini_set("session.cookie_httponly", 1);
|
||||
ini_set("log_errors", 1);
|
||||
error_reporting(E_WARNING | E_ERROR);
|
||||
|
||||
define("BAIKAL_CONTEXT", true);
|
||||
define("BAIKAL_CONTEXT_INSTALL", true);
|
||||
define("PROJECT_CONTEXT_BASEURI", "/admin/install/");
|
||||
|
||||
define('PROJECT_PATH_ROOT', realpath(__DIR__ . '/..') . '/' );
|
||||
|
||||
if (!file_exists(PROJECT_PATH_ROOT . 'vendor/')) {
|
||||
echo "Baïkal is not completely installed!\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require PROJECT_PATH_ROOT . "vendor/autoload.php";
|
||||
|
||||
# Extend VersionUpgrade for cli usage
|
||||
class CLIUpgrade extends \BaikalAdmin\Controller\Install\VersionUpgrade {
|
||||
|
||||
function run() {
|
||||
$sBaikalVersion = BAIKAL_VERSION;
|
||||
$sBaikalConfiguredVersion = BAIKAL_CONFIGURED_VERSION;
|
||||
|
||||
if (BAIKAL_CONFIGURED_VERSION === BAIKAL_VERSION) {
|
||||
$this->output("Baïkal is already configured for version " . $sBaikalVersion);
|
||||
return true;
|
||||
} else {
|
||||
$this->output("Upgrading Baïkal from version " . $sBaikalConfiguredVersion . " to version " . $sBaikalVersion);
|
||||
}
|
||||
|
||||
try {
|
||||
$bSuccess = $this->upgrade(BAIKAL_CONFIGURED_VERSION, BAIKAL_VERSION);
|
||||
} catch (\Exception $e) {
|
||||
$bSuccess = false;
|
||||
$this->output("Uncaught exception during upgrade: " . (string)$e);
|
||||
}
|
||||
if (!empty($oUpgrade->aErrors)) {
|
||||
$this->output("Some errors occured:\n" . implode("\n - ", $oUpgrade->aErrors));
|
||||
}
|
||||
if (!empty($oUpgrade->aSuccess)) {
|
||||
$this->output(implode("\n", $oUpgrade->aSuccess));
|
||||
}
|
||||
if ($bSuccess === false) {
|
||||
$this->output("Error: unable to upgrade Baïkal.");
|
||||
} else {
|
||||
$this->output("Baïkal has been upgraded!");
|
||||
}
|
||||
|
||||
return $bSuccess;
|
||||
}
|
||||
|
||||
function output($message) {
|
||||
echo $message . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
# Bootstraping Flake
|
||||
\Flake\Framework::bootstrap();
|
||||
|
||||
# Bootstrap BaikalAdmin
|
||||
\BaikalAdmin\Framework::bootstrap();
|
||||
|
||||
if (!defined("BAIKAL_CONFIGURED_VERSION") || !defined("BAIKAL_ADMIN_PASSWORDHASH")) {
|
||||
echo "Baïkal is not properly configured!\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
# Run the upgrade
|
||||
$oUpgrade = new CLIUpgrade();
|
||||
if (!$oUpgrade->run()) {
|
||||
exit(1);
|
||||
}
|
Loading…
Add table
Reference in a new issue