shell-host/modules/host-utils.mod

78 lines
1.5 KiB
Bash

#!/bin/bash
arch () {
uname -m
}
function get_chip_type() {
local ARCH
case $(arch) in
"x86_64")
ARCH=amd64
;;
"aarch64")
ARCH=arm64
;;
"armv8")
ARCH=arm64
;;
.*386.*)
ARCH=amd32
;;
*)
ARCH=arm32
;;
esac
echo $ARCH
}
function get_platform() {
echo $(uname -s)-$(get_chip_type)
}
hostinfo () {
hostnamectl
echo -e "--------------------------"
echo kernel: $(uname -r)
echo chip architecture: $(uname -m)
echo -e "--------------------------"
cat /etc/os-release
echo -e "--------------------------"
[[ -f /etc/upstream-release/lsb-release ]] && cat /etc/upstream-release/lsb-release
}
# function get_distro() {
# source /etc/os-release
# declare distros=${@:-"arch alpine debian ubuntu"}
# # echo $ID $ID_LIKE
# for distro in $distros; do
# echo $distro $ID $ID_LIKE
# [[ $ID =~ $distro ]] && echo $distro && return 0
# [[ $ID_LIKE =~ $distro ]] && echo $distro && return 0
# done
# return 1
# }
# function get_release() {
# }
get_distro() {
local file=/etc/upstream-release/lsb-release
if [[ -f $file ]]; then
echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
return 0
else
file=/etc/os-release
if [[ -f $file ]]; then
echo $(cat $file | tr [:upper:] [:lower:] | grep -Poi '(debian|ubuntu|red hat|centos|arch|alpine)' | uniq)
fi
fi
}