-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.my.sincerest.apologies.on.ubuntu.17.10.py
executable file
·142 lines (102 loc) · 3.22 KB
/
install.my.sincerest.apologies.on.ubuntu.17.10.py
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
#!/usr/bin/env python3
import os.path
from os.path import exists, basename
import sys
print("This script will install My Sincerest Apologies in the")
print("'apologies' subdirectory of the current directory:")
print(" ", os.getcwd() + "/apologies")
print()
input("[Press Enter to continue or Ctrl-C to abort> ")
def header():
print()
print()
print("_" * 79)
print("_" * 79)
print()
def packages_failed(*failed):
header()
print("Couldn't install all packages! Failed to install:")
print(" ", " ".join(failed))
sys.exit("Sorry, this script can't handle this. Maybe you're not on the network?")
os.system("sudo apt install update")
install_test_map = {
"g++" : "/usr/bin/g++",
"gcc" : "/usr/bin/gcc",
"git" : "/usr/bin/git",
"libffi-dev" : "/usr/lib/x86_64-linux-gnu/libffi.so",
"libglu1-mesa-dev" : "/usr/lib/x86_64-linux-gnu/libGLU.so",
"libopenal1" : "/usr/lib/x86_64-linux-gnu/libopenal.so.1",
"python3-dev" : "/usr/share/doc/python3-dev",
"python3-venv" : "/usr/bin/pyvenv",
}
os.system("sudo apt install -y " + " ".join(install_test_map))
failed = []
for package, filename in install_test_map.items():
if not exists(filename):
failed.append(package)
if failed:
packages_failed(*failed)
os.system("python3 -m venv apologies")
if not exists("apologies/bin/activate"):
header()
sys.exit("Couldn't create apologies venv! I have no idea why this failed.")
os.chdir("apologies")
platform_bits = "64" if sys.maxsize > 2**32 else "32"
avbin_url = "https://github.com/downloads/AVbin/AVbin/install-avbin-linux-x86-" + platform_bits + "-v10"
avbin_filename = basename(avbin_url)
os.system("wget " + avbin_url)
os.system("sudo sh " + avbin_filename)
if not exists("/usr/lib/libavbin.so"):
packages_failed("AVBin")
os.system("git clone https://github.com/larryhastings/pyweek24.git")
if not exists("pyweek24"):
header()
sys.exit("Couldn't clone pyweek24 repo! Are you on the network?")
with open("pyweek24/requirements.txt", "rt") as f:
requirements = [line.partition('=')[0] for line in f.read().split()]
with open("import.test.py", "wt") as f:
def p(s): print(s, file=f)
for package in requirements:
p("import " + package)
p('with open("python.success.txt", "wt") as f:')
p(' f.write("Success!\\n")')
p('print("All Python packages installed. Phew!")')
files_map = {
"child.install.sh": """
#!/usr/bin/env bash
. bin/activate
cd pyweek24
../bin/pip install -r requirements.txt
cd ..
bin/python3 import.test.py
""",
"run_game": """
#!/usr/bin/env bash
. bin/activate
cd pyweek24
../bin/python3 run_game.py
""",
}
for filename, text in files_map.items():
with open(filename, "wt") as f:
f.write(text.lstrip() + "\n")
os.chmod(filename, 0o755)
os.system("sh child.install.sh")
if not exists("python.success.txt"):
header()
sys.exit("Couldn't install all Python packages.\nI have no idea how to fix this, sorry!")
#
# it all worked! clean up.
#
for filename in """
import.test.py
python.success.txt
child.install.sh
""".strip().split():
os.unlink(filename)
os.unlink(avbin_filename)
header()
print("Ready! cd into the 'apologies' directory and run")
print(" % ./run_game")
print("to play My Sincerest Apologies!")
print()