[go: up one dir, main page]

Skip to content

Instantly share code, notes, and snippets.

@ErHaWeb
Last active September 5, 2024 20:10
Show Gist options
  • Save ErHaWeb/961dc1029ce05cee49825f4600219573 to your computer and use it in GitHub Desktop.
Save ErHaWeb/961dc1029ce05cee49825f4600219573 to your computer and use it in GitHub Desktop.
TYPO3 Auto-Installation

TYPO3 Auto-Installation

Since I need a TYPO3 test environment from time to time, I use these bash scripts for the automatic installation and removal of TYPO3. The installation script currently supports TYPO3 versions 10, 11, 12, 13 and dev.

Installation

I have stored the scripts under:

~/.shellscripts/typo3/

I use the following aliases:

alias install-typo3="bash ~/.shellscripts/typo3/install.sh"
alias remove-typo3="bash ~/.shellscripts/typo3/remove.sh"

Requirements

Since the installation script set up a local development environment based on Docker and DDEV, you must ensure that DDEV is installed and working correctly on your machine before running it. For help with installing DDEV, please see the official DDEV documentation.

Usage

The installation script can be called with a version number as the first parameter, which can be "10", "11", "12", "13" or "dev" (for the latest dev version), and any number of string parameters. Each string parameter after the version number is used as the DDEV project name and directory name of the TYPO3 instance.

Example:

install-typo3 12 domain1.com domain2.com domain3.com

This command creates three TYPO3 12 projects in the directories domain1.com/, domain2.com/ and domain3.com/.

If no directory names are specified, the name typo3-<version>-project is used. If no version number is specified, the latest version 13 will be installed in directory typo3-13-project.

What it does

  • The DDEV plugin DDEV-CRON automatically creates a cronjob that runs the TYPO3 scheduler every minute.
  • phpMyAdmin is also installed via DDEV plugin and can be called via ddev phpmyadmin.
  • Furthermore a packages/ directory is created and stored in the composer.json as local repository path.
  • Inside packages/ my sitepackage basic structure is cloned and changed to the branch matching the TYPO3 version.
  • With the installation of the sitepackage a root site is created with references to the Page TSconfig and TypoScript of the sitepackage, so you can start directly.

Backend-Login

With the following credentials you can log in to the backend:

Username: admin
Password: Password1%

Showcase on YouTube

I have recorded the installation process of all versions as a YouTube-video here:

Uninstall

If you don't need the TYPO3 test-installation anymore you can change to the directory of the installation and execute remove-typo3 (see alias above). This will A) delete the DDEV project and B) delete the whole directory (with sudo).

Disclaimer

Please note that the execution of these scripts is at your own risk and I assume no liability for anything. For this reason you should make sure that you have understood which steps are executed by the script.

