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
|
#!/usr/bin/env python3
"""
sudo pacman -Syu
nix-channel --update && nix-env -u
nvim '+PlugUpdate' '+PlugClean!' '+PlugUpdate' '+qall' > /dev/null 2>&1
aur sync -unr # requires interactivity
"""
import sys, os
import subprocess
from time import localtime, strftime
def log(message: str):
print(f'[{strftime("%Y-%m-%d %H:%M:%S", localtime())}] {message}')
lock_file = 'update.lock'
if os.path.exists(lock_file):
log('Update already running')
sys.exit(0)
open(lock_file, 'a').close()
log('Starting pacman process...')
pacman_process = subprocess.Popen(['sudo', 'pacman', '-Syu', '--confirm'], stdout=subprocess.DEVNULL)
log('Starting nix process...')
nix_process = subprocess.Popen(['nix-channel', '--update'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
log('Starting nvim process...')
nvim_process = subprocess.Popen(['nvim', '+PlugUpdate', '+PlugClean!', '+PlugUpdate!', '+qall'], stdout=subprocess.DEVNULL)
nix_process.wait()
log('nix process done. Calling nix-env...')
nix_env_process = subprocess.Popen(['nix-env', '-u'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
pacman_process.wait()
log('pacman process done. Calling aur sync...')
subprocess.run(['aur', 'sync', '-unr'])
nix_env_process.wait()
log('Cleaning up...')
os.remove(lock_file)
|