summaryrefslogtreecommitdiff
path: root/sh/migrate-to-run.sh.in
blob: 73978e7cebd9eee0b531182444f40da16d383b44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!@SHELL@
# Copyright (c) 2012 William Hubbs <w.d.hubbs@gmail.com>
# Released under the 2-clause BSD license.

. "@LIBEXECDIR@/sh/functions.sh"

if ! mountinfo -q -f tmpfs "@LIBEXECDIR@/init.d"; then
	einfo "The OpenRC dependency data has already been migrated."
	exit 0
fi

if [ ! -d /run ]; then
	eerror "/run is not a directory."
	eerror "This means the OpenRC dependency data cannot be migrated."
	eerror "Please create the /run directory and reboot the system."
	exit 1
fi

if ! mountinfo -q -f tmpfs /run; then
	for x in /run/.* /run/*; do
		case "$x" in
			/run/.|/run/..)
				continue
				;;
		esac
		if [ -e "$x" ]; then
				eerror "Your /run directory contains files."
				eerror "Please reboot the system."
				exit 1
		fi
	done

	mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run 2> /dev/null
	if [ $? != 0 ]; then
		eerror "Unable to mount a tmpfs on /run."
		eerror "This means the OpenRC dependency data cannot be migrated."
		eerror "Please create the /run directory and reboot the system."
		exit 1
	fi
fi

rm -rf /run/openrc
cp -a "@LIBEXECDIR@/init.d" /run/openrc
rc-update -u
umount "@LIBEXECDIR@/init.d"
rm -rf "@LIBEXECDIR@/init.d"
einfo "The OpenRC dependency data was migrated successfully."
exit 0