forked from AsahiLinux/asahi-audio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
103 lines (80 loc) · 2.99 KB
/
install.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
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
# (C) 2022 James Calligeros
import os
import shutil
import time
def get_system():
# Use the list of subdirs in 'conf' as our list of supported machines
supported = os.listdir(path="./conf/")
# Get rid of '.conf'
for i, machine in enumerate(supported):
supported[i] = machine[0:4]
with open("/sys/firmware/devicetree/base/compatible", "r") as sys:
sys = sys.read()
compat = sys[6:10] # Get only the 4 chars after 'apple,'
if compat in supported:
return compat
else:
return -1
def install_pw_conf(system):
'''
Since the audio stack is dumb and cannot pick and choose configurations
for us on the fly, we must install a specific configuration based on the
user's machine. Luckily, it's all pretty trivial stuff.
'''
try:
shutil.copy2(f"conf/{system}.conf",
f"/etc/pipewire/pipewire.conf.d/10-{system}-sink.conf")
except FileExistsError:
choice = input("File exists. Replace? (Y/n)")
if choice == "n":
return -1
else:
os.remove(f"/etc/pipewire/pipewire.conf.d/10-{system}-sink.conf")
shutil.copy2(f"conf/{system}.conf",
f"/etc/pipewire/pipewire.conf.d/10-{system}-sink.conf")
return
def install_firs(system):
try:
shutil.copytree(f"firs/{system}",
f"/usr/share/pipewire/devices/apple/{system}")
except FileExistsError:
choice = input("Files exist. Replace? (Y/n)")
if choice == "n":
return -1
else:
shutil.rmtree(f"/usr/share/pipewire/devices/apple/{system}")
shutil.copytree(f"firs/{system}",
f"/usr/share/pipewire/devices/apple/{system}")
return
def main():
machine = get_system()
if machine == -1:
print(f"Sorry, the {machine} is not currently supported.")
exit()
print(f"This machine is a {machine}.\n")
input("Press Enter to continue...")
print("Installing PipeWire configuration files...\n")
pwret = install_pw_conf(machine)
if pwret == -1:
print("Could not install PipeWire configuration files.")
print("This program will now exit.")
exit()
print("Installing Finite Impulse Responses...\n")
irret = install_firs(machine)
if irret == -1:
print("Could not install FIRs.")
print("This program will now exit.")
exit()
print("Please put the current built-in audio device into the Pro Audio")
print("profile. Do not continue until you have done this.")
input("Press Enter to continue...\n")
print("Killing PipeWire...\n")
os.system("killall pipewire")
time.sleep(2)
print("PipeWire has been stopped. Please reboot your machine for the")
print("changes to take effect. Logging out and logging in again is not")
print("sufficient.")
if __name__ == "__main__":
main()