-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbosskey
More file actions
executable file
·104 lines (88 loc) · 2.6 KB
/
bosskey
File metadata and controls
executable file
·104 lines (88 loc) · 2.6 KB
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
#!/bin/bash
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2021 Jeremy Brubaker <jbru362@gmail.com>
#
# abstract: "install" packages forever
#
# Requires dialog(1) for the output and dnf(1) to get a list of packages
#
### Configurable settings {{{1
#
PERCENT_DELTA_START=10
PERCENT_DELTA=5
PERCENT_DELTA_MIN=1
TIME_MS_MIN=25
TIME_MS_MAX=100
BOX_LINES=6
BOX_COLS=65 # This should be fairly large to keep package names visible
### End configurable settings
PROGNAME=$(basename "$0")
random()
{
awk -v min="$1" -v max="$2" 'BEGIN{srand(); print int(min+rand()*(max-min+1))}'
}
get_pkg_name() { # {{{1
# Get a random letter
c=$(random 97 122) # 97-122: lowercase letter range
c=$(printf \\$(printf '%03o' $c))
# Get a random package name that starts with that letter
dnf list 2>/dev/null \
| grep -E "^$c" \
| awk '{print $1}' | shuf -n1
}
# Main {{{1
#
check_command()
{
if ! command -v $1 >/dev/null; then
return 1
fi
}
if ! check_command dialog; then
printf "Missing dialog(1). Exiting\n" >&2
exit 1
fi
if ! check_command dnf; then
printf "Missing dnf(1). Exiting\n" >&2
exit 1
fi
TMPFILE=$(mktemp "$(basename "$0").XXXXXX")
trap 'clear; rm -f "$TMPFILE"' EXIT
exec 3<>"$TMPFILE"
rm "$TMPFILE"
part=1
pkg="Preparing..."
while true; do
# Get the next package name in the background
get_pkg_name >/dev/fd/3 &
i=0
delta=$PERCENT_DELTA_START
while test $i -lt 100; do
# Send new % complete to output
echo $i
# Increase % by last change +/- PERCENT_DELTA%
delta=$(random $((delta-PERCENT_DELTA)) $((delta+PERCENT_DELTA)))
test "$delta" -lt "$PERCENT_DELTA_MIN" && delta="$PERCENT_DELTA_MIN"
i=$(( i+delta ))
# Delay a random time
time=$(random $TIME_MS_MIN $TIME_MS_MAX)
sleep $((TIME_MS_MAX / time));
done | dialog --gauge "$pkg" $BOX_LINES $BOX_COLS;
# Block for a new package name
IFS= read -r pkg </dev/fd/3
pkg="Install part $part : $pkg"
part=$(( part+1 ))
done