shell-host/modules/host-utils.mod

94 lines
2.3 KiB
Modula-2
Raw Normal View History

#!/bin/bash
arch () {
uname -m
}
get_arch () {
local arch
arch=$(uname -m)
[[ ! $arch ]] && return 1
case $arch in
x86_64) binArch='amd64' ;;
armhf) binArch='armv6' ;;
armv7) binArch='armv7' ;;
aarch64) binArch='arm64' ;;
ppc64el|ppc64le) binArch='ppc64le' ;;
s390x) binArch='s390x' ;;
.*386.*) binArch='amd32' ;;
*) return 2 ;;\
esac;
echo $binArch
}
function get_os () {
declare -l os
os=$(uname -s)
echo $os
}
function get_platform() {
echo $(get_os)-$(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
}
# function get_distro() {
# /bin/cp /etc/os-release /tmp/os-release.tmp
# if [[ $1 == "-d" ]]; then
# shift 1
# # docker run -it --name get_container_os --rm --entrypoint cat $1 /etc/os-release
# docker create --name dummy $1 > /dev/null
# docker cp -L dummy:/etc/os-release /tmp/os-release.tmp
# docker rm -f dummy > /dev/null
# # docker run -it --name get_container_os --rm --entrypoint cat $1 /etc/os-release > /tmp/container-os.tmp 2> /dev/null
# shift 1
# fi
# source /tmp/os-release.tmp
# declare valid=${@:-"alpine debian ubuntu"}
# # echo $ID $ID_LIKE
# [[ "${valid}" =~ $ID ]] && echo $ID && return 0
# [[ "${valid}" =~ $ID_LIKE ]] && echo $ID_LIKE && return 0
# return 1
# }