aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-03-22 23:23:49 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-03-22 23:23:49 +0100
commit657f6d2d6775968c7e269cf74a414719e7b241f4 (patch)
tree2c913abe4760cb17ab08d3d616a7004409a71531 /lib
parent01a1ed449f72740d81cda58357936639ce8b79cd (diff)
Discover some system information
Diffstat (limited to 'lib')
-rw-r--r--lib/actions/sysinfo.bash12
-rw-r--r--lib/main.bash53
2 files changed, 57 insertions, 8 deletions
diff --git a/lib/actions/sysinfo.bash b/lib/actions/sysinfo.bash
new file mode 100644
index 0000000..d0e07aa
--- /dev/null
+++ b/lib/actions/sysinfo.bash
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+RSTAR_DEPS_BIN+=(
+ awk
+)
+
+action() {
+ for key in "${!RSTAR_PLATFORM[@]}"
+ do
+ printf "%-15s %s\n" "$key" "${RSTAR_PLATFORM[$key]}"
+ done
+}
diff --git a/lib/main.bash b/lib/main.bash
index 113f2e0..da2b0ea 100644
--- a/lib/main.bash
+++ b/lib/main.bash
@@ -22,10 +22,15 @@ main() {
exit 2
fi
- # Set some global defaults
- RSTAR_TOOLS=()
- RSTAR_BACKEND=moar
- RSTAR_PREFIX="$BASEDIR"
+ # Declare some global variables
+ declare -a RSTAR_TOOLS
+ declare RSTAR_BACKEND=moar
+ declare RSTAR_PREFIX="$BASEDIR"
+ declare -A RSTAR_PLATFORM
+
+ # Figure out system details
+ debug "Discovering system information"
+ discover_system
# Source the file defining the action.
debug "Sourcing $action_path"
@@ -35,10 +40,6 @@ main() {
depcheck_bin || exit 3
depcheck_perl || exit 3
- # TODO: Figure out which OS/distro we're on, to allow for working
- # around edge-cases. Probably expose this info as RSTAR_PLATFORM, in an
- # associative array.
-
# Maintain our own tempdir
export TMPDIR="$BASEDIR/tmp"
mkdir -p -- "$TMPDIR"
@@ -72,6 +73,7 @@ Actions:
fetch Fetch all required sources.
install Install Raku on this system.
test Run tests on Raku and the bundled ecosystem modules.
+ sysinfo Show information about your system. Useful for debugging.
EOF
}
@@ -128,4 +130,39 @@ depcheck_perl() {
fi
}
+# Discover information about the system. If any bugs are reported and you want
+# more information about the system the user is running on, additional checks
+# can be added here, and the user will simply have to include the output of the
+# sysinfo command in their message to you.
+discover_system() {
+ RSTAR_PLATFORM["os"]="$(discover_system_os)"
+
+ if [[ ${RSTAR_PLATFORM[os]} == "gnu_linux" ]]
+ then
+ RSTAR_PLATFORM["distro"]="$(discover_system_distro)"
+ RSTAR_PLATFORM["kernel"]="$(discover_system_kernel)"
+ RSTAR_PLATFORM["kernel_version"]="$(discover_system_kernel_version)"
+ fi
+}
+
+discover_system_distro() {
+ awk -F= '$1 == "NAME" {print tolower($2);q}' /etc/*release
+}
+
+discover_system_kernel() {
+ printf "%s" "$(uname -s | awk '{print tolower($0)}')"
+}
+
+discover_system_kernel_version() {
+ printf "%s" "$(uname -r | awk '{print tolower($0)}')"
+}
+
+discover_system_os() {
+ if command -v uname > /dev/null
+ then
+ printf "%s" "$(uname -o | awk '{print tolower($0)}' | sed 's_[/+]_\__g')"
+ return
+ fi
+}
+
main "$@"