Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding /usr/lib/ublue-update.d #100

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions files/usr/lib/ublue-update.d/system/03-nix-system-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

if [ -x /nix/var/nix/profiles/default/bin/nix ]; then
/nix/var/nix/profiles/default/bin/nix upgrade '.*' --profile ~/nix/var/nix/profiles/default
fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions files/usr/lib/ublue-update.d/user/05-nix-user-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

if [ -x /nix/var/nix/profiles/default/bin/nix ]; then
/nix/var/nix/profiles/default/bin/nix upgrade '.*' --profile ~/.nix-profile
fi
64 changes: 41 additions & 23 deletions src/ublue_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,46 @@ def hardware_inhibitor_checks_failed(
raise Exception(f"update failed to pass checks: \n - {exception_log}")


def run_update_scripts(root_dir: str):
def run_update_script(script_path: str):
executable = os.access(script_path, os.X_OK)
if executable:
log.info(f"Running update script: {script_path}")
out = subprocess.run(
[script_path],
capture_output=True,
)
if out.returncode != 0:
log.error(
f"{full_path} returned error code: {out.returncode}, program output:" # noqa: E501
)
log.error(out.stdout.decode("utf-8"))
notify(
"System Updater",
f"Error in update script: {script_path}, check logs for more info",
)
else:
log.info(f"could not execute file {script_path}")


def run_update_scripts(root_dir: str, override_dir: str):
# get a list of all the files in the override dir
override_files = []
for root, dirs, files in os.walk(override_dir):
for file in files:
override_files.append(file)

for root, dirs, files in os.walk(root_dir):
for file in files:
full_path = root_dir + str(file)
executable = os.access(full_path, os.X_OK)
if executable:
log.info(f"Running update script: {full_path}")
out = subprocess.run(
[full_path],
capture_output=True,
)
if out.returncode != 0:
log.error(
f"{full_path} returned error code: {out.returncode}, program output:" # noqa: E501
)
log.error(out.stdout.decode("utf-8"))
notify(
"System Updater",
f"Error in update script: {file}, check logs for more info",
)
# check if a script overrides the update script in the root dir
if file in override_files:
run_update_script(override_dir + str(file))
# remove from the list to prevent running scripts again
override_files.remove(file)
else:
log.info(f"could not execute file {full_path}")
run_update_script(root_dir + str(file))
# run the remaining scripts in the override dir
for file in override_files:
run_update_script(override_dir + str(file))


def run_updates(system, system_update_available):
Expand All @@ -120,7 +138,8 @@ def run_updates(system, system_update_available):
fd = acquire_lock(filelock_path)
if fd is None:
raise Exception("updates are already running for this user")
root_dir = "/etc/ublue-update.d"
root_dir = "/usr/lib/ublue-update.d"
override_dir = "/etc/ublue-update.d"

"""Wait on any existing transactions to complete before updating"""
transaction_wait()
Expand All @@ -139,7 +158,7 @@ def run_updates(system, system_update_available):
if system:
users = []

run_update_scripts(f"{root_dir}/system/")
run_update_scripts(f"{root_dir}/system/", f"{override_dir}/system/")
for user in users:
try:
xdg_runtime_dir = get_xdg_runtime_dir(user["User"])
Expand Down Expand Up @@ -181,7 +200,7 @@ def run_updates(system, system_update_available):
raise Exception(
"ublue-update needs to be run as root to perform system updates!"
)
run_update_scripts(f"{root_dir}/user/")
run_update_scripts(f"{root_dir}/user/", f"{override_dir}/user/")
release_lock(fd)
os._exit(0)

Expand All @@ -197,7 +216,6 @@ def run_updates(system, system_update_available):


def main():

# setup argparse
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions src/ublue_update/update_inhibitors/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def check_battery_status() -> dict:
battery_pass: bool = True
if battery_status is not None:
battery_pass = (
battery_status.percent >= min_battery_percent or battery_status.power_plugged
battery_status.percent >= min_battery_percent
or battery_status.power_plugged
)
return {
"passed": battery_pass,
Expand All @@ -56,7 +57,6 @@ def check_mem_percentage() -> dict:


def check_hardware_inhibitors() -> bool:

hardware_inhibitors = [
check_network_status(),
check_battery_status(),
Expand Down