-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpkg
executable file
·103 lines (83 loc) · 3.26 KB
/
pkg
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
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
# Sigil adaptations made by Doug Massay 2017
from __future__ import (unicode_literals, division, absolute_import,
print_function)
import sys
import os
import subprocess
import errno
base = os.path.dirname(os.path.abspath(__file__))
def abspath(x):
return os.path.abspath(os.path.join(base, x))
def usage():
raise SystemExit((
'Usage: %s 32|64'
' [the rest of the command line is passed to main.py]'
) % sys.argv[0])
arch = sys.argv[1] #.decode('UTF-8')
if arch not in '64 32'.split() or len(sys.argv) < 2:
usage()
def mkdir(x):
try:
os.mkdir(abspath(x))
except EnvironmentError as err:
if err.errno == errno.EEXIST:
return
raise
if 'SUDO_UID' in os.environ and os.geteuid() == 0:
os.chown(abspath(x),
int(os.environ['SUDO_UID']), int(os.environ['SUDO_GID']))
mkdir('sources-cache')
mkdir('build')
output_dir = os.path.join(abspath('build'), arch)
mkdir(output_dir)
def check_for_image(tag):
return bool(subprocess.check_output(('docker images -q sigil:%s' % tag).split()))
def build_docker():
DOCKERFILE = '''
FROM {}
MAINTAINER Doug Massay
ARG DEBIAN_FRONTEND=noninteractive
RUN useradd --home-dir=/tmp --uid=1000 --gid=100 sigil
# Basic build environment
RUN apt-get update && apt-get install -y build-essential xorg-dev python python-argparse chrpath gettext nasm cmake pkg-config \
libtool autoconf automake
# Build time deps for Qt. See http://doc.qt.io/qt-5/linux-requirements.html and https://wiki.qt.io/Building_Qt_5_from_Git
RUN apt-get install -y flex bison gperf ruby libcups2-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev \
libxcb1-dev libx11-xcb-dev libxcb-glx0-dev xkb-data libglu1-mesa-dev libgtk2.0-dev libasound2-dev libpulse-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-libav gstreamer1.0-pulseaudio gstreamer1.0-alsa
RUN apt-get clean
'''.format('ubuntu:trusty' if arch == '64' else 'daald/ubuntu32:trusty')
with open(os.path.join(output_dir, 'dockerfile'), 'wb') as f:
f.write(DOCKERFILE.encode('utf-8'))
cmd = ('docker', 'build', '-t', ('sigil:' + arch), '-f', f.name, output_dir)
print(*cmd)
p = subprocess.Popen(cmd)
if p.wait() != 0:
raise SystemExit(p.wait())
if sys.argv[2:] == ['docker']:
build_docker()
raise SystemExit(0)
if not check_for_image(arch):
build_docker()
cmd = [
'docker', 'run',
'-v', abspath('sources-cache') + ':/sources:rw',
'-v', abspath('scripts') + ':/scripts:ro',
'-v', abspath('patches') + ':/patches:ro',
'-v', output_dir + ':/sw:rw',
'--tmpfs', '/tmp:rw,nodev,nosuid,size=6G,noatime,exec',
'--rm=true',
'--interactive=' + ('true' if sys.stdin.isatty() else 'false'),
'--tty=' + ('true' if sys.stdin.isatty() else 'false'),
'sigil:' + arch,
'python', '/scripts/main.py',
]
sigil_dir = os.environ.get('SIGIL_SRC_DIR')
if sigil_dir is not None and os.path.exists(sigil_dir) and os.path.isdir(sigil_dir):
cmd[2:2] = ['-v', abspath(sigil_dir) + ':/sigil-src:ro']
cmd += sys.argv[2:]
print(*cmd)
raise SystemExit(subprocess.Popen(cmd).wait())