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