From 2abb843752c7bbe8ea7ba03643da8b55ef084da3 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 7 Sep 2023 17:42:58 +0200 Subject: [system] add --no-confirm flag to update script --- .local/bin/update | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to '.local/bin') 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) -- cgit v1.2.3