Sophie

Sophie

distrib > Mageia > cauldron > i586 > by-pkgid > 44769378fa32556142636eeb8aea9812 > scriptlet

docker-24.0.5-5.mga10.i586.rpm

PREIN

/bin/sh
getent group docker > /dev/null || /usr/sbin/groupadd -r docker
# If upgrade, try to export all images
if [ $1 -ge 2 ];then
	majver=`docker --version | awk '{print $3}' | cut -d. -f1`
	if [ $majver -ge 24 ]; then
		# No need to update from version 24 on.
		exit 0
	fi
	echo "Docker version is less than 24.x, migration of images needed"
	# Get storage location
	storage=`grep -E '^DOCKER_STORAGE_OPTIONS' /etc/sysconfig/docker-storage | cut -d' ' -f2 | sed 's/"//g'`
	if [ ! -d "$storage" ]; then
		echo "Unable to find Docker storage dir - aborting migration"
		exit -1
	fi
	mkdir -p $storage/save
	echo "Exporting Docker images to $storage/save"
	echo "This may really take a long time depending on the number of images !!"
	echo "You also need enough room under $storage to host them"
	date
	# Export images and tags to recreate them once update is done
	for i in `docker image ls -q | sort -u`; do
		echo "Exporting image $i to $storage/save/$i.tar.xz"
		docker save $i | xz > $storage/save/$i.tar.xz && /bin/true
	done
	docker image ls > $storage/save/tags.txt
	echo "Renamig the backed up aufs directory as aufs.old"
	mv $storage/aufs $storage/aufs.old
	mv $storage/image/aufs $storage/image/aufs.old
	echo "End of docker images export"
	date
fi
exit 0

PREUN

/bin/sh

 
if [ $1 -eq 0 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then 
    # Package removal, not upgrade 
    /usr/lib/systemd/systemd-update-helper remove-system-units docker || : 
fi

POSTIN

/bin/sh
# -g option moved to --data-root to manage image storage
perl -pi -e 's|-g |--data-root |' /etc/sysconfig/docker-storage
# If upgrade, try to import all saved images
# Deals with a change of format between mga8 (aufs) and mga9 (overlay2)
if [ $1 -ge 2 ];then
	# Get storage location
	storage=`grep -E '^DOCKER_STORAGE_OPTIONS' /etc/sysconfig/docker-storage | cut -d' ' -f2 | sed 's/"//g'`
	if [ ! -d "$storage/save" ]; then
		exit 0
	else
		echo "Restoring images from $storage/save"
	fi
	cd $storage/save
	echo "Starting Docker service"
	systemctl start docker
	echo "Importing Docker images from $storage/save"
	echo "This will again take time depending on the number of images saved but 10 times less !!"
	# Import images
	date
	for i in `ls *.xz`; do
		img=`echo $i | sed 's|.tar.xz$||'`
		echo "Importing image $img"
		xzcat $i | docker load
		while IFS=" " read -r repo tag imgid remainder
		do
			if [ $tag = "<none>" ]; then
				tag="latest"
			fi
			if [ $repo != "REPOSITORY" ]; then
				if [ $imgid = $img ] && [ $repo != "<none>" ] ; then
					echo "Tagging image $img ${repo}:${tag}"
					docker tag $img ${repo}:${tag}
				fi
			fi
		done < "$storage/save/tags.txt"
	done
	date
	echo "Purging now useless old and converted aufs based images"
	rm -rf $storage/aufs.old
	echo "Please purge $storage/oldsave once you checked all your Docker images are ok"
	mv $storage/save $storage/oldsave
	echo "Stopping Docker service"
	systemctl stop docker
fi

 
if [ $1 -eq 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then 
    # Initial installation 
    /usr/lib/systemd/systemd-update-helper install-system-units docker || : 
fi 

exit 0

POSTUN

/bin/sh

 
if [ $1 -ge 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then 
    # Package upgrade, not uninstall 
    /usr/lib/systemd/systemd-update-helper mark-restart-system-units docker || : 
fi