Add 'call-update-php-hack.sh'

This commit adds a hacky script that can manually call update.php.
This commit is contained in:
Tom Wiesing 2021-04-29 13:45:02 +02:00
parent e0dbe5b862
commit f703f9865f
No known key found for this signature in database
GPG key ID: DC1F29F2BC78AB15
4 changed files with 115 additions and 4 deletions

View file

@ -0,0 +1,36 @@
#!/bin/bash
set -e
# read the lib/shared.sh and read the slug argument.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR"
source "$DIR/lib/lib.sh"
require_slug_argument
# if the site doesn't exist, I can't open a shell.
if ! sql_bookkeep_exists "$SLUG"; then
log_error "=> Site '$SLUG' does not exist in bookeeping table. "
echo "I can't rebuild it. "
exit 1
fi;
# Read everything from the database
read -r INSTANCE_BASE_DIR MYSQL_DATABASE MYSQL_USER GRAPHDB_REPO GRAPHDB_USER <<< "$(sql_bookkeep_load "${SLUG}" "filesystem_base,sql_database,sql_user,graphdb_repository,graphdb_user" | tail -n +2)"
# cd into the right directory
cd "$INSTANCE_BASE_DIR"
log_info " => Enabling 'update.php' access"
docker-compose exec barrel bash /utils/settings_php_set.sh update_free_access true
log_info " => Calling update.php"
IP=`docker-compose exec barrel awk 'END{print $1}' /etc/hosts | tr -d '\r'`
URL="http://$IP:8080/update.php/selection"
# TODO: This should really call update.php sensibly
curl -H "Host: $INSTANCE_DOMAIN" $URL
log_info "=> Disabling update.php access"
docker-compose exec barrel bash /utils/settings_php_set.sh update_free_access false

View file

@ -5,7 +5,9 @@
INSTANCE_DOMAIN="$(hostname -f)" INSTANCE_DOMAIN="$(hostname -f)"
INSTANCE_DOMAIN="${INSTANCE_DOMAIN%.wisski}" INSTANCE_DOMAIN="${INSTANCE_DOMAIN%.wisski}"
chmod u+w web/sites/default/settings.php
echo "" >> web/sites/default/settings.php TRUSTED_HOST_PATTERN="${INSTANCE_DOMAIN//\./\\\\.}"
echo "\$settings['trusted_host_patterns'] = ['${INSTANCE_DOMAIN//\./\\\.}'];" >> web/sites/default/settings.php TRUSTED_HOST_PATTERNS='["'$TRUSTED_HOST_PATTERN'"]'
chmod u-w web/sites/default/settings.php
echo "Setting 'trusted_host_patterns' to $TRUSTED_HOST_PATTERNS"
bash /utils/settings_php_set.sh 'trusted_host_patterns' "$TRUSTED_HOST_PATTERNS"

View file

@ -0,0 +1,17 @@
#!/bin/bash
# settings_php_get.sh name
# Gets the 'settings_php_get.php' setting 'name' as json-encoded value, or null when it does not exist.
NAME=$1
if [ -z "$NAME" ]; then
echo "Usage: get_settings_setting.sh NAME"
exit 1
fi;
echo "$NAME" | drush php:eval '
use \Drupal\Core\Site\Settings;
$name=trim(file_get_contents("php://stdin"));
echo json_encode(Settings::get($name));
';

View file

@ -0,0 +1,56 @@
#!/bin/bash
# settings_php_set.sh name value
# Sets the 'settings.php' setting 'name' to 'value'.
# Value must be json-encoded.
NAME=$1
VALUE=$2
if [ -z "$NAME" ]; then
echo "Usage: settings_php_set.sh NAME VALUE"
exit 1
fi;
if [ -z "$VALUE" ]; then
echo "Usage: settings_php_set.sh NAME VALUE"
exit 1
fi;
cd /var/www/data/project
chmod u+w web/sites/default/settings.php
(echo "$NAME"; echo "$VALUE" ) | drush php:eval '
include_once DRUPAL_ROOT . "/core/includes/install.inc";
// read NAME and VALUE from STDIN
$content=file_get_contents("php://stdin");
$newline=strpos($content, "\n");
$name=trim(substr($content, 0, $newline));
$jvalue=trim(substr($content, $newline + 1));
// decode json values
$value = @json_decode($jvalue);
if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
echo "Invalid JSON, cannot update settings.php. \n";
return 1;
}
// make parameters to drush_rewrite_settings
$settings["settings"][$name] = (object)[
"value" => $value,
"required" => TRUE,
];
// find the actual settings.php file to rewrite
$filename = DRUPAL_ROOT . "/" . \Drupal::service("site.path") . "/settings.php";
drupal_rewrite_settings($settings, $filename);
echo "Wrote " . $filename . "\n";
return 0;
';
EXIT=$?
chmod u-w web/sites/default/settings.php
exit $?