|
|
3ae847 |
#!/bin/bash
|
|
|
3ae847 |
|
|
|
3ae847 |
# Copyright (C) 2016 Red Hat, Inc.
|
|
|
3ae847 |
#
|
|
|
3ae847 |
# This program is free software: you can redistribute it and/or modify
|
|
|
3ae847 |
# it under the terms of the GNU General Public License as published by
|
|
|
3ae847 |
# the Free Software Foundation, either version 3 of the License, or
|
|
|
3ae847 |
# (at your option) any later version.
|
|
|
3ae847 |
#
|
|
|
3ae847 |
# This program is distributed in the hope that it will be useful,
|
|
|
3ae847 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
3ae847 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
3ae847 |
# GNU General Public License for more details.
|
|
|
3ae847 |
#
|
|
|
3ae847 |
# You should have received a copy of the GNU General Public License
|
|
|
3ae847 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
3ae847 |
|
|
|
3ae847 |
set -euo pipefail
|
|
|
3ae847 |
IFS=$'\n\t'
|
|
|
3ae847 |
|
|
|
3ae847 |
# This is a small wrapper script that automatically fetches
|
|
|
3ae847 |
# the storage options from the docker-storage sysconfig file
|
|
|
3ae847 |
# and passes them to the migrator.
|
|
|
3ae847 |
#
|
|
|
3ae847 |
# The script supports both in-container runs and direct
|
|
|
3ae847 |
# invocation.
|
|
|
3ae847 |
|
|
|
3ae847 |
MIGRATOR=/usr/bin/v1.10-migrator-local
|
|
|
3ae847 |
STORAGE_FILE=/etc/sysconfig/docker-storage
|
|
|
3ae847 |
GRAPH=/var/lib/docker
|
|
|
3ae847 |
|
|
|
3ae847 |
main() {
|
|
|
3ae847 |
|
|
|
3ae847 |
# are we in a container?
|
|
|
3ae847 |
if [[ -n ${container-} ]]; then
|
|
|
3ae847 |
|
|
|
3ae847 |
if [[ ! -d /host ]]; then
|
|
|
3ae847 |
echo "ERROR: Running inside a container, but /host not mounted." >&2
|
|
|
3ae847 |
exit 1
|
|
|
3ae847 |
fi
|
|
|
3ae847 |
|
|
|
3ae847 |
cp "$MIGRATOR" /host/tmp
|
|
|
3ae847 |
MIGRATOR="chroot /host /tmp/$(basename $MIGRATOR)"
|
|
|
3ae847 |
STORAGE_FILE=/host${STORAGE_FILE}
|
|
|
3ae847 |
fi
|
|
|
3ae847 |
|
|
|
3ae847 |
if [ ! -d "$GRAPH" ]; then
|
|
|
3ae847 |
echo "ERROR: Cannot find docker root dir at \"$GRAPH\"." >&2
|
|
|
3ae847 |
exit 1
|
|
|
3ae847 |
fi
|
|
|
3ae847 |
|
|
|
3ae847 |
# load storage opts if we can find the file
|
|
|
3ae847 |
local storage_opts=
|
|
|
3ae847 |
if [ -r "$STORAGE_FILE" ] && grep -q -E '^DOCKER_STORAGE_OPTIONS\s*=' "$STORAGE_FILE"; then
|
|
|
3ae847 |
storage_opts=$(sed -n -e 's/^DOCKER_STORAGE_OPTIONS\s*=\s*// p' "$STORAGE_FILE")
|
|
|
3ae847 |
storage_opts=${storage_opts#\"}
|
|
|
3ae847 |
storage_opts=${storage_opts%\"}
|
|
|
3ae847 |
fi
|
|
|
3ae847 |
|
|
|
3ae847 |
CMD="$MIGRATOR --graph $GRAPH $storage_opts"
|
|
|
3ae847 |
echo "RUNNING: $CMD"
|
|
|
3ae847 |
eval $CMD
|
|
|
3ae847 |
}
|
|
|
3ae847 |
|
|
|
3ae847 |
main "$@"
|