-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapt_scan
executable file
·99 lines (80 loc) · 2.21 KB
/
apt_scan
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
#!/usr/bin/env bash
enable ate
enable pwb
source <( pwb_sources \
ate_exit_on_error \
ate_print_formatted_table \
ate_get_index_with_key \
pwb_exit_on_error \
pwb_display_ate_table
)
# Read contents of /var/lib/dpkg/status into an ate table
read_status()
{
local table_name="$1"
local arr_name
ate get_array_name "$table_name" -v arr_name
ate_exit_on_error
local -n larray="$arr_name"
while read -r; do
larray+=( "$REPLY" )
done < /var/lib/dpkg/status
ate index_rows "$table_name"
ate_exit_on_error
}
index_package_from_status()
{
local packages_table="$1"
local status_table="$2"
local ptname
ate get_array_name "$packages_table" -v ptname
local -n ptarray="$ptname"
local -n row_type="BASH_REMATCH[1]"
local -n row_value="BASH_REMATCH[2]"
local -a cur_package=()
process_line()
{
local -n pl_row="$1"
local -i index="$2"
local -a pl_line
if [[ "$pl_row" =~ ([^[:space:]][^:]+):\ (.*) ]]; then
case "$row_type" in
Package)
if [ "${#cur_package[*]}" -gt 0 ]; then
ptarray+=( "${cur_package[@]}" )
fi
cur_package=("$row_value" "$index" "" "" )
;;
Status)
cur_package[2]="$row_value"
;;
Description)
cur_package[3]="$row_value"
;;
esac
fi
}
ate get_row_count "$status_table"
ate_exit_on_error
ate walk_rows "$status_table" process_line
ate_exit_on_error
ate index_rows "$packages_table"
ate_exit_on_error
}
ate declare status_lines 1
read_status "status_lines"
# package table has 4 columns:
# name
# index (into status_lines table)
# status
# description
ate declare ptable 4
index_package_from_status "ptable" "status_lines"
ate get_row_count "ptable" -v row_count
ate_exit_on_error
echo "There are $row_count package entries in the table"
pwb init
echo -n $'\e[?25l'
pwb_display_ate_table ptable
echo -n $'\e[?25h'
pwb restore