2022-02-21 12:42:22 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-02-23 10:23:19 -08:00
|
|
|
arch () {
|
|
|
|
uname -m
|
|
|
|
}
|
2023-02-07 13:03:18 -08:00
|
|
|
|
2023-12-14 17:29:19 -08:00
|
|
|
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
|
|
|
|
}
|
2023-02-07 13:03:18 -08:00
|
|
|
|
2023-12-14 17:29:19 -08:00
|
|
|
function get_os () {
|
|
|
|
declare -l os
|
|
|
|
os=$(uname -s)
|
|
|
|
echo $os
|
2023-02-07 13:03:18 -08:00
|
|
|
}
|
|
|
|
|
2023-02-23 10:23:19 -08:00
|
|
|
function get_platform() {
|
2023-12-14 17:29:19 -08:00
|
|
|
echo $(get_os)-$(get_chip_type)
|
2023-02-23 10:23:19 -08:00
|
|
|
|
|
|
|
}
|
2023-02-07 13:03:18 -08:00
|
|
|
|
2023-02-23 10:23:19 -08:00
|
|
|
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
|
2023-02-07 13:03:18 -08:00
|
|
|
}
|
|
|
|
|
2023-02-23 10:23:19 -08:00
|
|
|
|
2023-02-23 11:16:55 -08:00
|
|
|
# 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
|
|
|
|
# }
|
2023-02-23 10:23:19 -08:00
|
|
|
|
|
|
|
# function get_release() {
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
2023-02-23 11:16:55 -08:00
|
|
|
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
|
|
|
|
}
|
2023-12-14 17:29:19 -08:00
|
|
|
|
|
|
|
# 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
|
|
|
|
# }
|