Nextcloud-Docker/update.sh

73 lines
2.1 KiB
Bash
Raw Normal View History

2016-09-02 13:11:38 +00:00
#!/bin/bash
set -eo pipefail
declare -A cmd=(
[apache]='apache2-foreground'
[fpm]='php-fpm'
)
2017-03-07 14:33:57 +00:00
# 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:]]+)+' | \
2017-06-23 14:12:44 +00:00
sort -urV ) )
2017-06-23 14:12:44 +00:00
find . -maxdepth 1 -type d -regextype sed -regex '\./[[:digit:]]\+\.[[:digit:]]\+' -exec rm -r '{}' \;
2017-06-10 21:15:01 +00:00
2017-03-14 09:48:58 +00:00
travisEnv=
for latest in "${latests[@]}"; do
version=$(echo "$latest" | cut -d. -f1-2)
2017-06-23 14:12:44 +00:00
if [ -d "$version" ]; then
continue
fi
2017-08-27 08:58:21 +00:00
# Only add versions >= 11
if version_greater_or_equal "$version" "11.0"; then
2017-06-10 21:15:01 +00:00
for variant in apache fpm; do
# Create the version+variant directory with a Dockerfile.
mkdir -p "$version/$variant"
2017-03-07 14:33:57 +00:00
2017-06-10 21:15:01 +00:00
template="Dockerfile.template"
cp "$template" "$version/$variant/Dockerfile"
2017-06-10 21:15:01 +00:00
echo "updating $latest [$version] $variant"
2017-06-10 21:15:01 +00:00
# Replace the variables.
sed -ri -e '
s/%%VARIANT%%/'"$variant"'/g;
s/%%VERSION%%/'"$latest"'/g;
s/%%CMD%%/'"${cmd[$variant]}"'/g;
' "$version/$variant/Dockerfile"
2017-06-10 21:15:01 +00:00
# Copy the docker-entrypoint.
cp docker-entrypoint.sh "$version/$variant/docker-entrypoint.sh"
2017-03-14 09:48:58 +00:00
2017-07-01 12:31:06 +00:00
# Copy the config directory
cp -rT .config "$version/$variant/config"
2017-04-17 21:02:25 +00:00
2017-09-14 08:23:46 +00:00
# Remove Apache commands and configs if we're not an Apache variant.
if [ "$variant" != "apache" ]; then
sed -ri -e '/a2enmod/d' "$version/$variant/Dockerfile"
rm "$version/$variant/config/apache-pretty-urls.config.php"
fi
2017-06-29 10:57:03 +00:00
for arch in i386 amd64; do
travisEnv='\n - env: VERSION='"$version"' VARIANT='"$variant"' ARCH='"$arch$travisEnv"
done
2017-06-10 21:15:01 +00:00
done
fi
done
2017-03-14 09:48:58 +00:00
2017-06-23 14:12:44 +00:00
# replace the fist '-' with ' '
travisEnv="$(echo "$travisEnv" | sed '0,/-/{s/-/ /}')"
2017-03-14 09:48:58 +00:00
# update .travis.yml
2017-06-23 14:12:44 +00:00
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)"
2017-03-14 09:48:58 +00:00
echo "$travis" > .travis.yml