metacall / install

Cross-platform set of script to install MetaCall infrastructure.
https://metacall.io
Apache License 2.0
13 stars 13 forks source link

Simplify `sudo` branches (install.sh script) #4

Closed viferga closed 2 months ago

viferga commented 2 years ago

The code is full of branches depending on root permissions or not, in order to use sudo, like this:

        if [ $(id -u) -eq 0 ]; then
            mkdir -p /etc/profile.d/
            echo "export PATH=\"\${PATH}:/usr/local/bin\"" > /etc/profile.d/metacall.sh
            chmod 644 /etc/profile.d/metacall.sh
        else
            echo "export PATH=\"\${PATH}:/usr/local/bin\"" | sudo tee /etc/profile.d/metacall.sh > /dev/null
            sudo mkdir -p /etc/profile.d/
            sudo chmod 644 /etc/profile.d/metacall.sh
        fi

This can be simplified if we test for root permissions at the beginning like this:

if [ $(id -u) -eq 0 ]; then
    SUDO=
else
    SUDO=sudo
fi

And the previous code would look like:

        echo "export PATH=\"\${PATH}:/usr/local/bin\"" | ${SUDO} tee /etc/profile.d/metacall.sh > /dev/null
        ${SUDO} mkdir -p /etc/profile.d/
        ${SUDO} chmod 644 /etc/profile.d/metacall.sh

Also all echos are unnecesary, we can just use tee for both cases, we have just to update the dependencies.

iamrahulmahato commented 2 years ago

Hi, I am a contributor to OpenForce 2022. I would like to work on this issue

viferga commented 2 months ago

Done. @iamrahulmahato check it out: https://github.com/metacall/install/commit/ef9cf16fabec6149ba2c9be176589d0acce09fef

Whenever you want to contribute, do it directly, there's no need to ask unless the requirements or the tasks are not clear for you. If you want to work on it, just do it.