|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +#ddev-generated |
| 4 | +# If you want to take over this file and customize it, remove the line above |
| 5 | +# and ddev will respect it and won't overwrite the file. |
| 6 | + |
| 7 | +# Function to get the lowest supported TYPO3 version from the environment variable TYPO3_VERSIONS |
| 8 | +# It reads the TYPO3_VERSIONS environment variable, splits it into an array, and sorts the versions. |
| 9 | +# If no versions are found, it prints an error message and exits with status 1. |
| 10 | +# Otherwise, it prints the lowest version. |
| 11 | +function get_lowest_supported_typo3_versions() { |
| 12 | + local TYPO3_VERSIONS_ARRAY=() |
| 13 | + IFS=' ' read -r -a TYPO3_VERSIONS_ARRAY <<< "$TYPO3_VERSIONS" |
| 14 | + if [ ${#TYPO3_VERSIONS_ARRAY[@]} -eq 0 ]; then |
| 15 | + message red "Error! No supported TYPO3 versions found in environment variables." |
| 16 | + exit 1 |
| 17 | + fi |
| 18 | + printf "%s\n" "${TYPO3_VERSIONS_ARRAY[@]}" | sort -V | head -n 1 |
| 19 | +} |
| 20 | + |
| 21 | +# Function to get the supported TYPO3 versions from the environment variable TYPO3_VERSIONS. |
| 22 | +# It checks if the TYPO3_VERSIONS environment variable is set and not empty. |
| 23 | +# If the variable is unset or empty, it prints an error message and returns 1. |
| 24 | +# Otherwise, it splits the TYPO3_VERSIONS variable into an array and prints the supported versions. |
| 25 | +function get_supported_typo3_versions() { |
| 26 | + if [ -z "${TYPO3_VERSIONS+x}" ]; then |
| 27 | + message red "TYPO3_VERSIONS is unset. Please set it before running this function." |
| 28 | + return 1 |
| 29 | + else |
| 30 | + local TYPO3_VERSIONS_ARRAY=() |
| 31 | + IFS=' ' read -r -a TYPO3_VERSIONS_ARRAY <<< "$TYPO3_VERSIONS" |
| 32 | + if [ ${#TYPO3_VERSIONS_ARRAY[@]} -eq 0 ]; then |
| 33 | + message red "Error! No supported TYPO3 versions found in environment variables." |
| 34 | + return 1 |
| 35 | + fi |
| 36 | + printf "%s\n" "${TYPO3_VERSIONS_ARRAY[@]}" |
| 37 | + fi |
| 38 | +} |
| 39 | + |
| 40 | +# Function to check if a given TYPO3 version is supported. |
| 41 | +# It takes one argument, the TYPO3 version to check. |
| 42 | +# The function reads the supported TYPO3 versions from the environment variable TYPO3_VERSIONS. |
| 43 | +# If the provided version is not in the list of supported versions, it prints an error message and exits with status 1. |
| 44 | +# If the provided version is supported, it returns 0. |
| 45 | +# |
| 46 | +# Arguments: |
| 47 | +# $1 - The TYPO3 version to check. |
| 48 | +# |
| 49 | +# Returns: |
| 50 | +# 0 if the provided TYPO3 version is supported. |
| 51 | +# 1 if the provided TYPO3 version is not supported or if no version is provided. |
| 52 | +function check_typo3_version() { |
| 53 | + local TYPO3=$1 |
| 54 | + local SUPPORTED_TYPO3_VERSIONS=() |
| 55 | + local found=0 |
| 56 | + |
| 57 | + if [ -z "$TYPO3" ]; then |
| 58 | + message red "No TYPO3 version provided. Please set one of the supported TYPO3 versions as argument: $(get_supported_typo3_versions_comma_separated)" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + |
| 62 | + while IFS= read -r line; do |
| 63 | + SUPPORTED_TYPO3_VERSIONS+=("$line") |
| 64 | + done < <(get_supported_typo3_versions) |
| 65 | + |
| 66 | + for version in "${SUPPORTED_TYPO3_VERSIONS[@]}"; do |
| 67 | + if [[ "$version" == "$TYPO3" ]]; then |
| 68 | + found=1 |
| 69 | + break |
| 70 | + fi |
| 71 | + done |
| 72 | + |
| 73 | + if [[ $found -eq 0 ]]; then |
| 74 | + message red "TYPO3 version '$TYPO3' is not supported." |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + |
| 78 | + return 0 |
| 79 | +} |
| 80 | + |
| 81 | +# Function to perform pre-setup tasks for TYPO3 installation. |
| 82 | +# It exports the provided TYPO3 version to the VERSION environment variable, |
| 83 | +# displays an introductory message for the TYPO3 version, and starts the installation process. |
| 84 | +# |
| 85 | +# Arguments: |
| 86 | +# $1 - The TYPO3 version to set up. |
| 87 | +# |
| 88 | +# Usage: |
| 89 | +# pre_setup <TYPO3_VERSION> |
| 90 | +function pre_setup() { |
| 91 | + export VERSION=$1 |
| 92 | + export BASE_PATH="/var/www/html/.Build/$VERSION" |
| 93 | + intro_typo3 |
| 94 | + message blue "Pre Setup for TYPO3 $VERSION" |
| 95 | + install_start |
| 96 | + message blue "Install Composer Packages" |
| 97 | +} |
| 98 | + |
| 99 | +# Function to perform post-setup tasks for TYPO3 installation. |
| 100 | +# It changes the current directory to the base path, sets the TYPO3 installation database name, |
| 101 | +# and calls the appropriate post-setup function based on the TYPO3 version. |
| 102 | +# After that, it imports data and updates TYPO3. |
| 103 | +function post_setup() { |
| 104 | + message blue "Post Setup for TYPO3 $VERSION" |
| 105 | + cd $BASE_PATH |
| 106 | + TYPO3_INSTALL_DB_DBNAME=$DATABASE |
| 107 | + |
| 108 | + if [ "$VERSION" == "11" ]; then |
| 109 | + post_setup_11 |
| 110 | + elif [ "$VERSION" == "12" ]; then |
| 111 | + post_setup_12 |
| 112 | + elif [ "$VERSION" == "13" ]; then |
| 113 | + post_setup_13 |
| 114 | + fi |
| 115 | + |
| 116 | + import_data |
| 117 | + update_typo3 |
| 118 | +} |
| 119 | + |
| 120 | +# Function to display an introductory message for the TYPO3 version. |
| 121 | +# It prints a formatted message with the TYPO3 version in magenta color. |
| 122 | +function intro_typo3() { |
| 123 | + message magenta "-------------------------------------------------" |
| 124 | + message magenta "|\t\t\t\t\t\t|" |
| 125 | + message magenta "| \t\t TYPO3 $VERSION \t\t|" |
| 126 | + message magenta "|\t\t\t\t\t\t|" |
| 127 | + message magenta "-------------------------------------------------" |
| 128 | +} |
| 129 | + |
| 130 | +# Function to start the installation process for TYPO3. |
| 131 | +# It removes any existing files in the test directory for the specified version, |
| 132 | +# sets up the environment, creates symlinks for the main and additional extensions, |
| 133 | +# and sets up Composer for the TYPO3 installation. |
| 134 | +function install_start() { |
| 135 | + rm -rf /var/www/html/.Build/$VERSION/* |
| 136 | + setup_environment |
| 137 | + create_symlinks_main_extension |
| 138 | + create_symlinks_additional_extensions |
| 139 | + setup_composer |
| 140 | +} |
| 141 | + |
| 142 | +# Function to set up the environment for TYPO3 installation. |
| 143 | +# It sets the base path for the TYPO3 installation, removes any existing files in the base path, |
| 144 | +# creates necessary directories, sets permissions, and exports environment variables. |
| 145 | +# Additionally, it drops the existing database for the TYPO3 version. |
| 146 | +function setup_environment() { |
| 147 | + rm -rf "$BASE_PATH" |
| 148 | + mkdir -p "$BASE_PATH/packages/$EXTENSION_KEY" |
| 149 | + chmod 775 -R $BASE_PATH |
| 150 | + export DATABASE="database_$VERSION" |
| 151 | + if [ "$VERSION" == "11" ]; then |
| 152 | + export TYPO3_BIN="$BASE_PATH/vendor/bin/typo3cms" |
| 153 | + else |
| 154 | + export TYPO3_BIN="$BASE_PATH/vendor/bin/typo3" |
| 155 | + fi |
| 156 | + mysql -uroot -proot -e "DROP DATABASE IF EXISTS $DATABASE" |
| 157 | +} |
| 158 | + |
| 159 | +# Function to create symlinks for the main extension. |
| 160 | +# It iterates over the items in the current directory, excluding certain directories and files, |
| 161 | +# and creates symbolic links for the remaining items in the specified base path. |
| 162 | +function create_symlinks_main_extension() { |
| 163 | + local EXCLUSIONS_ARRAY=() |
| 164 | + IFS=' ' read -r -a EXCLUSIONS_ARRAY <<< "$EXCLUSIONS" |
| 165 | + for item in ./*; do |
| 166 | + local base_name=$(basename "$item") |
| 167 | + for exclusion in "${EXCLUSIONS_ARRAY[@]}"; do |
| 168 | + if [[ $base_name == "$exclusion" ]]; then |
| 169 | + continue 2 |
| 170 | + fi |
| 171 | + done |
| 172 | + ln -sr "$item" "$BASE_PATH/packages/$EXTENSION_KEY/$base_name" |
| 173 | + done |
| 174 | +} |
| 175 | + |
| 176 | +# Function to create symlinks for additional extensions. |
| 177 | +# It iterates over the directories in the specified path and creates symbolic links |
| 178 | +# for each directory in the base path. |
| 179 | +function create_symlinks_additional_extensions() { |
| 180 | + for dir in Tests/.typo3-setup/packages/*/; do |
| 181 | + ln -sr "$dir" "$BASE_PATH/packages/$(basename "$dir")" |
| 182 | + done |
| 183 | +} |
| 184 | + |
| 185 | +# Function to set up Composer for TYPO3 installation. |
| 186 | +# It initializes a new Composer project in the specified base path, |
| 187 | +# configures the TYPO3 web directory, sets up the repository for packages, |
| 188 | +# and allows necessary Composer plugins. |
| 189 | +function setup_composer() { |
| 190 | + composer init --name="xima/typo3-$VERSION" --description="TYPO3 $VERSION" --no-interaction --working-dir "$BASE_PATH" |
| 191 | + composer config extra.typo3/cms.web-dir public --working-dir "$BASE_PATH" |
| 192 | + composer config repositories.packages path 'packages/*' --working-dir "$BASE_PATH" |
| 193 | + composer config --no-interaction allow-plugins.typo3/cms-composer-installers true --working-dir "$BASE_PATH" |
| 194 | + composer config --no-interaction allow-plugins.typo3/class-alias-loader true --working-dir "$BASE_PATH" |
| 195 | +} |
| 196 | + |
| 197 | +# Function to set up TYPO3 configuration. |
| 198 | +# It changes the current directory to the base path, sets the TYPO3 installation database name, |
| 199 | +# and configures various TYPO3 settings such as debug mode, error display, trusted hosts pattern, |
| 200 | +# mail transport, and graphics processor. |
| 201 | +function setup_typo3() { |
| 202 | + cd $BASE_PATH |
| 203 | + export TYPO3_INSTALL_DB_DBNAME=$DATABASE |
| 204 | + $TYPO3_BIN configuration:set 'BE/debug' 1 |
| 205 | + $TYPO3_BIN configuration:set 'FE/debug' 1 |
| 206 | + $TYPO3_BIN configuration:set 'SYS/devIPmask' '*' |
| 207 | + $TYPO3_BIN configuration:set 'SYS/displayErrors' 1 |
| 208 | + $TYPO3_BIN configuration:set 'SYS/trustedHostsPattern' '.*.*' |
| 209 | + $TYPO3_BIN configuration:set 'MAIL/transport' 'smtp' |
| 210 | + $TYPO3_BIN configuration:set 'MAIL/transport_smtp_server' 'localhost:1025' |
| 211 | + $TYPO3_BIN configuration:set 'GFX/processor' 'ImageMagick' |
| 212 | + $TYPO3_BIN configuration:set 'GFX/processor_path' '/usr/bin/' |
| 213 | +} |
| 214 | + |
| 215 | +# Function to update TYPO3. |
| 216 | +# It updates the TYPO3 database schema and flushes the cache. |
| 217 | +function update_typo3() { |
| 218 | + $TYPO3_BIN database:updateschema |
| 219 | + $TYPO3_BIN cache:flush |
| 220 | +} |
| 221 | + |
| 222 | +# Function to import data into TYPO3. |
| 223 | +# It sets the public directory and export directory paths, checks if the data file exists, |
| 224 | +# and if it does, it copies the data file to the export directory and imports the data using TYPO3's import/export tool. |
| 225 | +function import_data() { |
| 226 | + PUBLIC_DIR="/var/www/html/.Build/${VERSION}/public" |
| 227 | + EXPORT_DIR="${PUBLIC_DIR}/fileadmin/user_upload/_temp_/importexport" |
| 228 | + DATA_FILE="/var/www/html/Tests/.typo3-setup/data/data.xml" |
| 229 | + |
| 230 | + if [ ! -f "$DATA_FILE" ]; then |
| 231 | + message yellow "Data file $DATA_FILE not found. Skipping import." |
| 232 | + return |
| 233 | + fi |
| 234 | + |
| 235 | + mkdir -p $EXPORT_DIR |
| 236 | + cp /$DATA_FILE $EXPORT_DIR |
| 237 | + $TYPO3_BIN impexp:import -vvv --force-uid "$EXPORT_DIR/data.xml" |
| 238 | +} |
| 239 | + |
| 240 | +# Function to perform post-setup tasks for TYPO3 version 11. |
| 241 | +# It sets up TYPO3 by running the installation setup, configuring TYPO3 settings, |
| 242 | +# and modifying configuration files to enable deprecations and adjust base paths. |
| 243 | +function post_setup_11 { |
| 244 | + $TYPO3_BIN install:setup -n --database-name $DATABASE |
| 245 | + setup_typo3 |
| 246 | + $TYPO3_BIN configuration:set 'GFX/processor_path_lzw' '/usr/bin/' |
| 247 | + |
| 248 | + sed -i "/'deprecations'/,/^[[:space:]]*'disabled' => true,/s/'disabled' => true,/'disabled' => false,/" /var/www/html/.Build/$VERSION/public/typo3conf/LocalConfiguration.php |
| 249 | + |
| 250 | + sed -i -e "s/base: ht\//base: \//g" /var/www/html/.Build/$VERSION/config/sites/main/config.yaml |
| 251 | + sed -i -e 's/base: \/en\//base: \//g' /var/www/html/.Build/$VERSION/config/sites/main/config.yaml |
| 252 | +} |
| 253 | + |
| 254 | +# Function to perform post-setup tasks for TYPO3 version 12. |
| 255 | +# It sets up TYPO3 by running the installation setup, configuring TYPO3 settings, |
| 256 | +# and modifying configuration files to enable deprecations and adjust base paths. |
| 257 | +function post_setup_12 { |
| 258 | + $TYPO3_BIN install:setup -n --database-name $DATABASE |
| 259 | + setup_typo3 |
| 260 | + |
| 261 | + sed -i "/'deprecations'/,/^[[:space:]]*'disabled' => true,/s/'disabled' => true,/'disabled' => false,/" /var/www/html/.Build/$VERSION/config/system/settings.php |
| 262 | + |
| 263 | + sed -i -e "s/base: ht\//base: \//g" /var/www/html/.Build/$VERSION/config/sites/main/config.yaml |
| 264 | + sed -i -e 's/base: \/en\//base: \//g' /var/www/html/.Build/$VERSION/config/sites/main/config.yaml |
| 265 | +} |
| 266 | + |
| 267 | +# Function to perform post-setup tasks for TYPO3 version 13. |
| 268 | +# It creates the TYPO3 database, sets up TYPO3 by running the installation setup, |
| 269 | +# configures TYPO3 settings, and modifies configuration files to enable deprecations. |
| 270 | +function post_setup_13 { |
| 271 | + mysql -h db -u root -p"root" -e "CREATE DATABASE $DATABASE;" |
| 272 | + $TYPO3_BIN setup -n --dbname=$DATABASE --password=$TYPO3_DB_PASSWORD --create-site="https://${VERSION}.${EXTENSION_NAME}.ddev.site" --admin-user-password=$TYPO3_SETUP_ADMIN_PASSWORD |
| 273 | + setup_typo3 |
| 274 | + |
| 275 | + sed -i "/'deprecations'/,/^[[:space:]]*'disabled' => true,/s/'disabled' => true,/'disabled' => false,/" /var/www/html/.Build/$VERSION/config/system/settings.php |
| 276 | +} |
| 277 | + |
| 278 | +# Function to display a colored message. |
| 279 | +# It takes two arguments: the color and the message to display. |
| 280 | +# The function supports the following colors: red, green, yellow, blue, magenta, cyan. |
| 281 | +# If an unsupported color is provided, the message is displayed without color. |
| 282 | +# |
| 283 | +# Usage: |
| 284 | +# message <color> <message> |
| 285 | +# |
| 286 | +# Arguments: |
| 287 | +# color - The color to use for the message (red, green, yellow, blue, magenta, cyan). |
| 288 | +# message - The message to display. |
| 289 | +message() { |
| 290 | + local color=$1 |
| 291 | + local message=$2 |
| 292 | + |
| 293 | + case $color in |
| 294 | + red) |
| 295 | + echo -e "\033[31m$message\033[0m" |
| 296 | + ;; |
| 297 | + green) |
| 298 | + echo -e "\033[32m$message\033[0m" |
| 299 | + ;; |
| 300 | + yellow) |
| 301 | + echo -e "\033[33m$message\033[0m" |
| 302 | + ;; |
| 303 | + blue) |
| 304 | + echo -e "\033[34m$message\033[0m" |
| 305 | + ;; |
| 306 | + magenta) |
| 307 | + echo -e "\033[35m$message\033[0m" |
| 308 | + ;; |
| 309 | + cyan) |
| 310 | + echo -e "\033[36m$message\033[0m" |
| 311 | + ;; |
| 312 | + *) |
| 313 | + echo -e "$message" |
| 314 | + ;; |
| 315 | + esac |
| 316 | +} |
0 commit comments