#!/bin/bash
## INSTALLATION:
## -----------------
## Create a new alias in your Bash/ZSH startup file
## For Bash the startup file can be found here "~/.bashrc"
## and for ZSH it can be found here "~/.zshrc".
## Now copy this script to a local directory, e.g. under:
##
## ~/.shellscripts/typo3/install.sh
##
## and add the following alias to your startup file:
##
## alias install-typo3="bash ~/.shellscripts/typo3/install.sh"
##
##
## USAGE
## -----------------
## Call the script with one of the version numbers "10", "11", "12", "13" or
## "dev" (for the latest dev version) and any number of following parameters,
## each of which stands for the installation directory name in which typo3 is
## to be installed.
##
## If no directory names are specified, the name typo3-<version>-project
## is used. If no version number is specified, the latest version 13 will
## be installed.
##
## Example for version 12 in directories "first-project" and "second-project":
## install-typo3 12 first-project second-project
##
##
## BACKEND LOGIN:
## -----------------
## Login-URL: https://directory.ddev.site/typo3/
## Username: admin
## Password: Password1%
##
## © 2024 Eric Harrer
##
set -Eeuo pipefail
# ANSI color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Function to execute TYPO3 installation with version check and directory preparation
execute_typo3_installation() {
local version=$1
local directories=("${@:2}") # Capture all arguments after the first one as directory names
# Verify if the version is supported before proceeding
if ! [[ $version =~ ^(10|11|12|13|dev)$ ]]; then
printf "\n--- %bThe specified TYPO3 version is not supported: %s%b\n" "$RED" "$version" "$NC"
printf "\n--- Supported versions are %b10, 11, 12, 13, dev%b.\n" "$GREEN" "$NC"
return 1
fi
# Default to a directory name based on the version if none specified
if [ ${#directories[@]} -eq 0 ]; then
directories=("typo3-${version}-project")
fi
# Run the installation process for each directory
for dir in "${directories[@]}"; do
if [ -d "$dir" ] && [ "$(ls -A "$dir")" ]; then
printf "\n--- %bError: The directory %s exists and is not empty. Aborting installation to prevent data loss.%b\n" "$RED" "$dir" "$NC"
return 1 # Abort execution to prevent overwriting existing data
fi
if [ ! -d "$dir" ]; then
printf "\n--- Creating directory: %b%s%b\n" "$GREEN" "$dir" "$NC"
mkdir -p "$dir" || exit # Exits the script if mkdir fails
else
printf "\n--- Directory %b%s%b exists but is empty. Continuing installation...\n" "$GREEN" "$dir" "$NC"
fi
printf "\n--- Changing to directory: %b%s%b\n" "$GREEN" "$dir" "$NC"
cd "$dir" || return # Returns if cd fails
# Determine PHP version based on TYPO3 version
local php_version="8.3"
[ "$version" = "10" ] && php_version="7.4"
printf "\n--- Executing general installation steps for TYPO3 version %b%s%b in directory %b%s%b...\n" "$GREEN" "$version" "$NC" "$GREEN" "$dir" "$NC"
ddev config \
--project-type=typo3 \
--docroot=public \
--php-version=$php_version \
--webserver-type=apache-fpm \
--xdebug-enabled=false \
--database=mariadb:10.11 \
--performance-mode=mutagen \
--webimage-extra-packages=graphicsmagick \
--use-dns-when-possible=true \
--timezone=Europe/Berlin \
--composer-version=2 \
--web-environment=TYPO3_CONTEXT=Development
printf "\n--- Install cronjob add-on (https://github.com/drud/ddev-cron)\n"
ddev get drud/ddev-cron
printf "\n--- Update cron configuration to execute scheduler every minute\n"
printf '* * * * * IS_DDEV_PROJECT=true /var/www/html/vendor/bin/typo3 scheduler:run -vv\n' >.ddev/web-build/typo3-scheduler.cron
printf "\n--- Install phpMyAdmin add-on (https://github.com/ddev/ddev-phpmyadmin)\n"
ddev get ddev/ddev-phpmyadmin
printf "\n--- Start environment\n"
ddev start -y
printf "\n--- Init composer\n"
ddev composer init \
--name="erhaweb/typo3-$version-autoinstallation" \
--description="TYPO3 $version Auto-Installation" \
--author="Eric Harrer <info@eric-harrer.de>" \
--type="project" \
--homepage="https://www.eric-harrer.de" \
--stability="stable" \
--license="GPL-2.0-or-later" \
--repository='{"type":"path","url":"packages/*"}' \
--quiet
printf "\n--- Allow plugin typo3/class-alias-loader\n"
ddev composer config --no-interaction allow-plugins.typo3/class-alias-loader true
printf "\n--- Allow plugin typo3/cms-composer-installers\n"
ddev composer config --no-interaction allow-plugins.typo3/cms-composer-installers true
printf "\n--- Add further default composer settings\n"
ddev composer config --no-interaction platform.php "$php_version"
ddev composer config --no-interaction sort-packages true
local sitepackage_branch="$version"
[ "$version" = "dev" ] && sitepackage_branch="main"
printf "\n--- Download sitepackage base structure\n"
ddev exec git clone --branch "$sitepackage_branch" https://github.com/ErHaWeb/sitepackage.git "packages/sitepackage/"
local typo3_branch=""
case $version in
10) typo3_branch="10.4" ;;
11) typo3_branch="11.5" ;;
12) typo3_branch="12.4" ;;
13) typo3_branch="13.1" ;;
*) typo3_branch="main" ;;
esac
printf "\n--- Download .editorconfig file from TYPO3 repository branch %b$typo3_branch%b\n" "$GREEN" "$NC"
ddev exec wget "https://raw.githubusercontent.com/TYPO3/typo3/$typo3_branch/.editorconfig"
local package_version=""
case $version in
10) package_version="^10.4" ;;
11) package_version="^11.5" ;;
12) package_version="^12.4" ;;
13) package_version="^13.1" ;;
*) package_version="dev-main" ;;
esac
printf "\n--- Add general TYPO3 core packages for version %b$version%b and sitepackage\n" "$GREEN" "$NC"
ddev composer require --no-install \
"typo3/cms-adminpanel:$package_version" \
"typo3/cms-backend:$package_version" \
"typo3/cms-belog:$package_version" \
"typo3/cms-beuser:$package_version" \
"typo3/cms-core:$package_version" \
"typo3/cms-dashboard:$package_version" \
"typo3/cms-extbase:$package_version" \
"typo3/cms-extensionmanager:$package_version" \
"typo3/cms-felogin:$package_version" \
"typo3/cms-filelist:$package_version" \
"typo3/cms-filemetadata:$package_version" \
"typo3/cms-fluid:$package_version" \
"typo3/cms-fluid-styled-content:$package_version" \
"typo3/cms-form:$package_version" \
"typo3/cms-frontend:$package_version" \
"typo3/cms-impexp:$package_version" \
"typo3/cms-indexed-search:$package_version" \
"typo3/cms-info:$package_version" \
"typo3/cms-install:$package_version" \
"typo3/cms-linkvalidator:$package_version" \
"typo3/cms-lowlevel:$package_version" \
"typo3/cms-opendocs:$package_version" \
"typo3/cms-recycler:$package_version" \
"typo3/cms-redirects:$package_version" \
"typo3/cms-reports:$package_version" \
"typo3/cms-rte-ckeditor:$package_version" \
"typo3/cms-scheduler:$package_version" \
"typo3/cms-seo:$package_version" \
"typo3/cms-setup:$package_version" \
"typo3/cms-sys-note:$package_version" \
"typo3/cms-tstemplate:$package_version" \
"typo3/cms-viewpage:$package_version" \
"typo3/cms-workspaces:$package_version" \
"vendorname/sitepackage:@dev"
printf "\n--- Add version specific TYPO3 core packages for version %b$version%b\n" "$GREEN" "$NC"
case $version in
10)
ddev composer require --no-install \
"typo3/cms-t3editor:$package_version" \
"typo3/cms-recordlist:$package_version" \
"typo3/cms-about:$package_version" \
"helhum/typo3-console:^6.7"
;;
11)
ddev composer require --no-install \
"typo3/cms-t3editor:$package_version" \
"typo3/cms-recordlist:$package_version" \
"typo3/cms-composer-installers:4.0.x@dev" \
"helhum/typo3-console:^8.0"
;;
12)
ddev composer require --no-install \
"typo3/cms-t3editor:$package_version" \
"typo3/cms-reactions:$package_version" \
"typo3/cms-webhooks:$package_version"
;;
*)
ddev composer require --no-install \
"typo3/cms-reactions:$package_version" \
"typo3/cms-webhooks:$package_version"
;;
esac
printf "\n--- Install all packages\n"
ddev composer update
local additional_path=""
case "$version" in
10 | 11) additional_path="public/typo3conf/AdditionalConfiguration.php" ;;
*) additional_path="config/system/additional.php" ;;
esac
printf "\n--- Rerun ddev config to create \"%s\"\n" "$additional_path"
ddev config --auto
local typo3_command="typo3"
[[ $version == 10 ]] && typo3_command="typo3cms"
printf "\n--- Run through TYPO3 installation process and take current directory name \"%s\" as site name\n" "${PWD##*/}"
case $version in
10 | 11)
ddev $typo3_command install:setup \
--use-existing-database \
--database-driver="mysqli" \
--database-host-name="db" \
--database-port="3306" \
--database-socket="" \
--database-name="db" \
--database-user-name="db" \
--database-user-password="db" \
--admin-user-name="admin" \
--admin-password="Password1%" \
--site-name="${PWD##*/}" \
--site-setup-type="no" \
--site-base-url="/" \
--web-server-config="apache" \
--force \
--no-interaction
;;
*)
# Tip: You may want to add the option --create-site="https://${PWD##*/}.ddev.site/"
# to create a site configuration independently of the initialization of my site package
ddev $typo3_command setup \
--driver="mysqli" \
--host="db" \
--port=3306 \
--dbname="db" \
--username="db" \
--password="db" \
--admin-username="admin" \
--admin-user-password="Password1%" \
--admin-email="info@eric-harrer.de" \
--project-name="${PWD##*/}" \
--server-type="apache" \
--force \
--no-interaction
;;
esac
local extension_setup_param=""
[[ $version == 10 ]] && extension_setup_param="sitepackage"
printf "\n--- Run typo3 extension:setup to initialise pre-configured sitepackage data\n"
ddev $typo3_command extension:setup $extension_setup_param
printf "\n--- Flush TYPO3 Cache\n"
ddev $typo3_command cache:flush
printf "\n--- TYPO3 Backend-Login:\nUsername: admin\nPassword: Password1%s\n" "%"
printf "\n--- Launch environment in browser\n"
ddev launch
cd - >/dev/null || return # Returns if cd fails
done
}
# Main script logic to handle arguments
if [ $# -eq 0 ]; then
execute_typo3_installation 13
elif [ $# -eq 1 ] && [[ $1 =~ ^[0-9]+$ ]]; then
execute_typo3_installation "$1"
else
execute_typo3_installation "$@"
fi
#!/bin/bash
## WHAT IT DOES:
## -----------------
## It is responsible for deleting an instance completely.
## Both the DDEV project and the base directory are removed.
## Don't worry, you will be warned and asked if you really
## want to run the removal when you run the script.
##
##
## INSTALLATION:
## -----------------
## Create a new alias in your Bash/ZSH startup file
## For Bash the startup file can be found here "~/.bashrc"
## and for ZSH it can be found here "~/.zshrc".
## Now copy this script to a local directory, e.g. under:
##
## ~/.shellscripts/typo3/remove.sh
##
## and add the following alias to your startup file:
##
## alias remove-typo3="bash ~/.shellscripts/typo3/remove.sh"
##
##
## USAGE:
## -----------------
## Go to the base directory of the project you want to
## remove and call the bash script as follows:
##
## cd directory.tld
## remove-typo3
##
## © 2024 Eric Harrer
##
set -Eeuo pipefail
current_dir=${PWD}
parent_dir=$(dirname "$current_dir")
project=${PWD##*/}
read -p "Remove DDEV project \"${project}\" (if exists) and directory \"${current_dir}\"? [y]es or [n]o (default) " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
printf "\n\n--- Delete DDEV project \"%s\"\n" "${project}"
ddev delete "${project}" --omit-snapshot -y
printf "\n--- Remove directory \"%s\"\n" "${current_dir}"
# Attention! Be careful with the following line.
# Do not execute this command in the wrong directory!
# On macOS, run `mv filename ~/.trash/` instead to move to the trash only
sudo rm -R -f "${current_dir}"
printf "\n--- change to parent directory \"%s\"\n" "${parent_dir}"
cd "${parent_dir}" || exit
else
printf "\n--- Deletion of project \"%s\" was aborted\n" "${project}"
fi
@Riiiad
Copy link
Riiiad commented Feb 14, 2024

This is great. Thank you for the updates @ErHaWeb

@ErHaWeb
Copy link
Author
ErHaWeb commented Feb 14, 2024

@Riiiad You're welcome, I'm glad you like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment