Blame SOURCES/v1.10-migrator-helper

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