Skip to content

Instantly share code, notes, and snippets.

@jonaseberle
Last active October 11, 2018 15:23
Show Gist options
  • Save jonaseberle/720236bc2d2f1127f1103b5e4748298e to your computer and use it in GitHub Desktop.
Save jonaseberle/720236bc2d2f1127f1103b5e4748298e to your computer and use it in GitHub Desktop.
Helps managing/upgrading several Typo3 sources for upgrading/development. Downloads the version(s) you want to the current directory. Sets up symlinks so that e.g. typo3_src-9 will point to the newest version 9.x.x, typo3_src-9.5 to the newest version 9.5.x etc.; try "./getTypo 3.8 4.7 6.2 7 8 9 current" to see it do its job; will ask for deleti…
#!/bin/bash
# @author jonas.eberle@aero.de
# Helps managing/upgrading several Typo3 sources for upgrading/development.
# Downloads the version(s) you request to the current directory.
# Sets up symlinks so that e.g. typo3_src-9 will point to the newest version 9.x.x, typo3_src-9.5 to the newest version 9.5.x etc.
# Try "./getTypo 3.8 4.7 6.2 7 8 9 current" to see it do its job.
# Will ask for deletion if it finds outdated versions.
#
# @params Call without parameters to see usage help
# @exit 127 on wrong usage, 1 on error, 3 on unexpected redirect, 0 on success
[ -z "$1" ] \
&& echo "Will download TYPO3 into current directory and create Symlinks to major- and minor version in current directory." \
&& echo "Usage: $0 ‹TYPO3 version, e.g. current, 6.2, 7, 8, ... see https://get.typo3.org› [‹TYPO3 version› [‹TYPO3 version›] ...]" \
&& exit 127
while [ ! -z "$1" ]; do
version="$1"
echo "Requesting version ‹$version›…"
# checking what we would download
uri="$(wget --quiet --spider -S http://get.typo3.org/"$version" 2>&1 | sed -rn 's/^\s*Location: (.*)/\1/p')"
[ -z "$uri" ] \
&& echo "Version ‹$version› not found at 'https://get.typo3.org/$version'" \
&& exit 1
if ! echo "$uri" | grep "$version[^/]*\.tar\.gz$" > /dev/null; then
# that does not look like what we requested
echo "Redirected to ‹$uri›."
read -p "Continue [y/N]? " -n 1 -r; echo
[[ ! $REPLY =~ ^[Yy]$ ]] \
&& exit 3
fi
lastFilePath="$(wget --show-progress --quiet -O - https://get.typo3.org/"$version" | tar xvzf - 2>/dev/null | tail -n1)"
# get the root path
downloadPath=$(dirname "${lastFilePath}" | sed 's#/.*##')
echo "Received ‹$downloadPath›."
_OLDIFS=$IFS
IFS=. _vParts=( ${downloadPath} )
IFS=$_OLDIFS
symlinkPath=""
for _vPart in ${_vParts[@]:0:2}; do
[ -z "$symlinkPath" ] \
&& symlinkPath="$_vPart" \
|| symlinkPath="$symlinkPath.$_vPart"
# find matching Typo3 dir for this symlink
# simple: sort -V, but needs newer sort version. This variant does not rely on -V
typo3Path=$(find -maxdepth 1 -type d -name "${symlinkPath}*" | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | tail -n 1)
# set symlink
printf "linking $symlinkPath\t-› $typo3Path\n"
ln -sfn "$typo3Path" "$symlinkPath"
done
echo
for _unlinkedDir in $( { find . -maxdepth 1 -type l -exec readlink {} \; ; find . -maxdepth 1 -type d ; } | grep -Ev '(^[^.]|\.$)' | sort | uniq -u ); do
read -p "Found unlinked (obsolete bugfix-) version $_unlinkedDir. Delete [y/N]? " -n 1 -r; echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "$_unlinkedDir" && echo " deleted"
fi
done
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment