Closed RichardFevrier closed 1 month ago
@RichardFevrier
Feel free to remove lsb_release. I am of the opinion that dependencies should be minimized especially if it yields more accurate results that supports more distros (ie. Amazon Linux, etc).
I think using lowercase is a good idea and personally think that sticking with ID is better.
This is really good stuff! You are a rock star! Thanks!
@hkdb
lsb_release removed ID used
Still work in progress cause I could not easily retreive the result of cat /etc/*-release
from those last 4 distributions:
I don't want to introduce any regression so if you have access to them would you mind posting here the result?
Other than that I have changed a little bit the way to determine the base distribution name by checking if it is contained in the result of the command above. Doing so a lot more distributions will be covered.
If you watch the code you will see that I used both cat /etc/*-release
& cat /etc/*-release | grep \"^ID=\" | head -1 | cut -d '=' -f 2
when I could have obviously used only the first one. It is to keep consistency with the install.sh
script.
Here's Garuda's output when running the command in terminal:
I also cloned your repo, checked out the develop branch, and added two lines into cli/environment.go
:
id, err := exec.Command(env.Bash, "-c", "cat /etc/*-release | grep \"^ID=\" | head -1 | cut -d '=' -f 2").Output()
if err != nil {
fmt.Print(utils.ColorRed, "Unable to determine distribution... Exiting...\n\n", utils.ColorReset)
os.Exit(1)
}
fmt.Println("ID 1:", string(id)) ///////////////////// HERE
distro := string(id)
//fmt.Println("Distro:", distro)
env.Distro = distro
i, err := exec.Command(env.Bash, "-c", "cat /etc/*-release").Output()
if err != nil {
fmt.Print(utils.ColorRed, "Unable to determine base distribution... Exiting...\n\n", utils.ColorReset)
os.Exit(1)
}
fmt.Println("ID 2:", string(i)) ////////////////////// AND HERE
infos := strings.ToLower(strings.ReplaceAll(string(i), " ", ""))
and here's the output:
Truth be told, I have never tested with RHEL, Endeavour, or Amazon Linux.... So if there were regressions, I wouldn't have noticed it nor am I sure that the current user base or lack there of consists of users of these distros at all... 😅️
I am more than happy to spin up VM's but it will take some time. Maybe let's not let them be blockers from us moving forward? I feel pretty comfortable at this point as long as it works for Ubuntu, Pop, Debian, Arch, Garuda, and Fedora.
Okay, I've added your second log (the first one was already handled by //fmt.Println("Distro:", distro)
), and updated garuda
id.
Ready to be merged I guess 🙂
Actually, should we just stick with cat /etc/*-release | grep \"^ID=\" | head -1 | cut -d '=' -f 2
and do if ==
. What do we gain from using just cat /etc/*-release
and using contains instead which could potentially be less accurate?
Using cat /etc/*-release | grep \"^ID=\" | head -1 | cut -d '=' -f 2
with ==
is the best way to determine the exact distro the user is using.
Using cat /etc/*-release
with contains
is better to determine the base one without having to add every distro name in the array (a little remember of the number of linux distro based from another one here)
Again I could have used only cat /etc/*-release
and search for the ID
but I prefered to keep consistency with install.sh
script.
If/When install.sh
script is merged with the rest of the app, only using cat /etc/*-release
will be the way.
Ahhh... "contains" is better because of ID_LIKE
and hence, not needing to add as many distros into the arrays?
Exact
Thanks for great work! 😀️ Love it!
I have added a fallback to determine the current linux distribution in case where
lsb_release
is missing.Sorry for introducing
golang.org/x/text
but it was necessary to capitalize the result (I would have prefer you using only lower cases for comparisons but I respect your choice) otherwise usingstrings.Title
would have introduced a deprecated and I prefered not to do that.I love the way you've organized your code. =)
Edit: I didn't want to remove completely
lsb_release
but I can if you prefer.Edit2: Im currently testing the behavior on different distribution (thanks
distrobox
) and I have a different result on Linux Mint, LinuxMint / Linuxmint.I renew my position about using only lower cases for comparisons (or I apply Edit 1). Let me know.
Edit 3: Testing
lsb_release
onamazonlinux
returnn/a
so I am definitively for Edit 1.Edit 4: I have extracted the result of
cat /etc/*-release
from those distribs so far:result
DISTRIB_ID=Ubuntu DISTRIB_RELEASE=24.04 DISTRIB_CODENAME=noble DISTRIB_DESCRIPTION="Ubuntu 24.04 LTS" PRETTY_NAME="Ubuntu 24.04 LTS" NAME="Ubuntu" VERSION_ID="24.04" VERSION="24.04 LTS (Noble Numbat)" VERSION_CODENAME=noble ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=noble LOGO=ubuntu-logo DISTRIB_ID=Pop DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Pop!_OS 22.04 LTS" NAME="Pop!_OS" VERSION="22.04 LTS" ID=pop ID_LIKE="ubuntu debian" PRETTY_NAME="Pop!_OS 22.04 LTS" VERSION_ID="22.04" HOME_URL="https://pop.system76.com" SUPPORT_URL="https://support.system76.com" BUG_REPORT_URL="https://github.com/pop-os/pop/issues" PRIVACY_POLICY_URL="https://system76.com/privacy" VERSION_CODENAME=jammy UBUNTU_CODENAME=jammy LOGO=distributor-logo-pop-os PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" DISTRIB_ID=LinuxMint DISTRIB_RELEASE=21.3 DISTRIB_CODENAME=virginia DISTRIB_DESCRIPTION="Linux Mint 21.3 Virginia" NAME="Linux Mint" VERSION="21.3 (Virginia)" ID=linuxmint ID_LIKE="ubuntu debian" PRETTY_NAME="Linux Mint 21.3" VERSION_ID="21.3" HOME_URL="https://www.linuxmint.com/" SUPPORT_URL="https://forums.linuxmint.com/" BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/" PRIVACY_POLICY_URL="https://www.linuxmint.com/" VERSION_CODENAME=virginia UBUNTU_CODENAME=jammy Fedora release 39 (Thirty Nine) NAME="Fedora Linux" VERSION="39 (Container Image)" ID=fedora VERSION_ID=39 VERSION_CODENAME="" PLATFORM_ID="platform:f39" PRETTY_NAME="Fedora Linux 39 (Container Image)" ANSI_COLOR="0;38;2;60;110;180" LOGO=fedora-logo-icon CPE_NAME="cpe:/o:fedoraproject:fedora:39" DEFAULT_HOSTNAME="fedora" HOME_URL="https://fedoraproject.org/" DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f39/system-administrators-guide/" SUPPORT_URL="https://ask.fedoraproject.org/" BUG_REPORT_URL="https://bugzilla.redhat.com/" REDHAT_BUGZILLA_PRODUCT="Fedora" REDHAT_BUGZILLA_PRODUCT_VERSION=39 REDHAT_SUPPORT_PRODUCT="Fedora" REDHAT_SUPPORT_PRODUCT_VERSION=39 SUPPORT_END=2024-11-12 VARIANT="Container Image" VARIANT_ID=container Fedora release 39 (Thirty Nine) Fedora release 39 (Thirty Nine) NAME="Rocky Linux" VERSION="9.3 (Blue Onyx)" ID="rocky" ID_LIKE="rhel centos fedora" VERSION_ID="9.3" PLATFORM_ID="platform:el9" PRETTY_NAME="Rocky Linux 9.3 (Blue Onyx)" ANSI_COLOR="0;32" LOGO="fedora-logo-icon" CPE_NAME="cpe:/o:rocky:rocky:9::baseos" HOME_URL="https://rockylinux.org/" BUG_REPORT_URL="https://bugs.rockylinux.org/" SUPPORT_END="2032-05-31" ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9" ROCKY_SUPPORT_PRODUCT_VERSION="9.3" REDHAT_SUPPORT_PRODUCT="Rocky Linux" REDHAT_SUPPORT_PRODUCT_VERSION="9.3" Rocky Linux release 9.3 (Blue Onyx) Rocky Linux release 9.3 (Blue Onyx) Rocky Linux release 9.3 (Blue Onyx) AlmaLinux release 9.4 (Seafoam Ocelot) NAME="AlmaLinux" VERSION="9.4 (Seafoam Ocelot)" ID="almalinux" ID_LIKE="rhel centos fedora" VERSION_ID="9.4" PLATFORM_ID="platform:el9" PRETTY_NAME="AlmaLinux 9.4 (Seafoam Ocelot)" ANSI_COLOR="0;34" LOGO="fedora-logo-icon" CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos" HOME_URL="https://almalinux.org/" DOCUMENTATION_URL="https://wiki.almalinux.org/" BUG_REPORT_URL="https://bugs.almalinux.org/" ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9" ALMALINUX_MANTISBT_PROJECT_VERSION="9.4" REDHAT_SUPPORT_PRODUCT="AlmaLinux" REDHAT_SUPPORT_PRODUCT_VERSION="9.4" SUPPORT_END=2032-06-01 AlmaLinux release 9.4 (Seafoam Ocelot) AlmaLinux release 9.4 (Seafoam Ocelot) CentOS Linux release 7.9.2009 (Core) NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" CentOS Linux release 7.9.2009 (Core) CentOS Linux release 7.9.2009 (Core) Oracle Linux Server release 9.4 NAME="Oracle Linux Server" VERSION="9.4" ID="ol" ID_LIKE="fedora" VARIANT="Server" VARIANT_ID="server" VERSION_ID="9.4" PLATFORM_ID="platform:el9" PRETTY_NAME="Oracle Linux Server 9.4" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:oracle:linux:9:4:server" HOME_URL="https://linux.oracle.com/" BUG_REPORT_URL="https://github.com/oracle/oracle-linux" ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9" ORACLE_BUGZILLA_PRODUCT_VERSION=9.4 ORACLE_SUPPORT_PRODUCT="Oracle Linux" ORACLE_SUPPORT_PRODUCT_VERSION=9.4 Red Hat Enterprise Linux release 9.4 (Plow) Oracle Linux Server release 9.4 NAME="Clear Linux OS" VERSION=1 ID=clear-linux-os ID_LIKE=clear-linux-os VERSION_ID=41730 PRETTY_NAME="Clear Linux OS" ANSI_COLOR="1;35" HOME_URL="https://clearlinux.org" SUPPORT_URL="https://clearlinux.org" BUG_REPORT_URL="mailto:dev@clearlinux.discoursemail.com" PRIVACY_POLICY_URL="http://www.intel.com/privacy" BUILD_ID=41730 Amazon Linux release 2023.4.20240513 (Amazon Linux) NAME="Amazon Linux" VERSION="2023" ID="amzn" ID_LIKE="fedora" VERSION_ID="2023" PLATFORM_ID="platform:al2023" PRETTY_NAME="Amazon Linux 2023.4.20240513" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023" HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/" DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/" SUPPORT_URL="https://aws.amazon.com/premiumsupport/" BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023" VENDOR_NAME="AWS" VENDOR_URL="https://aws.amazon.com/" SUPPORT_END="2028-03-15" Amazon Linux release 2023.4.20240513 (Amazon Linux) NAME="Arch Linux" PRETTY_NAME="Arch Linux" ID=arch BUILD_ID=rolling VERSION_ID=20240101.0.204074 ANSI_COLOR="38;2;23;147;209" HOME_URL="https://archlinux.org/" DOCUMENTATION_URL="https://wiki.archlinux.org/" SUPPORT_URL="https://bbs.archlinux.org/" BUG_REPORT_URL="https://bugs.archlinux.org/" PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/" LOGO=archlinux-logo Manjaro Linux DISTRIB_ID="ManjaroLinux" DISTRIB_RELEASE="24.0.0" DISTRIB_CODENAME="Wynsdey" DISTRIB_DESCRIPTION="Manjaro Linux" Manjaro Linux NAME="Manjaro Linux" PRETTY_NAME="Manjaro Linux" ID=manjaro ID_LIKE=arch BUILD_ID=rolling ANSI_COLOR="32;1;24;144;200" HOME_URL="https://manjaro.org/" DOCUMENTATION_URL="https://wiki.manjaro.org/" SUPPORT_URL="https://forum.manjaro.org/" BUG_REPORT_URL="https://docs.manjaro.org/reporting-bugs/" PRIVACY_POLICY_URL="https://manjaro.org/privacy-policy/" LOGO=manjarolinuxI am torn between using directly the
ID
but less pretty or theNAME
with some cleaning.