2
# 2007-2023 (c) Vitaly Lipatov <lav@etersoft.ru>
3
# 2007-2023 (c) Etersoft
4
# 2007-2023 Public domain
6
# You can set ROOTDIR to root system dir
11
# TODO: check /etc/system-release
13
# Check for DISTRO specific file in /etc
16
#[ -n "$ROOTDIR" ] || return
17
# fill global DISTROFILE
18
DISTROFILE="$ROOTDIR/etc/$1"
22
# Has a distro file the specified word?
25
[ -n "$DISTROFILE" ] || exit 1
26
grep "$*" "$DISTROFILE" >/dev/null 2>&1
29
# copied from epm-sh-functions
30
# print a path to the command if exists in $PATH
31
if a='' which which 2>/dev/null >/dev/null ; then
32
# the best case if we have which command (other ways needs checking)
33
# TODO: don't use which at all, it is binary, not builtin shell command
36
a='' which -- "$1" 2>/dev/null
38
elif a='' type -a type 2>/dev/null >/dev/null ; then
41
a='' type -fpP -- "$1" 2>/dev/null
46
a='' type "$1" 2>/dev/null | sed -e 's|.* /|/|'
50
# check if <arg> is a real command
53
print_command_path "$1" >/dev/null
55
##########################3
60
# FIXME: works with GNU sed only
61
echo "$*" | sed 's/.*/\u&/'
66
# tr is broken in busybox (checked with OpenWrt)
67
#echo "$*" | tr "[:upper:]" "[:lower:]"
68
echo "$*" | awk '{print tolower($0)}'
73
echo "$BUG_REPORT_URL"
76
# allows x86_64/Distro/Version
79
[ -n "$DISTRNAMEOVERRIDE" ] || DISTRNAMEOVERRIDE="$1"
80
[ -n "$DISTRNAMEOVERRIDE" ] || return
82
local name="$(echo "$DISTRNAMEOVERRIDE" | sed -e 's|x86_64/||')"
83
[ "$name" = "$DISTRNAMEOVERRIDE" ] && DIST_ARCH="x86" || DIST_ARCH="x86_64"
84
DISTRIB_ID="$(echo "$name" | sed -e 's|/.*||')"
85
DISTRIB_RELEASE="$(echo "$name" | sed -e 's|.*/||')"
86
[ "$DISTRIB_ID" = "$DISTRIB_RELEASE" ] && DISTRIB_RELEASE=''
89
PRETTY_NAME="$DISTRIB_ID"
90
DISTRO_NAME="$DISTRIB_ID"
91
DISTRIB_CODENAME="$DISTRIB_RELEASE"
92
DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE"
96
# Translate DISTRIB_ID to vendor name (like %_vendor does or package release name uses), uses VENDOR_ID by default
99
[ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return
100
[ "$DISTRIB_ID" = "ALTServer" ] && echo "alt" && return
101
[ "$DISTRIB_ID" = "MOC" ] && echo "alt" && return
102
[ "$DISTRIB_ID" = "MESh" ] && echo "alt" && return
103
[ "$DISTRIB_ID" = "AstraLinuxSE" ] && echo "astra" && return
104
[ "$DISTRIB_ID" = "AstraLinuxCE" ] && echo "astra" && return
105
[ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return
106
[ "$DISTRIB_ID" = "TinyCoreLinux" ] && echo "tcl" && return
107
[ "$DISTRIB_ID" = "VoidLinux" ] && echo "void" && return
108
[ "$DISTRIB_ID" = "ManjaroLinux" ] && echo "manjaro" && return
109
[ "$DISTRIB_ID" = "OpenSUSE" ] && echo "suse" && return
110
[ "$DISTRIB_ID" = "openSUSETumbleweed" ] && echo "suse" && return
111
[ "$DISTRIB_ID" = "openSUSELeap" ] && echo "suse" && return
112
if [ -n "$VENDOR_ID" ] ; then
113
[ "$VENDOR_ID" = "altlinux" ] && echo "alt" && return
117
tolower "$DISTRIB_ID"
120
# TODO: in more appropriate way
121
#which pkcon 2>/dev/null >/dev/null && info "You can run $ PMTYPE=packagekit epm to use packagekit backend"
123
# Print package manager (need DISTRIB_ID, DISTRIB_RELEASE vars)
130
echo "apt-rpm" && return
133
echo "pacman" && return
136
echo "apt-dpkg" && return
140
# FIXME: some problems with multibased distros (Server Edition on CentOS and Desktop Edition on Ubuntu)
145
Ubuntu|Debian|Mint|OSNovaLinux|AstraLinux*|Elbrus)
147
#which aptitude 2>/dev/null >/dev/null && CMD=aptitude-dpkg
148
#is_command snappy && CMD=snappy
158
is_command yum && CMD="yum-rpm"
159
is_command dnf && CMD="dnf-rpm"
161
#[ "$DISTRIB_ID/$DISTRIB_RELEASE" = "ROSA/2020" ] && CMD="urpm-rpm"
163
FreeBSD|NetBSD|OpenBSD|Solaris)
165
is_command pkg && CMD=pkgng
170
ArchLinux|ManjaroLinux)
173
Fedora|CentOS|OracleLinux|RockyLinux|AlmaLinux|RHEL|RELS|Scientific|GosLinux|Amzn|RedOS)
175
is_command dnf || CMD="yum-rpm"
176
[ "$DISTRIB_ID/$DISTRIB_RELEASE" = "CentOS/7" ] && CMD="yum-rpm"
181
SUSE|SLED|SLES|openSUSETumbleweed|openSUSELeap)
184
ForesightLinux|rPathLinux)
188
is_command winget && echo "winget" && return
189
is_command appget && CMD="appget"
190
is_command choco && CMD="choco"
191
is_command npackdcl && CMD="npackd"
207
# TODO: CMD="termux-pkg"
222
if is_command "rpm" && [ -s /var/lib/rpm/Name ] || [ -s /var/lib/rpm/rpmdb.sqlite ] ; then
223
is_command "apt-get" && [ -d /var/lib/apt ] && echo "apt-rpm" && return
224
is_command "zypper" && echo "zypper-rpm" && return
225
is_command "dnf" && echo "dnf-rpm" && return
226
is_command "yum" && echo "yum-rpm" && return
227
is_command "urpmi" && echo "urpm-rpm" && return
230
if is_command "dpkg" && [ -s /var/lib/dpkg/status ] ; then
231
is_command "apt" && echo "apt-dpkg" && return
232
is_command "apt-get" && echo "apt-dpkg" && return
235
echo "pkgmanager(): We don't support yet DISTRIB_ID $DISTRIB_ID (VENDOR_ID $VENDOR_ID)" >&2
241
# Print pkgtype (need DISTRIB_ID var)
247
echo "pkg.tar.xz" && return
251
# TODO: try use generic names
253
freebsd) echo "tbz" ;;
254
sunos) echo "pkg.gz" ;;
255
slackware|mopslinux) echo "tgz" ;;
256
archlinux|manjaro) echo "pkg.tar.xz" ;;
257
gentoo) echo "tbz2" ;;
258
windows) echo "exe" ;;
259
android) echo "apk" ;;
260
alpine) echo "apk" ;;
261
tinycorelinux) echo "tcz" ;;
262
voidlinux) echo "xbps" ;;
263
openwrt) echo "ipk" ;;
264
cygwin) echo "tar.xz" ;;
265
solus) echo "eopkg" ;;
267
case $(pkgmanager) in
280
echo "$DISTRIB_CODENAME"
285
echo "$DISTRIB_CODENAME"
290
# get first variable and print it out, drop quotes if exists
291
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//" | sed -e "s/^[\'\"]\(.*\)[\'\"]/\1/"
297
echo "$1" | sed -e "s/\..*//g"
318
"Red Hat Enterprise Linux Server")
321
"ROSA Fresh"*|"ROSA Desktop Fresh"*)
324
"ROSA Chrome Desktop")
327
"MOS Desktop"|"MOS Panel")
330
"ROSA Enterprise Linux Desktop")
333
"ROSA Enterprise Linux Server")
338
#firstupper "$1" | sed -e "s/ //g" -e 's|(.*||'
339
echo "$1" | sed -e "s/ //g" -e 's|(.*||'
347
echo "$1" | sed -e "s|\..*||"
353
echo "$1" | sed -e "s|^\([^.][^.]*\.[^.][^.]*\)\..*|\1|"
359
echo "$1" | sed -e "s|^\([^.][^.]*\.[^.][^.]*\.[^.][^.]*\)\..*|\1|"
369
DISTRIB_FULL_RELEASE=""
370
DISTRIB_RELEASE_ORIG=""
375
# Default detection by /etc/os-release
376
# https://www.freedesktop.org/software/systemd/man/os-release.html
377
if distro os-release ; then
378
# shellcheck disable=SC1090
381
DISTRIB_ID="$(normalize_name "$NAME")"
382
DISTRIB_RELEASE_ORIG="$VERSION_ID"
383
DISTRIB_RELEASE="$VERSION_ID"
384
[ -n "$DISTRIB_RELEASE" ] || DISTRIB_RELEASE="CUR"
385
[ "$BUILD_ID" = "rolling" ] && DISTRIB_RELEASE="rolling"
386
[ -n "$BUG_REPORT_URL" ] || BUG_REPORT_URL="$HOME_URL"
391
ubuntu|reld|rhel|astra|manjaro)
394
[ -n "$ID_LIKE" ] && VENDOR_ID="$(echo "$ID_LIKE" | cut -d" " -f1)"
397
DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE"
398
DISTRIB_CODENAME="$VERSION_CODENAME"
400
elif distro lsb-release ; then
401
DISTRIB_ID=$(cat $DISTROFILE | get_var DISTRIB_ID)
402
DISTRO_NAME=$(cat $DISTROFILE | get_var DISTRIB_ID)
403
DISTRIB_RELEASE="$(cat $DISTROFILE | get_var DISTRIB_RELEASE)"
404
DISTRIB_RELEASE_ORIG="$DISTRIB_RELEASE"
405
DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE"
406
DISTRIB_CODENAME=$(cat $DISTROFILE | get_var DISTRIB_CODENAME)
407
PRETTY_NAME=$(cat $DISTROFILE | get_var DISTRIB_DESCRIPTION)
410
DISTRIB_RELEASE=$(normalize_version2 "$DISTRIB_RELEASE")
411
[ -n "$DISTRIB_CODENAME" ] || DISTRIB_CODENAME=$DISTRIB_RELEASE
416
DISTRIB_RELEASE=$(normalize_version1 "$DISTRIB_RELEASE_ORIG")
417
case "$DISTRIB_ID" in
418
"ALTServer"|"ALTSPWorkstation"|"Sisyphus")
421
DISTRIB_ID="ALTLinux"
426
DISTRIB_RELEASE=$(normalize_version2 "$DISTRIB_RELEASE_ORIG" | sed -e 's|_.*||')
427
DISTRIB_FULL_RELEASE=$(normalize_version3 "$DISTRIB_RELEASE_ORIG" | sed -e 's|_.*||')
428
if [ "$VARIANT" = "orel" ] || [ "$VARIANT" = "Orel" ] ; then
429
DISTRIB_ID="AstraLinuxCE"
431
DISTRIB_ID="AstraLinuxSE"
433
if [ "$DISTRIB_ID" = "AstraLinuxSE" ] ; then
434
local fr="$(cat /etc/astra_version 2>/dev/null)"
435
[ -n "$fr" ] && echo "$fr" | grep -q "$DISTRIB_RELEASE" && DISTRIB_FULL_RELEASE="$fr"
442
echo "$VERSION" | grep -q "c9.* branch" && DISTRIB_RELEASE="c9"
443
echo "$VERSION" | grep -q "c9f1 branch" && DISTRIB_RELEASE="c9f1"
444
echo "$VERSION" | grep -q "c9f2 branch" && DISTRIB_RELEASE="c9f2"
445
echo "$VERSION" | grep -q "c9f3 branch" && DISTRIB_RELEASE="c9f3"
446
DISTRIB_CODENAME="$DISTRIB_RELEASE"
447
# FIXME: fast hack for fallback: 10.1 -> p10 for /etc/os-release
448
if echo "$DISTRIB_RELEASE" | grep -q "^0" ; then
449
DISTRIB_RELEASE="Sisyphus"
450
DISTRIB_CODENAME="$DISTRIB_RELEASE"
451
elif echo "$DISTRIB_RELEASE" | grep -q "^[0-9]" && echo "$DISTRIB_RELEASE" | grep -q -v "[0-9][0-9][0-9]" ; then
452
DISTRIB_CODENAME="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||')"
453
# TODO: change p10 to 10
454
DISTRIB_RELEASE="$DISTRIB_CODENAME"
458
DISTRIB_ID="ALTLinux"
459
DISTRIB_CODENAME="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||')"
460
# TODO: change p10 to 10
461
DISTRIB_RELEASE="$DISTRIB_CODENAME"
464
DISTRIB_ID="ALTLinux"
465
case "$DISTRIB_RELEASE_ORIG" in
469
DISTRIB_RELEASE="c9f1"
472
DISTRIB_RELEASE="c9f2"
475
DISTRIB_RELEASE="c9f3"
478
[ -n "$ALT_BRANCH_ID" ] && DISTRIB_RELEASE="$ALT_BRANCH_ID"
479
DISTRIB_CODENAME="$DISTRIB_RELEASE"
480
# DISTRIB_RELEASE=$(echo $DISTRIB_RELEASE | sed -e "s/\..*//g")
483
DISTRIB_ID="ALTLinux"
484
DISTRIB_RELEASE="Sisyphus"
485
DISTRIB_CODENAME="$DISTRIB_RELEASE"
487
"ROSA"|"MOSDesktop"|"MOSPanel")
488
DISTRIB_FULL_RELEASE="$DISTRIB_CODENAME"
489
DISTRIB_CODENAME="$DISTRIB_RELEASE"
494
[ -n "$DISTRIB_ID" ] && [ -n "$DISTRIB_RELEASE" ] && return
497
# check via obsoleted ways
500
if distro altlinux-release ; then
501
DISTRIB_ID="ALTLinux"
502
# FIXME: fast hack for fallback: 10 -> p10 for /etc/os-release
503
DISTRIB_RELEASE="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||' -e 's|^pp|p|')"
504
if has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
505
elif has "ALT p10.* p10 " ; then DISTRIB_RELEASE="p10"
506
elif has "ALTServer 10." ; then DISTRIB_RELEASE="p10"
507
elif has "ALTServer 9." ; then DISTRIB_RELEASE="p9"
508
elif has "ALT c10.* c10 " ; then DISTRIB_RELEASE="c10"
509
elif has "ALT p9.* p9 " ; then DISTRIB_RELEASE="p9"
510
elif has "ALT 9 SP " ; then DISTRIB_RELEASE="c9"
511
elif has "ALT c9f1" ; then DISTRIB_RELEASE="c9f1"
512
elif has "ALT MED72 " ; then DISTRIB_RELEASE="p8"
513
elif has "ALT 8 SP " ; then DISTRIB_RELEASE="c8"
514
elif has "ALT c8.2 " ; then DISTRIB_RELEASE="c8.2"
515
elif has "ALT c8.1 " ; then DISTRIB_RELEASE="c8.1"
516
elif has "ALT c8 " ; then DISTRIB_RELEASE="c8"
517
elif has "ALT .*8.[0-9]" ; then DISTRIB_RELEASE="p8"
518
elif has "Simply Linux 10." ; then DISTRIB_RELEASE="p10"
519
elif has "Simply Linux 9." ; then DISTRIB_RELEASE="p9"
520
elif has "Simply Linux 8." ; then DISTRIB_RELEASE="p8"
521
elif has "Simply Linux 7." ; then DISTRIB_RELEASE="p7"
522
elif has "Simply Linux 6." ; then DISTRIB_RELEASE="p6"
523
elif has "ALT Linux p8" ; then DISTRIB_RELEASE="p8"
524
elif has "ALT Linux 8." ; then DISTRIB_RELEASE="p8"
525
elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7"
526
elif has "ALT Linux 7." ; then DISTRIB_RELEASE="p7"
527
elif has "ALT Linux t7." ; then DISTRIB_RELEASE="t7"
528
elif has "ALT Linux 6." ; then DISTRIB_RELEASE="p6"
529
elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6"
530
elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5"
531
elif has "ALT Linux 5.1" ; then DISTRIB_RELEASE="5.1"
532
elif has "ALT Linux 5.0" ; then DISTRIB_RELEASE="5.0"
533
elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1"
534
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0"
535
elif has "starter kit" ; then DISTRIB_RELEASE="Sisyphus"
536
elif has Citron ; then DISTRIB_RELEASE="2.4"
538
PRETTY_NAME="$(cat /etc/altlinux-release)"
539
DISTRIB_CODENAME="$DISTRIB_RELEASE"
540
DISTRO_NAME="$DISTRIB_ID"
541
DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE"
543
elif distro gentoo-release ; then
545
MAKEPROFILE=$(readlink $ROOTDIR/etc/portage/make.profile 2>/dev/null) || MAKEPROFILE=$(readlink $ROOTDIR/etc/make.profile)
546
DISTRIB_RELEASE=$(basename $MAKEPROFILE)
547
echo $DISTRIB_RELEASE | grep -q "[0-9]" || DISTRIB_RELEASE=$(basename "$(dirname $MAKEPROFILE)") #"
549
elif distro slackware-version ; then
550
DISTRIB_ID="Slackware"
551
DISTRIB_RELEASE="$(grep -Eo '[0-9]+\.[0-9]+' $DISTROFILE)"
553
elif distro os-release && is_command tce-ab ; then
554
# shellcheck disable=SC1090
555
. $ROOTDIR/etc/os-release
556
DISTRIB_ID="TinyCoreLinux"
557
DISTRIB_RELEASE="$VERSION_ID"
559
elif distro os-release && is_command xbps-query ; then
560
# shellcheck disable=SC1090
561
. $ROOTDIR/etc/os-release
562
DISTRIB_ID="VoidLinux"
563
DISTRIB_RELEASE="Live"
565
# TODO: use standart /etc/os-release or lsb
566
elif distro arch-release ; then
567
DISTRIB_ID="ArchLinux"
568
DISTRIB_RELEASE="rolling"
571
elif distro mcst_version ; then
573
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g") #"
576
elif distro openwrt_release ; then
578
DISTRIB_RELEASE=$(cat $ROOTDIR/etc/openwrt_version)
581
elif distro debian_version ; then
583
DISTRIB_RELEASE=$(cat $DISTROFILE | sed -e "s/\..*//g")
587
elif distro SuSe-release || distro SuSE-release ; then
589
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "VERSION" | sed -e "s|^VERSION = ||g")
590
if has "SUSE Linux Enterprise Desktop" ; then
592
elif has "SUSE Linux Enterprise Server" ; then
596
# fixme: can we detect by some file?
597
elif [ "$(uname)" = "FreeBSD" ] ; then
600
DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g") #"
602
# fixme: can we detect by some file?
603
elif [ "$(uname)" = "SunOS" ] ; then
605
DISTRIB_RELEASE=$(uname -r)
607
# fixme: can we detect by some file?
608
elif [ "$(uname -s 2>/dev/null)" = "Darwin" ] ; then
610
DISTRIB_RELEASE=$(uname -r)
613
elif [ "$(uname)" = "Linux" ] && is_command guix ; then
614
DISTRIB_ID="GNU/Linux/Guix"
615
DISTRIB_RELEASE=$(uname -r)
618
elif [ "$(uname)" = "Linux" ] && [ -x $ROOTDIR/system/bin/getprop ] ; then
620
DISTRIB_RELEASE=$(getprop | awk -F": " '/build.version.release/ { print $2 }' | tr -d '[]')
622
elif [ "$(uname -o 2>/dev/null)" = "Cygwin" ] ; then
624
DISTRIB_RELEASE="all"
631
tolower "$(uname $1)" | tr -d " \t\r\n"
636
for i in /lib/x86_64-linux-gnu /lib64 /lib/i386-linux-gnu /lib ; do
637
[ -x "$ROOTDIR$i/libc.so.6" ] && $ROOTDIR$i/libc.so.6 | head -n1 | grep "version" | sed -e 's|.*version ||' -e 's|\.$||' && return
645
DIST_OS="$(get_uname -s)"
659
'freebsd' | 'openbsd' | 'netbsd')
669
[ -n "$DIST_ARCH" ] && return 0
670
# Resolve the architecture
671
DIST_ARCH="$(get_uname -m)"
673
'ia32' | 'i386' | 'i486' | 'i586' | 'i686')
685
'powermacintosh' | 'power' | 'powerpc' | 'power_pc' | 'ppc64')
688
'pa_risc' | 'pa-risc')
701
# TODO: use uname only
702
# uses binutils package
703
if is_command readelf && [ -z "$(readelf -A /proc/self/exe | grep Tag_ABI_VFP_args)" ] ; then
715
local arch="$(get_arch)"
729
local arch="$(get_arch)"
749
DIST_BIT="$(getconf LONG_BIT 2>/dev/null)"
750
if [ -n "$DIST_BIT" ] ; then
755
# Try detect arch size by arch name
756
case "$(get_uname -m)" in
757
'amd64' | 'ia64' | 'x86_64' | 'ppc64')
766
# 'pa_risc' | 'pa-risc') # Are some of these 64bit? Least not all...
769
'sun4u' | 'sparcv9') # Are all sparcs 64?
775
*) # In any other case default to 32
782
# TODO: check before calc
786
local DIST_OS="$(get_base_os_name)"
789
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
792
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
795
[ -r /proc/meminfo ] && detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
798
detected=$(prtconf | grep Memory | sed -e "s|Memory size: \([0-9][0-9]*\) Megabyte.*|\1|") #"
801
# fatal "Unsupported OS $DIST_OS"
804
[ -n "$detected" ] || detected=0
810
[ -n "$DISTRIB_RELEASE" ] && echo $DISTRIB_ID/$DISTRIB_RELEASE || echo $DISTRIB_ID
816
local DIST_OS="$(get_base_os_name)"
819
detected=$(a= sysctl hw.ncpu | awk '{print $2}')
822
detected=$(grep -c "^processor" /proc/cpuinfo)
825
detected=$(a= prtconf | grep -c 'cpu[^s]')
828
detected=$(a= lsdev -Cc processor -S A | wc -l)
831
# fatal "Unsupported OS $DIST_OS"
834
[ -n "$detected" ] || detected=0
840
cat /proc/cpuinfo | grep "cpu MHz" | head -n1 | cut -d':' -f2 | cut -d' ' -f2 | cut -d'.' -f1
847
if is_command systemd-detect-virt ; then
848
VIRT="$(systemd-detect-virt)"
849
[ "$VIRT" = "none" ] && echo "(host system)" && return
850
[ -z "$VIRT" ] && echo "(unknown)" && return
851
echo "$VIRT" && return
854
# TODO: use virt-what under root
856
# inspired by virt_what
857
if [ -d "/proc/vz" -a ! -d "/proc/bc" ]; then
858
echo "openvz" && return
861
if [ -r "/sys/bus/xen" ] ; then
866
if LC_ALL=C a= lscpu | grep "Hypervisor vendor:" | grep -q "KVM" ; then
871
# TODO: check for openvz
874
get_init_process_name()
876
[ ! -f /proc/1/comm ] && echo "(unknown)" && return 1
877
cat /proc/1/comm | head -n1
878
#ps --no-headers -o comm 1
881
# https://unix.stackexchange.com/questions/196166/how-to-find-out-if-a-system-uses-sysv-upstart-or-systemd-initsystem
884
[ -d /run/systemd/system ] && echo "systemd" && return
886
#[ -d /usr/share/upstart ] && echo "upstart" && return
887
is_command systemctl && [ "$(get_init_process_name)" = 'systemd' ] && echo "systemd" && return
888
[ -d /etc/init.d ] && echo "sysvinit" && return
889
get_init_process_name
892
filter_duplicated_words()
894
echo "$*" | xargs -n1 echo | uniq | xargs -n100 echo
899
if [ -z "$PRETTY_NAME" ] ; then
900
PRETTY_NAME="$DISTRIB_ID $DISTRIB_RELEASE"
903
if ! echo "$PRETTY_NAME" | grep -q "$DISTRIB_FULL_RELEASE" ; then
904
PRETTY_NAME="$PRETTY_NAME ($DISTRIB_FULL_RELEASE)"
907
if ! echo "$PRETTY_NAME" | grep -q "$DISTRIB_RELEASE" ; then
908
PRETTY_NAME="$PRETTY_NAME ($DISTRIB_RELEASE)"
911
echo "$(filter_duplicated_words "$PRETTY_NAME")"
917
[ -n "$BUILD_ID" ] && [ "$DISTRIB_FULL_RELEASE" != "$BUILD_ID" ] && orig=" (orig. $BUILD_ID)"
919
[ -n "$EPMVERSION" ] && EV="(EPM version $EPMVERSION) "
921
distro_info v$PROGVERSION $EV: Copyright © 2007-2024 Etersoft
923
Pretty name (--pretty): $(print_pretty_name)
924
(--distro-name / --distro-version): $DISTRO_NAME / $DISTRIB_FULL_RELEASE$orig
925
Base distro name (-d) / version (-v): $(print_name_version)
926
Vendor distro name (-s) / Repo name (-r): $(pkgvendor) / $(print_repo_name)
927
Package manager/type (-g/-p): $(pkgmanager) / $(pkgtype)
928
Base OS name (-o) / CPU arch (-a): $(get_base_os_name) $(get_arch)
929
CPU norm register size (-b): $(get_bit_size) bit
930
Virtualization (-i): $(get_virt)
931
CPU Cores/MHz (-c/-z): $(get_core_count) / $(get_core_mhz) MHz
932
System memory size (-m): $(get_memory_size) MiB
933
Running service manager (-y): $(get_service_manager)
934
Bug report URL (--bug-report-url): $(print_bug_report_url)
936
(run with -h to get help)
942
echo "distro_info v$PROGVERSION - distro information retriever"
943
echo "Usage: distro_info [options] [SystemName/Version]"
945
echo " -h | --help - this help"
946
echo " -a - print hardware architecture (use --distro-arch for distro depended arch name)"
947
echo " -b - print size of arch bit (32/64)"
948
echo " -c - print number of CPU cores"
949
echo " -i - print virtualization type"
950
echo " -m - print system memory size (in MB)"
951
echo " -y|--service-manager - print running service manager"
952
echo " -z - print current CPU MHz"
953
echo " --glibc-version - print system glibc version"
955
echo " -d|--base-distro-name - print distro id (short distro name)"
956
echo " -e - print full name of distro with version"
957
echo " -o | --os-name - print base OS name"
958
echo " -p | --package-type - print type of the packaging system (f.i., apt-dpkg)"
959
echo " -g - print name of the packaging system (f.i., deb)"
960
echo " -s|-n|--vendor-name - print name of the distro family (vendor name) (ubuntu for all Ubuntu family, alt for all ALT family) (see _vendor macros in rpm)"
961
echo " --pretty|--pretty-name - print pretty distro name"
962
echo " -v | --base-version - print version of the distro"
963
echo " --distro-name - print distro name"
964
echo " --distro-version - print full version of the distro"
965
echo " --full-version - print full version of the distro"
966
echo " --codename (obsoleted) - print distro codename (focal for Ubuntu 20.04)"
967
echo " -r|--repo-name - print repository name (focal for Ubuntu 20.04)"
968
echo " --build-id - print a string uniquely identifying the system image originally used as the installation base"
969
echo " -V - print the utility version"
970
echo "Run without args to print all information."
973
# print code for eval with names for eepm
977
# -d | --base-distro-name
978
DISTRNAME="$(echo $DISTRIB_ID)"
980
DISTRVERSION="$(echo "$DISTRIB_RELEASE")"
981
# distro dependent arch
982
DISTRARCH="$(get_distro_arch)"
984
BASEDISTRNAME=$(pkgvendor)
986
DISTRREPONAME=$(print_repo_name)
989
SYSTEMARCH="$(get_arch)"
990
# -y | --service-manager
991
DISTRCONTROL="$(get_service_manager)"
993
PMTYPE="$(pkgmanager)"
997
DISTRMEMORY="$(get_memory_size)"
1000
PKGVENDOR=$(pkgvendor)
1001
RPMVENDOR=$(pkgvendor)
1007
override_distrib "$DISTRNAMEOVERRIDE"
1009
if [ -n "$*" ] ; then
1015
override_distrib "$lastarg"
1017
set -- "${@:1:$(($#-1))}"
1022
# if without override
1023
if [ -z "$DISTRIB_ID" ] ; then
1025
[ -n "$DISTRIB_ID" ] || DISTRIB_ID="Generic"
1028
if [ -z "$1" ] ; then
1033
while [ -n "$1" ] ; do
1045
--pretty|--pretty-name)
1057
-d|--base-distro-name)
1067
if [ -n "$DIST_ARCH" ] ; then
1098
echo "$DISTRIB_RELEASE"
1100
--full-version|--distro-version)
1101
echo "$DISTRIB_FULL_RELEASE"
1104
print_bug_report_url
1106
-s|-n|--vendor-name)
1109
-y|--service-manager)
1123
echo "Unsupported option $1" >&2
1124
# print empty line in any case