Nextcloud-Docker/update.sh

102 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
set -eo pipefail
declare -A php_version=(
[default]='7.1'
)
declare -A cmd=(
[apache]='apache2-foreground'
[fpm]='php-fpm'
[fpm-alpine]='php-fpm'
)
declare -A base=(
[apache]='debian'
[fpm]='debian'
[fpm-alpine]='alpine'
)
declare -A extras=(
[apache]='\nRUN a2enmod rewrite'
[fpm]=''
[fpm-alpine]=''
)
declare -A pecl_versions=(
[APCu]='5.1.11'
[memcached]='3.0.4'
[redis]='3.1.6'
)
# version_greater_or_equal A B returns whether A >= B
function version_greater_or_equal() {
[[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" || "$1" == "$2" ]];
}
latests=( $( curl -fsSL 'https://download.nextcloud.com/server/releases/' |tac|tac| \
grep -oE 'nextcloud-[[:digit:]]+(.[[:digit:]]+)+' | \
grep -oE '[[:digit:]]+(.[[:digit:]]+)+' | \
sort -urV ) )
find . -maxdepth 1 -type d -regextype sed -regex '\./[[:digit:]]\+\.[[:digit:]]\+' -exec rm -r '{}' \;
travisEnv=
for latest in "${latests[@]}"; do
version=$(echo "$latest" | cut -d. -f1-2)
if [ -d "$version" ]; then
continue
fi
# Only add versions >= 11
if version_greater_or_equal "$version" "11.0"; then
for variant in apache fpm fpm-alpine; do
# Create the version+variant directory with a Dockerfile.
mkdir -p "$version/$variant"
template="Dockerfile-${base[$variant]}.template"
cp "$template" "$version/$variant/Dockerfile"
echo "updating $latest [$version] $variant"
# Replace the variables.
sed -ri -e '
s/%%PHP_VERSION%%/'"${php_version[$version]-${php_version[default]}}"'/g;
s/%%VARIANT%%/'"$variant"'/g;
s/%%VERSION%%/'"$latest"'/g;
s/%%CMD%%/'"${cmd[$variant]}"'/g;
s/%%VARIANT_EXTRAS%%/'"${extras[$variant]}"'/g;
s/%%APCU_VERSION%%/'"${pecl_versions[APCu]}"'/g;
s/%%MEMCACHED_VERSION%%/'"${pecl_versions[memcached]}"'/g;
s/%%REDIS_VERSION%%/'"${pecl_versions[redis]}"'/g;
' "$version/$variant/Dockerfile"
# Copy the shell scripts
for name in entrypoint cron; do
cp "docker-$name.sh" "$version/$variant/$name.sh"
done
# Copy the config directory
cp -rT .config "$version/$variant/config"
# Remove Apache config if we're not an Apache variant.
if [ "$variant" != "apache" ]; then
rm "$version/$variant/config/apache-pretty-urls.config.php"
fi
for arch in i386 amd64; do
travisEnv='\n - env: VERSION='"$version"' VARIANT='"$variant"' ARCH='"$arch$travisEnv"
done
done
fi
done
# replace the fist '-' with ' '
travisEnv="$(echo "$travisEnv" | sed '0,/-/{s/-/ /}')"
# update .travis.yml
travis="$(awk -v 'RS=\n\n' '$1 == "-" && $2 == "stage:" && $3 == "test" && $4 == "images" { $0 = " - stage: test images'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml