79 lines
2.2 KiB
Bash
Executable File
79 lines
2.2 KiB
Bash
Executable File
#! /bin/bash
|
|
|
|
# This file is part of Cockpit.
|
|
#
|
|
# Copyright (C) 2015 Red Hat, Inc.
|
|
#
|
|
# Cockpit is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU Lesser General Public License as published by
|
|
# the Free Software Foundation; either version 2.1 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Cockpit is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
set -ex
|
|
|
|
out="$1"
|
|
base="$2"
|
|
|
|
redirect_base=$(curl -s -w "%{redirect_url}" "$base" -o /dev/null)
|
|
if [ -n "$redirect_base" ]; then
|
|
base="$redirect_base"
|
|
fi
|
|
|
|
# Lookup the newest base image recursively
|
|
url="$base"
|
|
while [ $# -gt 2 ]; do
|
|
fragment="$3"
|
|
|
|
if [ "$fragment" = "sort" ]; then
|
|
backref="$4"
|
|
pattern="$5"
|
|
|
|
result="`wget -q -O- $url | grep -oE "$pattern" | sed -E "s/${pattern}/\\\\${backref} \\0/" | sort -V -k1 | tail -1`"
|
|
fragment="`echo $result | cut -f2 -d' '`"
|
|
|
|
|
|
if [ -z "$fragment" ]; then
|
|
echo "Could not find '$pattern' at: $url" >&2
|
|
exit 1
|
|
fi
|
|
|
|
shift; shift
|
|
fi
|
|
|
|
base="$url"
|
|
url="$base/$fragment"
|
|
|
|
shift
|
|
done
|
|
|
|
# we link to the file so wget can properly detect if we have already downloaded it
|
|
# note that due to mirroring, timestamp comparison can result in unnecessary downloading
|
|
out_base="`dirname $out`"
|
|
intermediate="$out_base/$fragment"
|
|
|
|
if [ "$intermediate" != "$out" ]; then
|
|
wget --no-clobber --directory-prefix="$out_base" "$base/$fragment"
|
|
cp "$intermediate" "$out"
|
|
else
|
|
rm -f "$out"
|
|
wget --directory-prefix="$out_base" "$base/$fragment"
|
|
fi
|
|
|
|
# Make the image be at least 12 Gig. During boot, docker-storage-setup
|
|
# will grow the partitions etc as appropriate, and atomic.setup will
|
|
# explicitly grow the docker pool.
|
|
|
|
vsize=$(qemu-img info "$out" --output=json | python3 -c 'import json, sys; print(json.load(sys.stdin)["virtual-size"])')
|
|
|
|
if [ "$vsize" -lt 12884901888 ]; then
|
|
qemu-img resize "$out" 12884901888
|
|
fi
|