File: setup-build-chroot

package info (click to toggle)
crawl 2%3A0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 100,188 kB
  • sloc: cpp: 363,709; ansic: 27,765; javascript: 9,516; python: 8,463; perl: 3,293; java: 3,132; xml: 2,380; makefile: 1,835; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (152 lines) | stat: -rwxr-xr-x 3,874 bytes parent folder | download | duplicates (4)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
#---help---
# Usage: setup-build-chroot
#
# This script sets up a DCSS server build chroot, and alters the dgamelaunch
# configuration to use it for compilation.
#
# The source and chroot directories are hard-coded:
# - Config is assumed to be at: /home/crawl-dev/
# - A new build chroot is assumed to be at: /home/crawl-dev/build-chroot/
#
# It will run these steps, in order:
# - bind-mount the existing crawl-build directory into the chroot
# - add a fstab entry to do that automatically
# - patch `dgamelaunch-config/crawl-git.conf` to build via the chroot
# - install required packages
#---help---

set -euo pipefail

die() {
    printf '\033[1;31mERROR:\033[0m %s\n' "$@" >&2  # bold red
    exit 1
}

einfo() {
    printf '\n\033[1;36m> %s\033[0m\n' "$@" >&2  # bold cyan
}

usage() {
    sed -En '/^#---help---/,/^#---help---/p' "$0" | sed -E 's/^# ?//; 1d;$d;'
}

################################################################################

while getopts 'h' OPTION; do
    case "$OPTION" in
        h) usage; exit 0;;
        *) exit 1;;
    esac
done

if [ "$(id -u)" -ne 0 ]; then
    die "This script must be run as root!"
fi

################################################################################

CRAWL_DEV="/home/crawl-dev"
BUILD_CHROOT="$CRAWL_DEV/build-chroot"

einfo "Sanity-testing the existing /home/crawl-dev/ directory"

[ -d "$CRAWL_DEV/dgamelaunch-config/crawl-build" ] \
    || die "Existing $CRAWL_DEV does not look correct";
[ -f "$BUILD_CHROOT/enter-chroot" ] \
    || die "Build chroot $BUILD_CHROOT does not look correct"

einfo "Binding the crawl-build directory into the chroot"

mkdir -p "$BUILD_CHROOT/crawl-build"

cat >> /etc/fstab <<-EOF
$CRAWL_DEV/dgamelaunch-config/crawl-build    $BUILD_CHROOT/crawl-build    none    bind    0    0
EOF

mount -v "$BUILD_CHROOT/crawl-build"

einfo "Patching crawl-git.conf"

(
    cd $CRAWL_DEV/dgamelaunch-config/

    git apply --verbose <<-'EOF'
diff --git a/crawl-git.conf b/crawl-git.conf
index 81489fd..3b2709c 100644
--- a/crawl-git.conf
+++ b/crawl-git.conf
@@ -49,7 +49,10 @@ crawl-repo-do() {
 }

 crawl-do() {
-    ( cd \$CRAWL_REPO/crawl-ref && "\$@" )
+    sudo $BUILD_CHROOT/enter-chroot <<-EOF
+        cd /crawl-build/crawl-git-repository/crawl-ref
+        \$@
+EOF
 }

 git-do() {
EOF

    patch --verbose utils/webtiles <<-'EOF'
--- utils/webtiles	2020-03-21 15:41:02.200482716 +0000
+++ utils/webtiles	2020-03-21 15:40:55.136478475 +0000
@@ -35,7 +35,7 @@
 	log_daemon_msg "Starting webtiles server" "webtiles"
 	ulimit -n 4096
 
-	PYTHONPATH=/home/crawl-dev/tornado/ python ./server.py
+	chroot %%DGL_CHROOT%% python3 crawl-master/webserver/server.py
 	local result=$?
 	log_end_msg $result
 	return $result
EOF

    git apply --verbose <<-'EOF'
diff --git a/config.py b/config.py
index 3bbfd89..48476ff 100644
--- a/config.py
+++ b/config.py
@@ -559,7 +559,7 @@ gid = "%%DGL_GID%%"  # after binding its sockets.
 
 umask = None # e.g. 0077
 
-chroot = "%%DGL_CHROOT%%"
+chroot = "/"
 
 pidfile = "%%CHROOT_WEBDIR%%/run/webtiles.pid"
 daemon = True # If true, the server will detach from the session after startup
EOF
)

einfo "Cleaning build directory"

(
    cd "$CRAWL_DEV/dgamelaunch-config/crawl-build/crawl-git-repository/"
    git clean -fdx
)

einfo "Mounting /proc and /dev/pts"

mount -v --bind /dev/pts "$BUILD_CHROOT/dev/pts"
mount -v --bind /proc "$BUILD_CHROOT/proc"

einfo "Installing required packages"

"$BUILD_CHROOT/enter-chroot" <<-EOF
    apt -y install make git libpcre3-dev libncursesw5-dev python python-yaml \
        pkg-config libpng++-dev libpng-dev
EOF

einfo "Unmounting /proc and /dev/pts"

umount -v "$BUILD_CHROOT/dev/pts"
umount -v "$BUILD_CHROOT/proc"

einfo "Publishing DGL config..."

/home/crawl-dev/dgamelaunch-config/bin/dgl publish --confirm

einfo 'Done! Remember to commit the changes to dgamelaunch-config!'