This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdepthboot_updates.py
306 lines (243 loc) · 12.6 KB
/
depthboot_updates.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# This file contains all updates for Depthboot. It is called by system-update.py
# The functions are named after the version they update to. For example, the update script for v1.1.0 is named v1_1_0().
# Read the full changelog here: https://github.com/eupnea-linux/depthboot-builder/releases
import contextlib
import json
import os
from functions import *
def v1_1_0():
# This update was done by the old scripts updater script. It is only here for reference.
# update-scripts.py can be found here: https://github.com/eupnea-linux/eupnea-utils/blob/main/update-scripts
pass
def v1_1_1():
# This update adds a fix for auto rotate being flipped on some devices.
# It has been added to the depthboot script a few weeks prior to this update
cpfile("/usr/lib/eupnea-system-update/configs/hwdb/61-sensor.hwdb", "/etc/udev/hwdb.d/61-sensor.hwdb")
bash("systemd-hwdb update")
# Remove old eupnea-utils scripts
rmfile("/usr/lib/eupnea/eupnea-postinstall") # has been renamed to just postinstall
rmfile("/usr/lib/eupnea/eupnea-update") # has been included accidentally in the package
# Remove unneeded settings from /etc/eupnea.json
with open("/etc/eupnea.json", "r") as f:
config = json.load(f)
# these settings were already removed in v1.1.0, but the json file on GitHub was not updated, therefore
# some newer installs still have them
with contextlib.suppress(KeyError):
del config["kernel_type"]
with contextlib.suppress(KeyError):
del config["kernel_version"]
with contextlib.suppress(KeyError):
del config["kernel_dev"]
with contextlib.suppress(KeyError):
del config["postinstall_version"]
with contextlib.suppress(KeyError):
del config["audio_version"]
with open("/etc/eupnea.json", "w") as file:
json.dump(config, file)
# if config["distro_name"] == "arch" and config["de_name"] != "cli":
# the auto-rotate service is not installed by default on Arch
# bash("pacman -Syyu --noconfirm") # update the package database
# bash("pacman -S --noconfirm iio-sensor-proxy")
# after a reboot the auto-rotate service will automatically be "integrated" into the DE
def v1_1_2():
# the depthboot_updates.py file was missing some imports and therefore the v1.1.1 update was not applied
# There were also a few other minor fixes
v1_1_1()
def v1_1_3():
# This update installs zram on systems that were not installed with zram
with open("/etc/eupnea.json", "r") as f:
config = json.load(f)
# fedora and pop os already have zram installed and setup ootb
# PopOS' zram generator only seems to work on new mainline kernels (possibly on new chromeos kernels too)
# -> might not work until v1.2.0 (kernel package update)
# if config["distro_name"] in ["arch", "ubuntu"]:
# cpfile("/usr/lib/eupnea-system-update/configs/systemd-services/eupnea-system-update-v1.1.3.service",
# "/etc/systemd/system/eupnea-system-update-v1.1.3.service")
# cpfile("/usr/lib/eupnea-system-update/configs/bash-scripts/update-v1.1.3-postinstall.sh",
# "/usr/lib/eupnea/update-v1.1.3-postinstall.sh")
# bash("systemctl enable eupnea-system-update-v1.1.3.service")
def v1_1_4():
# The previous update tried to install a package from inside a postinstall script which does not work as the
# apt/pacman processes have lock files
# The v1.1.3 update has now been fixed and this update reruns the v1.1.3 update
v1_1_3()
def v1_1_5():
# All previous updates tried installing and uninstalling packages from within this script which did not work due to
# the package manager processes having lock files
# v1_1_1 attempted to install iio-sensor-proxy, which did not work due to the package manager processes having lock
# files
# v1_1_3 attempted to install zram-generator, which also did not work
# -> install iio-sensor-proxy and zram-generator via the new systemd service on arch
with open("/etc/eupnea.json") as f:
distro_name = json.load(f)["distro_name"]
match distro_name:
case "ubuntu":
with open("/var/tmp/eupnea-updates/v1_1_5.txt", "w") as f:
f.write("systemd-zram-generator")
case "arch":
with open("/var/tmp/eupnea-updates/v1_1_5.txt", "w") as f:
f.write("iio-sensor-proxy zram-generator")
case _:
# Fedora & Pop!_OS already have zram
pass
# Completely clean eupnea.json for the last time
with open("/etc/eupnea.json", "r") as f:
config = json.load(f)
# these settings were already removed in previous updates, but the json file on GitHub was not updated, therefore
# some newer installs still have them
with contextlib.suppress(KeyError):
del config["kernel_type"]
with contextlib.suppress(KeyError):
del config["kernel_version"]
with contextlib.suppress(KeyError):
del config["kernel_dev"]
with contextlib.suppress(KeyError):
del config["postinstall_version"]
with contextlib.suppress(KeyError):
del config["audio_version"]
with contextlib.suppress(KeyError):
del config["dev_build"]
with open("/etc/eupnea.json", "w") as file:
json.dump(config, file)
# add custom zram config file to fedora as otherwise zram fails to start, presumably due to trying the wrong algo
if distro_name == "fedora":
cpfile("/usr/lib/eupnea-system-update/configs/zram/zram-generator.conf", "/etc/systemd/zram-generator.conf")
def v1_1_6():
# The v1.1.5 update was not applied correctly on some systems
# -> rerun the v1.1.5 update
v1_1_5()
# some older depthboot systems still have cloud-utils installed
with open("/var/tmp/eupnea-updates/v1_1_6_1.txt", "w") as f:
f.write("-cloud-utils") # the package has the same name on all distros
# Fix the ubuntu version on installs
with open("/etc/eupnea.json") as f:
config = json.load(f)
if config["distro_version"] == "22.04":
# Fix the repo target on ubuntu 22.04 and popos
with open("/etc/apt/sources.list.d/eupnea.list", "r") as file:
repo = file.read()
repo = repo.replace("kinetic", "jammy")
with open("/etc/apt/sources.list.d/eupnea.list", "w") as file:
file.write(repo)
# update repos to get jammy eupnea packages
# this will not interfere with the apt lock file
bash("apt-get update")
# install the backported libasound2-eupnea package on jammy to support ucm configs v6 syntax
# PopOS has an updated libasound2-eupnea package in their repo -> no need to install our backport
if config["distro_name"] == "ubuntu":
with open("/var/tmp/eupnea-updates/v1_1_6_2.txt", "w") as f:
f.write("libasound2-eupnea")
def v1_2_0():
# This update removes the old kernel scripts/configs and installs the new kernel packages
# Remove old kernel modules load config; the new kernels have been fixed and can now automatically load modules
rmfile("/etc/modules-load.d/eupnea-modules.conf")
# Clean /boot from any stock kernel files
for file in os.listdir("/boot"):
if not file.__contains__("eupnea"):
rmdir(file, keep_dir=False)
# check if mainline or chromeos kernel is currently installed
kernel_version = bash("uname -r").strip()
if kernel_version.startswith("6."):
with open("/var/tmp/eupnea-updates/v1_2_0.txt", "w") as f:
f.write("eupnea-mainline-kernel")
else:
with open("/var/tmp/eupnea-updates/v1_2_0.txt", "w") as f:
f.write("eupnea-chromeos-kernel")
def v1_2_1():
# the kernel packages on arch were broken -> uninstall and install again
v1_2_0()
with open("/var/tmp/eupnea-updates/a_v1_2_0.txt", "w") as f: # add "a" to force modify-packages to read it first
f.write("-eupnea-mainline-kernel -eupnea-chromeos-kernel")
def v1_2_2():
# rename de_name in pop-os
with open("/etc/eupnea.json") as f:
config = json.load(f)
if config["de_name"] == "popos":
config["de_name"] = "cosmic-gnome"
def v1_2_3():
# libasound2-eupnea was not installed on newer Jammy Depthboot builds -> install again on all systems
with open("/etc/eupnea.json") as f:
config = json.load(f)
if config["distro_name"] == "ubuntu" and config["distro_version"] == "22.04":
with open("/var/tmp/eupnea-updates/v1_2_3.txt", "w") as f:
f.write("libasound2-eupnea")
def v1_2_4():
# This update will remove the deep sleep block in sleep.conf and modify the cmdline to enable deep sleep by default
# There is a chance this update will trigger an NVRAM reset
# remove deep sleep block in sleep.conf if present (some testers have removed it already)
# the code below was broken and is fixed in the next update
# with open("/etc/systemd/sleep.conf", "r") as file:
# sleep_conf = file.read().strip().splitlines()
# if sleep_conf[-1] == "HibernateState=freeze" and sleep_conf[-2] == "SuspendState=freeze":
# sleep_conf = sleep_conf[:-2]
# with open("/etc/systemd/sleep.conf", "w") as file:
# file.writelines(sleep_conf)
# modify the kernel cmdline to enable deep sleep by default
with open("/proc/cmdline", "r") as file:
current_cmdline = file.read().strip()
new_cmdline_file = bash("mktemp").strip() # make a temp file to write the new cmdline to
print(f"Updated cmdline: {current_cmdline} mem_sleep_default=deep")
with open(new_cmdline_file, "w") as file:
file.write(f"{current_cmdline} mem_sleep_default=deep")
# pass temp file to install-cmdline to install the new cmdline
bash(f"/usr/lib/eupnea/install-kernel --kernel-flags {new_cmdline_file}")
def v1_2_5():
# the previous update stored the sleep.conf files in a broken way
# (not really broken, but they weren't reverted to stock either)
with open("/etc/eupnea.json", "r") as file:
sys_conf = json.load(file)
cpfile(f"/usr/lib/eupnea-system-update/configs/sleep_conf/{sys_conf['distro_name']}-"
f"{sys_conf['distro_version']}-sleep.conf", "/etc/systemd/sleep.conf")
def v1_2_6():
# somehow a lot of devices are still on old kernels -> reapply the kernel update
v1_2_0()
def v1_3_0():
# this update installs keyd and custom keymaps
# restore stock xkb pc file
cpfile("/usr/share/X11/xkb/symbols/pc.default", "/usr/share/X11/xkb/symbols/pc")
rmfile("/usr/share/X11/xkb/symbols/pc.default") # not needed anymore
# install keyd
with open("/var/tmp/eupnea-updates/v1_3_0.txt", "w") as f:
f.write("keyd")
def v1_3_1():
# update kinetic repo to lunar
# will not do anything on 22.04 based systems
with contextlib.suppress(FileNotFoundError):
with open("/etc/apt/sources.list.d/eupnea.list", "r") as file:
repo = file.read()
repo = repo.replace("kinetic", "lunar")
with open("/etc/apt/sources.list.d/eupnea.list", "w") as file:
file.write(repo)
def v1_3_2():
# this update will update the distro version in the eupnea.json file
# Only applies to fedora and ubuntu as those had updates recently
with open("/etc/eupnea.json", "r") as file:
sys_conf = json.load(file)
with open("/etc/os-release", "r") as file:
os_release = file.read().strip()
if os_release.__contains__("23.04 (Lunar Lobster)"):
sys_conf["distro_version"] = "23.04"
elif os_release.__contains__("Fedora Linux 38 (Workstation Edition)"):
sys_conf["distro_version"] = "38"
with open("/etc/eupnea.json", "w") as file:
json.dump(sys_conf, file, indent=4)
def v1_3_3():
# the keyd packages postinstall was broken when installed from a chroot -> some newer systems don't have keyd
# this update will install keyd
with open("/var/tmp/eupnea-updates/v1_3_3.txt", "w") as f:
f.write("keyd")
def v1_3_4():
# remove the cmdline argument that forces deep sleep
# deep sleep has been deprecated by Intel. Devices that support it will still use it by default
with open("/proc/cmdline", "r") as file:
current_cmdline = file.read().strip()
new_cmdline_file = bash("mktemp").strip() # make a temp file to write the new cmdline to
new_cmdline = current_cmdline.replace(" mem_sleep_default=deep", "").strip()
print(f"Updated cmdline: {new_cmdline}")
with open(new_cmdline_file, "w") as file:
file.write(new_cmdline)
# pass temp file to install-cmdline to install the new cmdline
bash(f"/usr/lib/eupnea/install-kernel --kernel-flags {new_cmdline_file}")
def v1_4_0():
# this release is purely symbolic and does not contain any updates to previous releases
pass