btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / by-name / de / deterministic-uname / deterministic-uname.sh
blobcb6f419b033118675dd0eedc008910838f7f4f11
1 #! @shell@
3 set -o errexit
4 set -o nounset
6 show_help() {
7 @coreutils@/bin/cat << EOF
8 Usage: uname [OPTION]...
9 Print certain system information. With no OPTION, same as -s.
11 -a, --all print all information, in the following order,
12 except omit -p and -i if unknown:
13 -s, --kernel-name print the kernel name
14 -n, --nodename print the network node hostname
15 -r, --kernel-release print the kernel release
16 -v, --kernel-version print the kernel version
17 -m, --machine print the machine hardware name
18 -p, --processor print the processor type (non-portable)
19 -i, --hardware-platform print the hardware platform (non-portable)
20 -o, --operating-system print the operating system
21 --help display this help and exit
22 --version output version information and exit
23 EOF
24 exit 0
27 # Potential command-line options.
28 version=0
29 all=0
32 kernel_name=0
33 nodename=0
34 kernel_release=0
35 kernel_version=0
36 machine=0
37 processor=0
38 hardware_platform=0
39 operating_system=0
41 # With no OPTION, same as -s.
42 if [[ $# -eq 0 ]]; then
43 kernel_name=1
46 @getopt@/bin/getopt --test > /dev/null && rc=$? || rc=$?
47 if [[ $rc -ne 4 ]]; then
48 # This shouldn't happen.
49 echo "Warning: Enhanced getopt not supported, please open an issue in nixpkgs." >&2
50 else
51 # Define all short and long options.
52 SHORT=hvsnrvmpioa
53 LONG=help,version,kernel-name,nodename,kernel-release,kernel-version,machine,processor,hardware-platform,operating-system,all
55 # Parse all options.
56 PARSED=`@getopt@/bin/getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@"`
58 eval set -- "$PARSED"
61 # Process each argument, and set the appropriate flag if we recognize it.
62 while [[ $# -ge 1 ]]; do
63 case "$1" in
64 --version)
65 version=1
67 -s|--kernel-name)
68 kernel_name=1
70 -n|--nodename)
71 nodename=1
73 -r|--kernel-release)
74 kernel_release=1
76 -v|--kernel-version)
77 kernel_version=1
79 -m|--machine)
80 machine=1
82 -p|--processor)
83 processor=1
85 -i|--hardware-platform)
86 hardware_platform=1
88 -o|--operating-system)
89 operating_system=1
91 -a|--all)
92 all=1
94 --help)
95 show_help
97 --)
98 shift
99 break
102 echo "uname: unrecognized option '$1'"
103 echo "Type 'uname --help' for a list of available options."
104 exit 1
106 esac
107 shift
108 done
111 KERNEL_NAME_VAL=@uSystem@
112 NODENAME_VAL=nixpkgs
113 KERNEL_RELEASE_VAL=@modDirVersion@
114 # #1-NixOS SMP PREEMPT_DYNAMIC Wed Dec 14 10:41:06 UTC 2022
115 KERNEL_VERSION_VAL="#1-NixOS Tue Jan 1 00:00:00 UTC 1980"
116 MACHINE_VAL=@processor@
117 PROCESSOR_VAL=unknown
118 HARDWARE_PLATFORM_VAL=unknown
119 OPERATING_SYSTEM_VAL=@operatingSystem@
122 if [[ "$version" = "1" ]]; then
123 # in case some script greps for GNU coreutils.
124 echo "uname (GNU coreutils) 9.1"
125 echo "Nixpkgs deterministic-uname"
126 exit
129 # output of the real uname from GNU coreutils
130 # Darwin:
131 # Darwin *nodename* 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:30 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8103 arm64 arm Darwin
132 # NixOS:
133 # Linux *nodename* 6.0.13 #1-NixOS SMP PREEMPT_DYNAMIC Wed Dec 14 10:41:06 UTC 2022 x86_64 GNU/Linux
134 # FreeBSD:
135 # FreeBSD *nodename* 14.0-RELEASE FreeBSD 14.0-RELEASE #0 releng/14.0-n265380-f9716eee8ab4: Fri Nov 10 05:57:23 UTC 2023 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64 amd64 AMD Ryzen 9 5950X 16-Core Processor FreeBSD
136 output=()
137 if [[ "$all" = "1" ]]; then
138 output+=("$KERNEL_NAME_VAL" "$NODENAME_VAL" "$KERNEL_RELEASE_VAL" "$KERNEL_VERSION_VAL" "$MACHINE_VAL")
139 # in help: except omit -p and -i if unknown.
140 # output+=($PROCESSOR_VAL $HARDWARE_PLATFORM_VAL)
141 output+=("$OPERATING_SYSTEM_VAL")
144 if [[ "$kernel_name" = "1" ]]; then
145 output+=("$KERNEL_NAME_VAL")
148 if [[ "$nodename" = "1" ]]; then
149 output+=("$NODENAME_VAL")
152 if [[ "$kernel_release" = "1" ]]; then
153 output+=("$KERNEL_RELEASE_VAL")
156 if [[ "$kernel_version" = "1" ]]; then
157 output+=("$KERNEL_VERSION_VAL")
160 if [[ "$machine" = "1" ]]; then
161 output+=("$MACHINE_VAL")
164 if [[ "$processor" = "1" ]]; then
165 output+=("$PROCESSOR_VAL")
168 if [[ "$hardware_platform" = "1" ]]; then
169 output+=("$HARDWARE_PLATFORM_VAL")
172 if [[ "$operating_system" = "1" ]]; then
173 output+=("$OPERATING_SYSTEM_VAL")
176 echo "${output[@]}"