forked from jdpedersen1/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsysinfo.sh
executable file
·111 lines (101 loc) · 3.36 KB
/
sysinfo.sh
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
#!/usr/bin/env bash
########################## !!! IMPORTANT NOTE !!! #############################
# #
# must run script one time from terminal using ./<path/to/script> to #
# generate the sysinfo.txt file for terminal to display, also if you use #
# the list_updates portion of the script, or create any other function that #
# displays any sort of data that changes, you will want to set the script #
# to run as a cronjob to verify the correct and current information is #
# displayed. #
# #
###############################################################################
### CHECKS WHICH DISTRO YOU ARE RUNNING
distro() {
file='/etc/os-release'
if [[ -f $file && -r $file ]]; then
while IFS='=' read key value; do
if [[ $key == NAME ]]; then
printf '%s\n' "${value//\"/}"
break
fi
done < "$file"
else
printf '?'
fi
}
### CHECKS FOR INIT SYSTEM
### ADD YOUR OWN LINE IF YOU USE OTHER INIT SYSTEM
find_init() {
if pidof systemd &> /dev/null; then
printf 'SystemD'
elif [[ -f /sbin/openrc ]]; then
printf 'OpenRC'
else
file='/proc/1/comm'
if [[ -r $file ]]; then
read data < "$file"
printf '%s' "${data%% *}"
else
printf '?'
fi
fi
}
### COUNTS NUMBER OF INSTALLED PACKAGES FOR APT PACMAN AND XBPS
### ADD YOUR OWN LINE IF YOUR MANAGER IS NOT LISTED
pkg_count() {
for pkg_mgr in xbps-install apt pacman; do
type -P "$pkg_mgr" &> /dev/null || continue
case $pkg_mgr in
xbps-install)
xbps-query -l | wc -l ;;
apt)
while read abbrev _; do
[[ $abbrev == ii ]] && (( line_count++ ))
done <<< "$(dpkg -l)"
printf '%d' $line_count ;;
pacman)
readarray lines <(pacman -Q)
printf '%d' ${#lines[*]} ;;
esac
return
done
printf 'Not Found'
}
### CHECKS FOR NUMBER OF UPDATES, ONLY SET UP TO RUN ON VOID
### EDIT LINES FOR APT OR PACMAN OR ADD YOUR OWN LINES FOR OTHER MANAGERS
list_updates() {
for pkg_mgr in xbps-install apt pacman; do
type -P "$pkg_mgr" &> /dev/null || continue
#TODO: Unfinished. May need to add code for each package manager.
case $pkg_mgr in
xbps-install)
readarray lines <(xbps-install -nuM)
printf '%d' ${#lines[*]} ;;
apt)
printf '?' ;;
pacman)
printf '?' ;;
esac
return
done
printf 'Not Found'
}
### CHECKS WHICH VERSION OF ZSH IS RUNNING, CHANGE FOR BASH OR OTHER SHELLS
shell() {
if type -P bash &> /dev/null; then
bash -c "printf '%s' \"$BASH_VERSION\""
elif type -P zsh &> /dev/null; then
zsh -c "printf '%s' \"$ZSH_VERSION\""
else
printf '?'
fi
}
{
printf '[ LSB: %s ] ' "$(distro)"
printf "\n"
printf '[ Init: %s ] ' "$(find_init)"
printf "\n"
printf '[ Shell: %s ] ' "$(shell)"
printf "\n"
printf '[ PKGs: %s ]' "$(pkg_count)"
} > .local/share/sysinfo.txt