Blame SOURCES/v1.10-migrator-helper

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