Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy install shell script #176

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

0xlildoudou
Copy link

Hi,

I have made a simply script for install Exegol wrapper like "curl -s https://github.com/TheProgs/Exegol/install.sh | sh"

It's work for GNU/Linux Debian distro but i continue for Fedora / Alpine and Debian-Like (ex: Ubuntu)
It is created in shell script and not in bash because the shell is available by default on all GNU/Linux systems.

a debug mode is available with the -v|--verbose argument

Please note:
In its current state, it is not completely immutable and is not insensitive to breakage.
For example, if a package is not installed, the script will not install it but will say which package is missing. Similarly, it cannot be restarted cleanly in the event of a problem.

@QU35T-code
Copy link
Member

ThePorgs/Roadmap#6

@ShutdownRepo
Copy link
Member

Awesome! thank you for this pull request, we'll need some testing, and to improve a few things, but it's a great start
Let's switch this PR to draft for now while the improvements are made, on "not completely immutable and is not insensitive to breakage"

@ShutdownRepo ShutdownRepo marked this pull request as draft August 14, 2023 05:30
@ShutdownRepo ShutdownRepo changed the title feat: [#173] add base instal shell script Easy install shell script Aug 14, 2023
@0xlildoudou
Copy link
Author

Hi Team,

I have add distro integration (debian/ubuntu/fedora/alpine).
Parameter for install dependencies (--fix-install)
Help page and check if repo is already clone

@ShutdownRepo ShutdownRepo added the enhancement New feature or request label Aug 22, 2023
@QU35T-code
Copy link
Member

A few comments (cc @ShutdownRepo) :

  • Better to use pip than sources ?
  • Since a certain version of python (3.10 or 3.11) it is mandatory to create a venv to use pip right ?
  • I don't think there is a need to check docker because exegol checks it on start
  • Isn't it better to run exegol info instead of exegol install at the end of the script ?

@ShutdownRepo
Copy link
Member

ShutdownRepo commented Aug 22, 2023

Better to use pip than sources ?

iirc, source install is better as it gives more control to the wrapper. Especially for updating itself.

Since a certain version of python (3.10 or 3.11) it is mandatory to create a venv to use pip right ?

Not sure, wasn't it a new requirement made in Debian? @Dramelac do you know?

I don't think there is a need to check docker because exegol checks it on start

Indeed

Isn't it better to run exegol info instead of exegol install at the end of the script ?

Hmm not sure. This is supposed to be an install script, so it makes sense to run exegol install. On the other hand, this action takes a bit of time. @Dramelac any pref?

@QU35T-code
Copy link
Member

QU35T-code commented Aug 22, 2023

I tried on a debian with python3.11.2 via apt install python3-full python3-pip and here is the error :

root@3197674ac39a:/# python3 -m pip install exegol

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

We can use --break-system-packages but i don't know if it can cause problems :

root@3197674ac39a:/# python3 -m pip install exegol --break-system-packages                                                                            

Collecting exegol
  Downloading Exegol-4.2.5.tar.gz (2.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2/2.2 MB 23.0 MB/s eta 0:00:00

@QU35T-code
Copy link
Member

Hmm not sure. This is supposed to be an install script, so it makes sense to run exegol install. On the other hand, this action takes a bit of time. @Dramelac any pref?

The goal is to install the wrapper and not necessarily the image ? Both are ok, you choose

iirc, source install is better as it gives more control to the wrapper. Especially for updating itself.

We must then choose an installation folder and configure a venv for exegol

@0xlildoudou
Copy link
Author

@QU35T-code
You're right, it's beter to use venv with the latest version of python but i don't no if we use venv with Exegol, it breaks the tool.
I have add --break-system-packages with debian 12, do you prefer to add for python > 3.10 ?

@Dramelac
Copy link
Member

i don't no if we use venv with Exegol, it breaks the tool

No it's OK to use venv. As long as the exegol command can run directly by the user it doesn't matter.
We should use venv (no matter which python version the system is using) to keep the wrapper clean and avoid "breaking system package". But that mean add a check / an install, if the venv module is not installed yet on the host.

I have add --break-system-packages with debian 12, do you prefer to add for python > 3.10 ?

Not sure to understand the question, but the default python should be ok with a venv if needed (and the latest python version is the better)

Isn't it better to run exegol info instead of exegol install at the end of the script ?

Let's keep exegol install, it makes more sense for an install script. Running exegol info without any downloaded image nor container created is not useful at all.

Better to use pip than sources ?

That's a trick one! When using source you have more control to switch on dev branch and the wrapper can be self-updated but on the other hand, when using pip for an upgrade, the requirements will be updated too with the wrapper.
So it's hard to say, i don't know at the moment if the wrapper will be able some day to self-update automatically it's own dependencies but that's unlikely.

@0xlildoudou
Copy link
Author

Hi,

I have add venv for install Exegol.
Do you prefer to activate venv with Exegol wrapper or at the end of the installer script ?

@ShutdownRepo
Copy link
Member

A pipx install would probably better wouldn't it? What do you think @QU35T-code ?

@QU35T-code
Copy link
Member

Sure, you right, pipx can be better. We won't have any problems with the venv in this case.

pipx install exegol / pipx install git+https://github.com/ThePorgs/Exegol

@VincentSan
Copy link

It is possible to add a check on the $OSTYPE variable for installation on macOS.

if [[ "$OSTYPE" == "darwin"* ]]; then
    if command -v brew >/dev/null 2>&1; then
        PACKAGE_MANAGER="brew"
        PACKAGE_MANAGER_INSTALL="brew install -y"
    else
        echo "Homebrew isn't install."
        echo "For install Exegol, pls refert to: https://exegol.readthedocs.io/en/latest/getting-started/install.html"
        exit 1
    fi
fi

@ShutdownRepo
Copy link
Member

It is possible to add a check on the $OSTYPE variable for installation on macOS.

if [[ "$OSTYPE" == "darwin"* ]]; then
    if command -v brew >/dev/null 2>&1; then
        PACKAGE_MANAGER="brew"
        PACKAGE_MANAGER_INSTALL="brew install -y"
    else
        echo "Homebrew isn't install."
        echo "For install Exegol, pls refert to: https://exegol.readthedocs.io/en/latest/getting-started/install.html"
        exit 1
    fi
fi

Agreed

@0xlildoudou
Copy link
Author

Hi @VincentSan

I have add MacOs install with brew.

@VincentSan
Copy link

VincentSan commented Dec 25, 2023

Hi @0xlildoudou

I attempted to run the script, but it failed on macOS due to dependency issues. I found a solution, but it's not compatible with the 'sh' shell. I'm looking for a solution that works with 'sh'.

#!/bin/bash

name_dependencies=("venv" "git" "pip" "docker" "sudo" "python3")
command_dependencies=("python3 -m venv -h" "git --version" "python3 -m pip --version" "docker --version" "sudo -h" "python3 --version")

name_dependencies_ko=()

for ((i=0; i<${#name_dependencies[@]}; i++)); do
    echo "Check dependencie ${name_dependencies[i]}: ${command_dependencies[i]}"
    ${command_dependencies[i]} &> /dev/null
    if [ $? -eq 0 ]; then
        echo "Done."
    else
        echo "KO."
        name_dependencies_ko+=("${name_dependencies[i]}")
    fi
done

# Display missing dependencies
if [ ${#name_dependencies_ko[@]} -ne 0 ]; then
    echo "Missing dependencies :"
    for ((i=0; i<${#name_dependencies_ko[@]}; i++)); do
        echo "${name_dependencies_ko[i]}"
    done
else
    echo "All dependencies has been install."
fi

This solution is universal and can be used on any operating system (without Windows). It does not require a package manager.

@0xlildoudou
Copy link
Author

@VincentSan

Can you send me the dependencies error for MacOS ?

Thanks

@VincentSan
Copy link

Yes, I use verbose option.

+ shift
+ '[' 0 -gt 0 ']'
+ check_dependencies git python3 python3-venv docker sudo
+ MISSING_DEPENDENCIES=0
+ '[' 5 -gt 0 ']'
++ command -v git
+ '[' /usr/bin/git ']'
+ shift
+ '[' 4 -gt 0 ']'
++ command -v python3
+ '[' /opt/homebrew/bin/python3 ']'
+ shift
+ '[' 3 -gt 0 ']'
++ command -v python3-venv
+ '[' '' ']'
+ echo 'Missing python3-venv'
Missing python3-venv
+ '[' '' = True ']'
++ expr 0 + 1
+ MISSING_DEPENDENCIES=1
+ shift
+ '[' 2 -gt 0 ']'
++ command -v docker
+ '[' /Users/fuko/.orbstack/bin/docker ']'
+ shift
+ '[' 1 -gt 0 ']'
++ command -v sudo
+ '[' /usr/bin/sudo ']'
+ shift
+ '[' 0 -gt 0 ']'
+ '[' '' = alpine ']'
+ check_dependencies python3-pip
+ MISSING_DEPENDENCIES=0
+ '[' 1 -gt 0 ']'
++ command -v python3-pip
+ '[' '' ']'
+ echo 'Missing python3-pip'
Missing python3-pip
+ '[' '' = True ']'
++ expr 0 + 1
+ MISSING_DEPENDENCIES=1
+ shift
+ '[' 0 -gt 0 ']'
+ '[' 1 -ge 1 ']'
+ echo 'For fix missing package, add --fix-install'
For fix missing package, add --fix-install
+ exit 1

@0xlildoudou
Copy link
Author

@VincentSan

I have add python dependencies check

@VincentSan
Copy link

@0xlildoudou

Test new commit

With the new changes, I no longer meet the condition below.

if [ -f "$lsb_dist" ]; then
    if command -v brew >/dev/null 2>&1; then
        PACKAGE_MANAGER="brew"
        PACKAGE_MANAGER_INSTALL="brew install -y"
    else
        echo "Homebrew isn't install."
        echo "For install Exegol, pls refert to: https://exegol.readthedocs.io/en/latest/getting-started/install.html"
        exit 1
    fi
else
...

If you replace if [ -f "$lsb_dist" ]; then with this if [ -z "$lsb_dist" ]; then, it will work again.

The dependency check is carried out without any issues.

Suggestion for improvement

Instead of checking if sudo is available, we can check if the user has executed the installation script with root privileges :

check_root(){
    if [ "$(id -u)" -ne 0 ]; then
        echo "❌ - To execute this script, root privileges are needed. Try with 'sudo'."
        exit 1
    else
        echo "✅ - Run with root privileges."
    fi
}

I'm not sure if it's necessary to check Docker permissions in the installation script, given that they will be automatically handled by Exegol. This would simplify the script.

@0xlildoudou 0xlildoudou marked this pull request as ready for review August 26, 2024 07:14
@0xlildoudou
Copy link
Author

@ShutdownRepo @QU35T-code whats next for this MR ?

@QU35T-code
Copy link
Member

I'm not the best person for this PR, I'll let @Dramelac and @ShutdownRepo follow this PR !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easy wrapper install
5 participants