As shown in the figure, the installation of the development environment is divided into 4 steps. If your environment has already installed some parts in advance, you can skip the corresponding steps and continue the installation from the back.
Operating System:x86_64
Python:3.10 and above(openssl 1.1.1 and above)
You need to build a tool image for each tool and enable the image to use it. These steps all require Docker to provide the image and container environment. The installation of Docker is described below.
- Find the Linux version of the docker installation tutorial on the official Docker download page and operate step by step:installation tutorial;
- You need to first launch Docker when using the tools and workflows on Leviathan and testing tool/workflow availability;
- Please confirm that the version of Docker Engine you installed is 20.10.10 or higher.
Copy the following command and run it directly.
curl -O https://raw.githubusercontent.com/talentsec/lev_installation/main/lev_installation_for_centos.sh && chmod +x lev_installation_for_centos.sh && source ./lev_installation_for_centos.sh
Since the package has been removed from mirror, you need to switch the source to Steam 8. Execute the following command:
dnf --disablerepo '*' --enablerepo extras swap centos-linux-repos centos-stream-repos
dnf distro-sync
If you want to know more information, you can refer to the following link: Convert to CentOS Stream 8
After switching to Steam 8, execute the following command to install:
curl -O https://raw.githubusercontent.com/talentsec/lev_installation/main/lev_installation_for_centos.sh && chmod +x lev_installation_for_centos.sh && source ./lev_installation_for_centos.sh
Copy the following command and run it directly.
curl -O https://raw.githubusercontent.com/talentsec/lev_installation/main/lev_installation_for_debian_and_ubuntu.sh && chmod +x lev_installation_for_debian_and_ubuntu.sh && source ./lev_installation_for_debian_and_ubuntu.sh
Copy the following command and run it directly.
curl -O https://raw.githubusercontent.com/talentsec/lev_installation/main/lev_installation_for_debian_and_ubuntu.sh && chmod +x lev_installation_for_debian_and_ubuntu.sh && source ./lev_installation_for_debian_and_ubuntu.sh
According to PEP 644, python 3.10 needs the support of openssl 1.1.1 and above, so systems with lower openssl versions need to compile a new openssl environment separately.
Execute the command
openssl version
to view the version of openssl.
The installation process of openssl will be different in different systems. For details, please refer to the followings:
Installation file for Debian/Ubuntu
Python3 is the main language for writing and uploading your cybersecurity tools and workflows on Leviathan . More specifically, python 3.10+ is needed.
For example, Ubuntu20.04 uses python3.8 by default, and so it needs to be upgraded.
Linux users should upgrade the python version carefully. Do not use PPA source to install python3.10. Please manually compile the source code for installation, otherwise it will affect the operation of internal programs, such as debian series apt tool.
The installation process of python 3.10 will be different in different systems. For details, please refer to the followings:
Installation file for Debian/Ubuntu
Enter python3.10
in the terminal, and entering the execution environment of Python 3.10.4 means successful.
(optional) configure the pip source to improve the speed of domestic pip use:
# Enter the following commands into ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host = pypi.douban.com
PDM is a modern Python package manager
pdm supports PEP 582。
Extension file: What is PDM?
PDM official website: https://pdm.fming.dev/
Execute the following command to install pdm:
curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3.10 -
After PDM installation, you need to add the path of pdm to the system environment variable:
export PATH=$PATH:$HOME/.local/bin
You can temporarily add the environment variable by executing this command in the terminal, then the reboot will disappear.,You can add this command to /etc/profile, or.bashrc
,.zshrc
file.
Once PDM is installed, you can verify whether the PDM tool has been installed successfully as follows.
-
Run
$ pdm plugin add pdm-lev
After the execution is completed, return to terminal:
✔ Installation succeeds.
It means that the installation is successful. If other abnormal situations occur, please check whether the operation is performed correctly according to the previous step.
-
Next perform the second verification step:
$ mkdir tmp # Create temp folder $ cd tmp # Go to temp folder $ pdm lev new test.demo # Create a test project
After the test project is created, it will be prompted to output:
Using Python interpreter: /usr/local/bin/python3.10 (3.10) Changes are written to pyproject.toml.
At this point, it means that the test project has been created successfully.
-
Third verification step:
$ cd test.demo $ pdm add levrt
If the terminal outputs the followings, it indicates success.
Adding packages to default dependencies: levrt ✔ 🔒 Lock successful Changes are written to pdm.lock. Changes are written to pyproject.toml. Synchronizing working set with lock file: 17 to add, 0 to update, 0 to remove ✔ Install aiofiles 0.8.0 successful ✔ Install anyio 3.5.0 successful ✔ Install certifi 2021.10.8 successful ✔ Install charset-normalizer 2.0.12 successful ✔ Install idna 3.3 successful ✔ Install httpcore 0.14.7 successful ✔ Install h11 0.12.0 successful ✔ Install httpx 0.22.0 successful ✔ Install levrt 1.3.2 successful ✔ Install motor 2.5.1 successful ✔ Install mpmath 1.2.1 successful ✔ Install msgpack 1.0.3 successful ✔ Install nats-py 2.0.0 successful ✔ Install pymongo 3.12.3 successful ✔ Install rfc3986 2.0.0 successful ✔ Install sniffio 1.2.0 successful ✔ Install sympy 1.10.1 successful Installing the project as an editable package... ✔ Install lev.test.demo 0.1.0 successful 🎉 All complete!
Otherwise, the installation is not successful, please check whether you have followed the previous prompts.
After the test is successful, you can delete the
test.demo
folder.
The next step is to enable the pep582 proposal globally. As a result, when the pdm command is executed in the shell, you can press the tab key and the system will promptis automatically.
Next, you need to configure pep582 environment variables to fit your own operating system. The following commands are only examples:
$ pdm --pep582 >> ~/.bashrc # Add the pdm configuration to the end of the .bash_profile file
$ pdm completion bash > /etc/bash_completion.d/pdm.bash-completion
$ pdm config install.cache True
$ pdm --pep582 >> /etc/zsh/zprofile # Add the pdm configuration to the end of the .zprofile file
$ pdm config install.cache True
$ pdm --pep582 >> /etc/zsh/zprofile # Add the pdm configuration to the end of the .zprofile file
$ mkdir $ZSH_CUSTOM/plugins/pdm
$ pdm completion zsh > $ZSH_CUSTOM/plugins/pdm/_pdm
# Then make sure pdm plugin is enabled in ~/.zshrc
$ pdm config install.cache True
Note: Under the ~/.zshrc
, there is a line plugins=(git)
, modified to plugins=(git pdm)
.
$ pdm --pep582 >> ~/.fprofile # or in /etc/
$ pdm completion fish > ~/.config/fish/completions/pdm.fish
$ pdm config feature.install.cache True
Next, configure the IDE to support PDM. PyCharm and VSCode will be illustrated, VSCode is recommended.
Now there are not built-in support or plugins for PEP 582 in most IDEs, you have to configure your tools manually.
PDM will write and store project-wide configurations in .pdm.toml and you are recommended to add following lines in the .gitignore:
.pdm.toml
__pypackages__/
Mark __pypackages__/<major.minor>/lib
as Sources Root. Then, select as Python interpreter a Python installation with the same <major.minor>
version.
Additionally, if you want to use tools from the environment (e.g. pytest
), you have to add the __pypackages__/<major.minor>/bin
directory to the PATH variable in the corresponding run/debug configuration.
Add the following two entries to the top-level dict in .vscode/settings.json
:
{
"python.autoComplete.extraPaths": ["__pypackages__/<major.minor>/lib"],
"python.analysis.extraPaths": ["__pypackages__/<major.minor>/lib"]
}
Note: When you add <major.minor>
to the configuration, it should be replaced by your Python3 version, such as __pypackages__/3.10/lib
.
pdm-lev is a pdm component provided by the official Leviathan, which provides comprehensive support for the development.
pdm-lev does not provide an upgrade method for the time being, you need to upgrade manually:
$ pdm plugin remove pdm-lev
$ pdm plugin add pdm-lev
If you encounter the following errors while developing:
No module named 'pdm'
No module named 'levrt'
It is likely that your python environment dependencies are abnormal. Please make sure the execution environment is the same as the python environment bound to pdm.
At this point, the environment configuration is completed, start the next step