-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacman-auto-update
executable file
·61 lines (47 loc) · 1.51 KB
/
pacman-auto-update
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
#!/bin/bash
# Pacman Auto Update
# Simple script to update automatically pacman packages when AFK
# Enzo Zavorski Delevatti
# @Zvorky
#___ ___,
#___\ .~´ `-,
#___\° / _ _ \.
# \° ,\`|_|''|_|´\
# ° / /) °
# (\ , , .\` |°
# `) ;`,; `,^,) ||°
# ´,´ `, ` ` |||
# \\\
# March 2024 |||
# '''
# Timing Settings
MAX_INACTIVITY=300000 # MiliSeconds - The system will be updated after this time AFK
UPDATE_COOLDOWN=10800 # Seconds - Delay to start checking again after an update
CHECK_COOLDOWN=60 # Seconds - Delay from a inactivity verification to another
# You can use another package manager too...
UPDATE_COMMAND=(sudo pacman -Syu --noconfirm)
# Get idle time from X11 or terminal
get_idle_time() {
if [ -n "$DISPLAY" ]; then
# Install xprintidle and update system if command not found
if ! command -v xprintidle &> /dev/null; then
"${UPDATE_COMMAND[@]}" xprintidle
fi
echo $(xprintidle)
else
echo $(w | awk '/tty/{print $4}')
fi
}
# Install xprintidle if command not found
if [ -n "$DISPLAY" ] && ! command -v xprintidle &> /dev/null; then
"${UPDATE_COMMAND[@]}" xprintidle
fi
# Loop Checking for Inactivity
while true; do
if (( $(get_idle_time) >= MAX_INACTIVITY )); then
"${UPDATE_COMMAND[@]}"
sleep $UPDATE_COOLDOWN
else
sleep $CHECK_COOLDOWN
fi
done