OS Probe updated to be more robust

This commit is contained in:
kake26 2024-10-15 16:32:07 -05:00
parent 227c83867c
commit 4596e42512
Signed by: kake26
GPG key ID: E8AFC43591876B4D
2 changed files with 29 additions and 10 deletions

View file

@ -7,33 +7,52 @@
# check if apt-get is installed
echo "Checking OS.."
# step 1 check via os-release
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID_LIKE" = "debian" ]; then
tosp="Debian"
elif [ "$ID_LIKE" = "arch" ]; then
tosp="Arch"
elif [ "$ID_LIKE" = "openwrt" ]; then
tosp="Openwrt"
fi
fi
if [ -x "$(command -v apt-get)" ]; then
# set environment variable for os
osp="Debian"
rosp="Debian"
fi
# check if pacman is installed
if [ -x "$(command -v pacman)" ]; then
osp="Arch"
rosp="Arch"
fi
# check if opkg is installed
if [ -x "$(command -v opkg)" ]; then
osp="Openwrt"
rosp="Openwrt"
fi
# I know its so high tech and amazing right?
# We are going to do a double check here using lsb_release
# check /etc/os-release for the ID_LIKE value
if [ -x "$(command -v lsb_release)" ]; then
# osp=$(lsb_release -i | awk '{print $3}')
if [[ "$tosp" == "$rosp" ]]; then
echo "OS detection successful"
osp=$tosp
else
echo "Looks like $tosp, but based on the package manager its $rosp"
osp=$rosp
fi
echo "Detected OS: $osp"
sleep 3

View file

@ -1,6 +1,6 @@
#!/bin/bash
# set -x # For debugging
#set -x # For debugging
set -eo pipefail # No -u that would just bother me
trap cleanup EXIT # A little more robust cleanup