-
Notifications
You must be signed in to change notification settings - Fork 0
/
distcompute
executable file
·122 lines (110 loc) · 2.99 KB
/
distcompute
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
# shellcheck disable=1090,2154
# Common distributed computing binaries:
# - boinc-client
# - foldingathome
#
# TODO: account for:
# - cryptocurrency miners
# - compute stuff? (ROCm, CUDA)
# - rely on rocm-smi, nvidia-smi
if systemctl is-enabled boinc-client >/dev/null; then
dist_prj=""
perm_level="sudo systemctl"
project_command=boinc-client
elif systemctl --user is-enabled foldingathome >/dev/null; then
dist_prj=""
notif="notify-send -i ~/.local/bin/i3blocks/img/[email protected] -h string:x-canonical-private-synchronous:i3bdistcompute"
project_command=foldingathome
perm_level="systemctl --user"
log="${XDG_CONFIG_HOME-$HOME/.config}/fah/log.txt"
status_command() { $notif "F@H Status" "$(tail "$log")" ;}
else
exit 1
fi
. "${XDG_CACHE_HOME-$HOME/.cache}/wal/colors.sh"
blockcolor=$color12
txtcolor=$color8
case $BLOCK_BUTTON in
1) # Left Click
status_command
;;
2) # Middle Click
if $perm_level is-active $project_command >/dev/null; then
$notif "Stopping $project_command"
$perm_level stop $project_command
$notif "$project_command stopped"
else
$notif "Starting $project_command"
$perm_level start $project_command
$notif "$project_command started"
fi
;;
3) # Right Click
xdg-open http://localhost:7396
;;
4) # Scroll Up
;;
5) # Scroll Down
;;
8) # Rear Side Button
xdg-open http://localhost:7396
;;
9) # Front Side Button
xdg-open http://localhost:7396
;;
esac
# - telescope
# - molecule
# - microscope
# - pill
# - biohazard
# - atom
get_steps_per_second()
{
cur_step=$(tail "$log" | grep -v "Web" | grep -v "WARNING" | tail -1)
cur_step_count=$(echo "$cur_step" | cut -d' ' -f2)
cur_step_seconds=$(echo "$cur_step" | cut -d' ' -f1 | awk -F':' '{print $1*60*60 + $2*60 + $3}')
prev_step=$(tail "$log" | grep -v "Web" | grep -v "WARNING" | tail -2 | head -1)
prev_step_count=$(echo "$prev_step" | cut -d' ' -f2)
prev_step_seconds=$(echo "$prev_step" | cut -d' ' -f1 | awk -F':' '{print $1*60*60 + $2*60 + $3}')
steps_per_second=$(echo "($cur_step_count - $prev_step_count)/($cur_step_seconds - $prev_step_seconds)" | bc)
block_out="$block_out $steps_per_second steps/s"
}
if [ "$project_command" = "boinc-client" ]; then
return
else
current_fah_status=$(tail -1 "$log")
case "$current_fah_status" in
*'Except'*|*'exit'*)
block_out=""
;;
*'Complete'*)
block_out="$(tail -1 "$log" | cut -d' ' -f7)"
get_steps_per_second
;;
*'Temperature'*|*'Web')
block_out="$(tail -20 "$log" | grep 'Complete' | tail -1 |
cut -d' ' -f7)"
get_steps_per_second
;;
*'checkpoint'*)
block_out=""
;;
*'Download'*)
block_out=""
;;
*'Upload'*)
block_out=""
;;
*)
block_out=""
;;
esac
fi
printf "<b><span foreground='%s' background='%s'></span>" \
"$blockcolor" "$color0"
printf "<span foreground='%s' background='%s'> %s </span>" \
"$txtcolor" "$blockcolor" "$dist_prj $block_out"
printf "<span foreground='%s' background='%s'></span></b>\n" \
"$color0" "$blockcolor"