devuan-desktop/install_custom_uname

120 lines
4.4 KiB
Bash

#!/bin/bash
# set -x
# A HEREDOC to output a uname bash script to network with a chroot with return
# values based on the devuan arm-sdk environment at buildtime not the system
# running the chroot.
#
#
# --------------------------------
## Test variables
# kernel_version="6.3.2-1"
# kernel_version_string="#1 SMP PREEMPT_DYNAMIC Debian ${kernel_version}-${kernel_version_build} ($(date +%F))"
# uname_ostype="Linux"
# uname_os="GNU/${uname_ostype}"
# hostname="rockpro64"
# build_string="g8cce48cacf88"
# arch="amd64"
# target_arch="aarch64"
# strapdir="/space/code_repositories/decode-os/os-build-system/arm-sdk/tmp/devuan-arm64-build/bootstrap"
#-------
install_custom_uname() {
fn install_custom_uname "(override)"
req=(strapdir kernel_version kernel_version_string uname_ostype uname_os hostname build_string arch target_arch)
ckreq || return 1
# cat <<-EOF | sudo tee "$strapdir/usr/local/bin/uname" >/dev/null
cat <<-EOF | sudo tee "$strapdir/usr/local/bin/uname" >/dev/null
#! /bin/sh
set -e
datarootdir="/usr/share"
datadir="\${datarootdir}"
if [ "x\$pkgdatadir" = x ]; then
pkgdatadir="\${datadir}/grub"
fi
# export it for scripts
export pkgdatadir
. "\${pkgdatadir}/grub-mkconfig_lib"
self=\$(basename \$0)
# Print the usage.
usage () {
gettext_printf "Usage: uname [OPTION]\n" "\$self"
gettext "Print certain system information. With no OPTION, same as -s."; echo
gettext "WARNING: this is a dummy uname with hardcoded values for use in a chroot"; echo
gettext "used by devuan arm-sdk."; echo
echo
print_option_help "-a, --all=\$(gettext FILE)" "\$(gettext "print all information, in the following order,")"
print_option_help "\$(gettext " except omit -p and -i if unknown:")"
print_option_help "-s, --kernel-name=\$(gettext FILE)" "\$(gettext "print the kernel name")"
print_option_help "-n, --nodename=\$(gettext FILE)" "\$(gettext "print the network node hostname")"
print_option_help "-r, --kernel-release=\$(gettext FILE)" "\$(gettext "print the kernel release")"
print_option_help "-v, --kernel-version=\$(gettext FILE)" "\$(gettext "print the kernel version")"
print_option_help "-m, --machine=\$(gettext FILE)" "\$(gettext "print the machine hardware name")"
print_option_help "-p, --processor=\$(gettext FILE)" "\$(gettext "print the processor type \(non-portable\)")"
print_option_help "-i, --hardware-platform=\$(gettext FILE)" "\$(gettext "print the hardware platform \(non-portable\) bsd/sunos")"
print_option_help "-o, --operating-system=\$(gettext FILE)" "\$(gettext "print the operating system")"
print_option_help "-h, --help" "\$(gettext "print this message and exit")"
echo
}
# Check the arguments.
while test \$# -gt 0
do
option=\$1
shift
case "\${option}" in
-h | --help)
usage
exit 0 ;;
-a | --all)
echo "${uname_ostype} ${hostname} ${kernel_version}-${build_string} ${kernel_version_string} ${target_arch}"
exit 0 ;;
-s | --kernel-name)
echo "${uname_ostype}" # \${uname_ostype} "Linux"
exit 0 ;;
-n | --nodename)
echo "${hostname}" # \${hostname} "rockpro64"
exit 0 ;;
-r | --kernel-release)
echo "${kernel_version}-${build_string}" # \${kernel_version}-\${build_string} "4.18.8-77394-g8cce48cacf88"
exit 0 ;;
-v | --kernel-version)
echo "${kernel_version_string}" # \${kernel_version_version_string} "#1 SMP PREEMPT_DYNAMIC Debian 6.1.8-1 (2023-01-29)"
exit 0 ;;
-m | --machine)
echo "${arch}" # \${arch] "x86_64" || "arm64"
exit 0 ;;
-p | --processor)
echo "${target_arch}" # \${target_arch} aarch64 non-portable
exit 0 ;;
-i | --hardware-platform)
echo "${arch}" # \${arch} x86_64 arm64
exit 0 ;;
-o | --operating-system)
echo "${uname_os}" # \${uname_os} GNU/Linux
exit 0 ;;
-*)
gettext_printf "Unrecognized option \'%s'\n" "\$option" 1>&2
usage
exit 1 ;;
# Explicitly ignore non-option arguments, for compatibility.
esac
done
EOF
sudo chmod +x "$strapdir/usr/local/bin/uname"
}
remove_custom_uname() {
fn install_custom_uname "(override)"
req=(strapdir)
ckreq || return 1
rm "$strapdir/usr/local/bin/uname"
}
# install_custom_uname