-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdirel.sh
executable file
·207 lines (195 loc) · 5.52 KB
/
gdirel.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/sh
# Required packages: coreutils and gawk
set -e
export verbose="false" help="true"
kernel_release() {
cat "/proc/version" | gawk "{ print(\$1, \$2, \$3); }"
}
distribution() {
if [ -f "/etc/os-release" ]
then
. "/etc/os-release"
if [ -n "${NAME}" ]
then
echo "${NAME}"
else
echo "Unknown Distribution."
fi
fi
}
# Priority: debian -> arch -> fedora -> suse
# this method is weak but fast.
packagemngr() {
if [ -d "/etc/apt" ] && [ -f "$(command -v apt)" ]
then
command -v apt
elif [ -f "/etc/pacman.conf" ] && [ -f "$(command -v pacman)" ]
then
command -v pacman
elif [ -f "/etc/dnf/dnf.conf" ] && [ -f "$(command -v dnf)" ]
then
command -v dnf
elif [ -d "/etc/zypp" ] && [ -f "$(command -v zypper)" ]
then
command -v zypper
else
echo "Unknown Package Manager."
fi
}
packages() {
case "${1}" in
("apt")
dpkg -l | head -n -5 | wc -l
;;
("pacman")
pacman -Qq | wc -l
;;
("dnf")
dnf list installed | tail -n +3 | wc -l
;;
("zypper")
zypper se --installed-only | tail -n +5 | wc -l
;;
(*)
echo "null"
;;
esac
}
desktop() {
if [ -n "${DESKTOP_SESSION}" ]
then
echo "${DESKTOP_SESSION}"
elif [ -n "${XDG_SESSION_DESKTOP}" ]
then
echo "${XDG_SESSION_DESKTOP}"
elif [ -n "${XDG_CURRENT_DESKTOP}" ]
then
echo "${XDG_CURRENT_DESKTOP}"
else
echo "Unknown Desktop Environment."
fi
}
processor() {
gawk -F ": " "/model name/ { print(\$2); exit; }" "/proc/cpuinfo"
}
corenum() {
gawk -F ": " "/model name/ { count++ } END { print(count); }" "/proc/cpuinfo"
}
while getopts :komndpcavh opt
do
case "${opt}" in
("k")
export help="false"
if "${verbose:-false}"
then
printf "Kernel Release: "
fi
kernel_release
;;
("o")
export help="false"
if "${verbose:-false}"
then
printf "Distribution Name: "
fi
distribution
;;
("m")
export help="false"
export pkgm="$(packagemngr)"
if "${verbose:-false}"
then
printf "Package Manager: "
fi
echo "${pkgm##*/}"
;;
("n")
export help="false"
export pkgm="$(packagemngr)"
if "${verbose:-false}"
then
printf "Package(s) installed via ${pkgm##*/}: "
fi
packages "${pkgm##*/}"
;;
("d")
export help="false"
if "${verbose:-false}"
then
printf "Default Desktop/Window Manager: "
fi
desktop
;;
("p")
export help="false"
if "${verbose:-false}"
then
printf "Processor: "
fi
processor
;;
("c")
export help="false"
if "${verbose:-false}"
then
printf "CPU(s): "
fi
corenum
;;
("a")
export help="false"
if "${verbose}"
then
export pkgm="$(packagemngr)"
cat <<VALL
Kernel Release: $(kernel_release)
Distribution Name: $(distribution)
Package Manager: ${pkgm##*/}
Package(s) installed via ${pkgm##*/}: $(packages "${pkgm##*/}")
Default Desktop/Window Manager: $(desktop)
Processor: $(processor)
CPU(s): $(corenum)
VALL
else
export pkgm="$(packagemngr)"
kernel_release
distribution
echo "${pkgm##*/}"
packages "${pkgm##*/}"
desktop
processor
corenum
fi
;;
("v")
if "${verbose:-false}"
then
export verbose="false"
else
export verbose="true"
fi
;;
("h")
printf "${0##*/} usage:
\t-k\tprint current kernel release.
\t-o\tprint distribution name.
\t-m\tprint current/native package manager name.
\t-n\thow many packages are installed with current/native package manager.
\t-d\tprint current desktop environment or window manager.
\t-p\tprint processor model.
\t-c\tprint the cpu have how many cores.
\t-a\tprint all informations above.
\t-v\tprint with verbose \"add header like (any: x)\".
\t-h\tprint this screen.
Pull requests are open: https://github.com/lazypwny751/gdirel \n"
exit 0
;;
(\?)
echo "\"-${OPTARG}\" is an unknown option, type \"sh ${0##*/} -h\" for more information."
;;
esac
done
if "${help}"
then
echo "If you don't know how to use it, you can start by typing \"sh ${0##*/} -va\", for more details type \"sh ${0##*/} -h\"."
fi