Browse Source

add dispatcher

master
belliash 7 years ago
parent
commit
0e574e400e
2 changed files with 113 additions and 0 deletions
  1. 101
    0
      files/dispatch.sh
  2. 12
    0
      modules/gentoo-dispatcher.ezmod

+ 101
- 0
files/dispatch.sh View File

@@ -0,0 +1,101 @@
1
+#!/bin/bash
2
+# Copyright 2010-2011, Asio Software Technologies
3
+# Distributed under the terms of the GNU General Public License v2
4
+
5
+PROGRESS=/var/run/dispatch-progress
6
+
7
+# Outputs error message and aborts script execution
8
+die() {
9
+	eerror $1
10
+	exit $2
11
+}
12
+
13
+# Sets progress of dispatch process
14
+dispatchProgress() {
15
+	export DISPATCH_STAGE=$1
16
+	echo "DISPATCH_STAGE=$1" > ${PROGRESS}
17
+}
18
+
19
+# Load necessary files
20
+. /etc/profile
21
+source /etc/init.d/functions.sh
22
+
23
+# Track progress of the dispatching process
24
+[[ -e ${PROGRESS} ]] && source ${PROGRESS}
25
+export DISPATCH_STAGE=${DISPATCH_STAGE:-0}
26
+
27
+# Check if system is dispatched already or if process has been aborted
28
+if [ ${DISPATCH_STAGE} -ge 3 ]; then
29
+	ewarn "Your system has been dispatched already!"
30
+	ewarn "It is not recommended to re-dispatch."
31
+	ewarn "Press ENTER to continue or CTRL+C to abort..."
32
+	read
33
+	dispatchProgress 0
34
+elif [ ${DISPATCH_STAGE} -gt 0 ]; then
35
+	einfo "Resuming dispatch at stage #${DISPATCH_STAGE}..."
36
+fi
37
+
38
+# Display warning when user aborts or process gets killed
39
+trap 'die "Process killed! This may lead into unexpected problems. Be warned!" 9' ABRT INT KILL QUIT TERM
40
+
41
+# Check system requirements
42
+einfo "The process of dispatching may take a while. Please be patient..."
43
+einfo "Checking system requirements..."
44
+[[ ! -e /dev/random ]] && die "The /dev directory seems to be not mounted!"
45
+[[ ! -e /proc/mounts ]] && die "The /proc directory seems to be not mounted!"
46
+ping -c 1 google.com &> /dev/null
47
+[[ "$?" -ne "0" ]] && die "There seems to be no Internet connectivity!"
48
+
49
+# Get necessary variables
50
+einfo "Obtaining necessary variables..."
51
+export ENV_EXPORTS="GENTOO_MIRRORS PORTDIR DISTDIR PKGDIR PORTAGE_TMPDIR
52
+		CFLAGS CHOST CXXFLAGS MAKEOPTS ACCEPT_KEYWORDS PROXY HTTP_PROXY
53
+		FTP_PROXY FEATURES STAGE1_USE"
54
+eval $(python -c 'import portage, os, sys; sys.stdout.write("".join(["export %s=\"%s\"; [[ -z \"%s\" ]] || einfo %s=\\\"%s\\\";\n" % (k, portage.settings[k], portage.settings[k], k, portage.settings[k]) for k in os.getenv("ENV_EXPORTS").split()]))') &> /dev/null
55
+unset ENV_EXPORTS
56
+
57
+# Begin stage #0
58
+if [ ${DISPATCH_STAGE} -eq 0 ]; then
59
+	einfo "Backing up files..."
60
+	mkdir -p /tmp/regen2-dispatch
61
+	cp -ap ${PORTDIR}/sys-apps/portage /tmp/regen2-dispatch/
62
+	dispatchProgress 1
63
+fi
64
+
65
+# Begin stage #1
66
+if [ ${DISPATCH_STAGE} -eq 1 ]; then
67
+	einfo "Generating manifests..."
68
+	cd ${PORTDIR}/sys-apps/portage
69
+	find * -maxdepth 0 -type f -name '*.ebuild' | while read FILE; do
70
+		ebuild ${FILE} manifest &> /dev/null || die "Unable to generate manifest!" 1
71
+	done
72
+	einfo "Installing reGen2 portage..."
73
+	cd ${PORTDIR}/scripts
74
+	export CONFIG_PROTECT="-*"
75
+	export EMERGE_DEFAULT_OPTS=""
76
+	export FEATURES="${FEATURES} -collision-protect"
77
+	emerge -1 --nodeps portage &> /dev/null || die "Unable to install sys-apps/portage!" 1
78
+	dispatchProgress 2
79
+fi
80
+
81
+# Begin stage #2
82
+if [ ${DISPATCH_STAGE} -eq 2 ]; then
83
+	einfo "Testing new portage..."
84
+	export FEATURES="${FEATURES} mini-manifest"
85
+	rm -rf ${PORTDIR}/sys-apps/portage
86
+	cp -ap /tmp/regen2-dispatch/portage ${PORTDIR}/sys-apps/
87
+	emerge -1 --nodeps portage &> /dev/null || die "reGen2 portage seems to be broken!" 2
88
+	einfo "Regenerating local cache..."
89
+	rm -rf /var/cache/edb/mtimedb
90
+	emerge --metadata &> /dev/null || die "Unable to regenerate metadata!" 2
91
+	dispatchProgress 3
92
+fi
93
+
94
+# Begin stage #3
95
+if [ ${DISPATCH_STAGE} -eq 3 ]; then
96
+	einfo "Cleaning up..."
97
+	rm -rf /tmp/regen2-dispatch
98
+	einfo "All done!"
99
+	sleep 5
100
+	einfo "Enjoy reGen2!"
101
+fi

+ 12
- 0
modules/gentoo-dispatcher.ezmod View File

@@ -0,0 +1,12 @@
1
+# Copyright 2010-2012, Asio Software Technologies
2
+# Distributed under the terms of the GNU General Public License v3
3
+EZMOD_DESCRIPTION="Puts Gentoo Dispatching Utility into generated tree"
4
+EZMOD_COMPATIBILITY="ezsync"
5
+EZMOD_AUTHOR="Rafal Kupiec"
6
+EZMOD_VERSION="1.0"
7
+
8
+ezsync_precommit() {
9
+	run "cp ${EZROOT}/files/dispatch.sh ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/scripts/dispatch.sh" || return 1
10
+	run "chmod +x ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/scripts/dispatch.sh" || return 1
11
+	return 0
12
+}

Loading…
Cancel
Save