diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-09-07 17:42:58 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-10-30 09:52:23 +0100 |
commit | 2abb843752c7bbe8ea7ba03643da8b55ef084da3 (patch) | |
tree | 54f450f282865f3cea3ad94be41191ede2da5879 | |
parent | 75230fda588116f514e8dcb27abd83cdc3c8bc89 (diff) |
[system] add --no-confirm flag to update script
-rwxr-xr-x | .local/bin/update | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/.local/bin/update b/.local/bin/update index fc02143..990f0cc 100755 --- a/.local/bin/update +++ b/.local/bin/update @@ -8,10 +8,16 @@ nix-channel --update && nix-env -u """ import sys, os +import argparse import subprocess from time import localtime, strftime +parser = argparse.ArgumentParser(prog = 'update') +parser.add_argument('--noconfirm', default = False, action = 'store_true') +args = parser.parse_args() + + def log(message: str): print(f'[{strftime("%H:%M:%S", localtime())}] {message}') @@ -24,20 +30,40 @@ if os.path.exists(lock_file): open(lock_file, 'a').close() -log('Running `nvim \'+PlugUpdate\'`...') -subprocess.run(['nvim', '+PlugUpdate']) +try: + commands_confirm = [ + lambda: log('Running `nvim \'+PlugUpdate\'`...'), + lambda: subprocess.run(['nvim', '+PlugUpdate']), + lambda: log('Running `sudo pacman -Syu`...'), + lambda: subprocess.run(['sudo', 'pacman', '-Syu']), + lambda: log('Running `aur sync -unr`...'), + lambda: subprocess.run(['aur', 'sync', '-unr']), + ] + + commands_noconfirm = [ + lambda: log('Running `aur sync -unr`...'), + lambda: subprocess.run(['aur', 'sync', '-unr']), + lambda: log('Running `sudo pacman -Syu`...'), + lambda: subprocess.run(['sudo', 'pacman', '-Syu', '--noconfirm']), + lambda: log('Running `nvim \'+PlugUpdate\'`...'), + lambda: subprocess.run(['nvim', '+PlugUpdate', '+qall']), + ] -log('Running `sudo pacman -Syu`...') -subprocess.run(['sudo', 'pacman', '-Syu']) + if not args.noconfirm: + for command in commands_confirm: + command() + else: + for command in commands_noconfirm: + command() -log('Running `aur sync -unr`...') -subprocess.run(['aur', 'sync', '-unr']) + log('Running `nix-channel --update`...') + subprocess.run(['nix-channel', '--update']) -log('Running `nix-channel --update`...') -subprocess.run(['nix-channel', '--update']) + log('Running `nix-env -u`...') + subprocess.run(['nix-env', '-u']) -log('Running `nix-env -u`...') -subprocess.run(['nix-env', '-u']) +except (KeyboardInterrupt): + pass log('Cleaning up...') os.remove(lock_file) |