Compare commits

...
42 Commits
Author SHA1 Message Date
pancake e94f9c07af Release 0.4.1 2021-09-27 00:36:56 +02:00
pancake ef703be9fe Windows installation goes directly into the bin/ 2021-09-27 00:35:23 +02:00
pancake b0c2e38ece Initial support for Windows packages 2021-09-26 23:56:35 +02:00
pancake aa4a5170cd A couple more guards for os.uname 2021-09-26 23:24:40 +02:00
pancake 01e2b5efaa Update README 2021-09-26 23:23:01 +02:00
pancake d58b97085c os.uname() doesnt exist on windows 2021-09-26 23:20:57 +02:00
pancake e15c4249a3 Do not use ansi colors on Windows 2021-09-26 23:18:19 +02:00
pancake 2a7f1893f1 Dont polute cwd 2021-09-26 23:04:06 +02:00
pancake 378adc688a Improve help message 2021-09-26 23:00:37 +02:00
pancake 092eda37ea Add support for Debian -p add,rm 2021-09-26 22:58:33 +02:00
pancake 068f103a89 Fix some more lint hints 2021-09-26 22:36:11 +02:00
pancake 6c0c26aa0b Release 0.4.0 2021-09-26 22:27:08 +02:00
pancake 29fa15b555 Add help in the readme 2021-09-26 22:26:18 +02:00
pancake fdd5602970 Fixes for the CI 2021-09-26 21:38:16 +02:00
pancake 684d6d5211 Add more packages, export PKG_CONFIG_PATH and handle R2ENV_PATH 2021-09-26 21:36:12 +02:00
pancake bf6ff7d2db Fix README 2021-09-26 21:36:05 +02:00
pancake 30e319f3fb Defaults to git when no @version is specified 2021-09-26 21:03:59 +02:00
pancake 7c948fab24 Use DYLD_LIBRARY_PATH on macOS 2021-09-26 20:56:51 +02:00
pancake b9089e9b2d Argument handling issues fixed 2021-09-26 20:49:15 +02:00
pancake 0fa2cf4a87 Add r2frida package 2021-09-26 20:43:11 +02:00
pancake 35f1c4152e latest -> git 2021-09-26 20:35:09 +02:00
pancake 7ece62f905 Add more actions and unify the arguments for handling -p rm 2021-09-26 20:34:22 +02:00
pancake 4323295829 Improve output logs when installing packages 2021-09-26 20:11:45 +02:00
pancake 444974cf0a Add purge, honor -p install, latest -> git and more 2021-09-26 20:06:47 +02:00
pancake 9b60d72a55 Fix binary package removal for macOS 2021-09-26 19:48:18 +02:00
pancake c9e7123fad Improve commandline handling 2021-09-26 19:44:35 +02:00
pancake 48ca2997e9 Initial support for binary package installation on macOS 2021-09-26 18:57:35 +02:00
pancake 57db2d1f7a Add 5.4.2 packages 2021-09-23 18:26:29 +02:00
pancake 4d03c87bf1 Add 5.4.0 2021-08-22 02:25:39 +02:00
pancake eb7dfa643a There's nothing termux-specific in here 2021-07-26 17:40:42 +02:00
murphy f8fbc50505 Update CI 2021-06-21 18:27:33 +02:00
murphy 8606f42ceb Update versioning system 2021-06-21 18:09:06 +02:00
murphy a37787570a Update ci.yml 2021-06-21 18:02:20 +02:00
murphy 58a2e071ab Update ci.yml 2021-06-21 18:01:20 +02:00
murphy 96fd4aab0a Update ci.yml 2021-06-21 17:50:35 +02:00
murphy ff9fd6fa3d Update release process 2021-06-21 17:48:45 +02:00
murphy be5154450d Update release process 2021-06-21 17:36:56 +02:00
murphy 24bfde5f9b Update gitignore 2021-06-21 15:54:29 +02:00
murphy 129e96b506 Update release files 2021-06-21 15:54:20 +02:00
pancake 26919c415a More pypi massaging 2021-06-17 19:25:40 +02:00
pancake e9e08436cb Fix make pub and sync version (#13) 2021-06-17 19:08:14 +02:00
pancake 3613127925 Fix more command parsing issues (#12) 2021-06-17 19:05:00 +02:00
13 changed files with 420 additions and 141 deletions

No files matched your search

+33 -4
View File
@@ -1,10 +1,14 @@
name: CI
on:
release:
types: [published]
push:
branches:
- master
pull_request:
branches:
- master
# schedule:
# - cron: '0 0 * * 1'
@@ -13,6 +17,7 @@ jobs:
pylint:
name: codecheck-pylint
runs-on: ubuntu-20.04
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v2
@@ -23,6 +28,7 @@ jobs:
flake8:
name: codecheck-flake8
runs-on: ubuntu-20.04
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v2
@@ -38,15 +44,38 @@ jobs:
uses: actions/checkout@v2
- name: Install
run: sudo pip install . --force-reinstall
- name: Initializing
run: r2env init
- name: Execute r2env
run: r2env list
- name: Install r2 using r2env
run: |
r2env init
r2env install radare2@latest
- name: Execute latest r2 version
[ "`r2env | wc -l`" -gt 10 ] # measure help message
[ "`r2env -l | wc -l`" -gt 6 ] # measure pkgs
r2env install radare2@git
- name: Execute git version of r2
run: |
r2env use radare2@latest
r2env use radare2@git
$HOME/.r2env/bin/r2 -v
r2env shell "r2 -v"
- name: Uninstalling
run: sudo pip uninstall -y r2env && rm -rf $HOME/.r2env
release-job:
name: Publish package
runs-on: ubuntu-20.04
needs: [integration-tests, flake8, pylint]
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/dist.txt
- name: Build
run: python setup.py sdist
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TWINE_PASSWORD }}
+5
View File
@@ -1,3 +1,8 @@
.idea
**/__pycache__/
venv
.DS_Store
AUTHORS
ChangeLog
dist/*
r2env.egg-info
+3 -1
View File
@@ -4,7 +4,9 @@ all:
pip install .
pub:
twine upload --repository-url https://upload.pypi.org/legacy/ --verbose dist/*
rm -rf dist
$(PYTHON) setup.py sdist
twine upload --repository=pypi --verbose dist/*
install:
pip install .
+60 -44
View File
@@ -1,53 +1,31 @@
r2env
=====
# r2env
[![CI](https://github.com/radareorg/r2env/actions/workflows/ci.yml/badge.svg)](https://github.com/radareorg/r2env/actions/workflows/ci.yml)
This repository contains the tool available via pip to install
and manage multiple versions of radare2 and its plugins.
Create self-contained environments with multiple versions of radare2
and plugins, make it easy to switch between them.
r2-tools doesn't conflict with r2pm in the sense that it's not
going to support all the packages and plugins and it's
r2env supports source and binary packages.
Dependencies
------------
* r2env should be self contained
Some tools may be used if installed in the system, making some
packages available, but we may try to use python-version if
possible, so it don't depend on system packages.
Package description
-------------------
INI, JSON or python class, loaded at runtime, but it is k=v stuff
* name: iaito
* platform: windows
* version: 5.2.1
* source: https://path/to/zip
Actions
-------
* install / uninstall
* link / unlink
* update - pip install -U r2env
* upgrade - upgrade r2 and all the deps in sync
* Build from source or install the system package if available.
*
How to install
--------------
## Installation
r2env is available via PIP. (`pip install r2env`)
r2env is available via PIP.
To build + install from source just run: `make`
* `pip install -U -f r2env`
Usage
-----
If you want to try it directly from source.
First of all you may want to initialize the `.r2env` directory somewhere with `cd .. ; r2env init`.
* `pip install .`
## Usage
First we need to initialize the working directory:
```
r2env init
```
Listing available packages is done via `r2env list`.
@@ -56,18 +34,56 @@ Source packages are managed with the `add`, `rm`, `use` and `unused`.
For example: Installing radare2 (assumes @git version)
```
cd /tmp
r2env init
r2env add radare2
r2env use radare2@git
r2env shell r2 -v
r2env shell "r2 -v"
```
r2pm vs r2env
-------------
## Help
```
Usage: r2env [-flags] [action] [args...]
Flags:
-h, --help - show this help
-v, --version - display r2env version
-m, --meson - use meson instead of acr
-p, --package - install the dist package instead of building
-l, --list - list available and installed packages
Actions:
init - create ~/.r2env directory
config - display current .r2env settings
add [pkg] - build and install given package. See -p and -m
use [pkg] - use r2 package defined. pkg should be a release version or git.
rm [pkg] - remove package from ~/.r2env
path - show path of current r2 in use
version - show version of r2env
versions - list installed packages
list - list all packages available to r2env
shell - enter a new shell with PATH env var set
purge - remove ~/.r2env
Environment
R2ENV_PATH - specify different path other than ~/.r2env
```
## r2pm vs r2env
r2env aims to provide a packaging for r2 with support for binary packages and for all major platforms.
r2pm focus on providing more packages, it's written in shellscript, so it doesnt run on windows and requires r2 to work.
Therefor r2env is kind of `nvm` from nodejs or `pyenv` from python. A way to run multiple different versions of r2 in the system.
This repository contains the tool available via pip to install
and manage multiple versions of radare2 and its plugins.
r2-tools doesn't conflict with r2pm in the sense that it's not
going to support all the packages and plugins and it's
+56 -8
View File
@@ -1,10 +1,37 @@
{
"radare0": {
"r2frida": {
"source": "https://github.com/nowsecure/r2frida",
"versions": [
{
"id": "git",
"packages": {}
}
]
},
"r2dec": {
"source": "https://github.com/wargio/r2dec-js",
"versions": [
{
"id": "git",
"packages": {}
}
]
},
"r2ghidra": {
"source": "https://github.com/radareorg/r2ghidra",
"versions": [
{
"id": "git",
"packages": {}
}
]
},
"r0": {
"source": "https://github.com/radareorg/r0",
"versions": [
{
"id": "latest",
"packages:": {}
"id": "git",
"packages": {}
}
]
},
@@ -13,20 +40,41 @@
"versions": [
{
"id": "5.3.0",
"packages:": {
"packages": {
"w64": "radare2-5.3.0-w64.zip",
"deb_x64": "radare2_5.3.0_amd64.deb"
}
},
{
"id": "5.3.1",
"packages:": {
"packages": {
"w64": "radare2-5.3.1-w64.zip",
"mac_x64": "radare2-5.3.1.pkg",
"deb_x64": "radare2_5.3.1_amd64.deb"
}
},
{
"id": "latest",
"packages:": {}
"id": "5.4.0",
"packages": {
"w64": "radare2-5.4.0-w64.zip",
"mac_x64": "radare2-5.4.0.pkg",
"deb_x64": "radare2_5.4.0_amd64.deb"
}
},
{
"id": "5.4.2",
"packages": {
"w32": "radare2-5.4.2-w32.zip",
"w64": "radare2-5.4.2-w64.zip",
"mac_x64": "radare2-5.4.2-amd64.pkg",
"mac_arm64": "radare2-5.4.2-m1.pkg",
"deb_i386": "radare2_5.4.2_i386.deb",
"deb_x64": "radare2_5.4.2_amd64.deb"
}
},
{
"id": "git",
"packages": {}
}
]
}
+45 -19
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import os
import re
import shutil
import json
import sys
@@ -38,43 +38,56 @@ class R2Env:
print_console("[*] Current r2env config:")
print_console(json.dumps(self._config))
def list_packages(self):
self.list_available_packages()
self.list_installed_packages()
def list_available_packages(self):
print_console("[*] List of available Radare packages")
print_console("- Available")
packages = self._package_manager.list_available_packages()
for profile in packages:
print_console(" - {} packages:".format(profile), WARNING)
print_console(" - {}:".format(profile), WARNING)
for version in packages[profile]['versions']:
print_console(" {}@{}".format(profile, version['id']), formatter=1)
dists = ", ".join(version['packages'].keys())
print_console(" - {}@{} - {}".format(profile, version['id'], dists), formatter=1)
def list_installed_packages(self):
self.exit_if_r2env_not_initialized()
print_console("[*] Installed Radare packages")
print_console("- Installed")
for pkg in self._package_manager.list_installed_packages():
if pkg == self._get_current_version():
print_console(" [*] {}".format(pkg))
print_console(" - {} (in use)".format(pkg))
else:
print_console(" - {}".format(pkg))
def install(self, package, use_meson=False):
def install(self, package, use_meson=False, use_dist=False):
self.exit_if_r2env_not_initialized()
if not self._check_package_format(package):
print_console("[x] Invalid Package format.", level=ERROR)
print_console("[x] Invalid package format.", level=ERROR)
return
profile, version = package.split('@')
self._package_manager.install_package(profile, version, use_meson=use_meson)
print_console("[*] Magic Done! Remember to add the $HOME/.r2env/bin folder to your PATH.")
try:
profile, version = package.split('@')
except:
profile = package
version = "git"
self._package_manager.install_package(profile, version, use_meson=use_meson, use_dist=use_dist)
print_console("[*] Add $HOME/.r2env/bin to your PATH or use 'r2env shell'.")
def uninstall(self, package):
def uninstall(self, package, use_meson, use_dist):
self.exit_if_r2env_not_initialized()
if not self._check_package_format(package):
print_console("[x] Invalid Package format.", level=ERROR)
print_console("[x] Invalid package format.", level=ERROR)
return
self._package_manager.uninstall_package(package)
self._package_manager.uninstall_package(package, use_dist)
def purge(self):
print("Removing " + self._r2env_path)
shutil.rmtree(self._r2env_path)
def use(self, package=None):
self.exit_if_r2env_not_initialized()
if not package:
print_console("[x] Package not defined. Please use 'r2env use' with one installed package. ", ERROR)
print_console("[x] Package not defined.", ERROR)
self.list_installed_packages()
return
cur_ver = self._get_current_version()
@@ -92,30 +105,43 @@ class R2Env:
return version.read()
def shell(self, cmd=""):
line = "export PS1=\"r2env\\$ \";export PATH=\"" + self._r2env_path + "/bin:$PATH\"; $SHELL -f"
if os.name== "nt":
os.system("set PATH="+self._r2env_path+"\\bin;%PATH% && cmd")
return True
line = "export PS1=\"r2env\\$ \";export PKG_CONFIG_PATH=\""
line = line + self._r2env_path+"/lib/pkgconfig\";export PATH=\""
line = line + self._r2env_path + "/bin:$PATH\"; $SHELL -f"
if os.path.isfile("/default.prop"): # hack for pre-dtag builds of r2
line = "export LD_LIBRARY_PATH=\"" + self._r2env_path + "/lib\";" + line
if os.uname().sysname == "Darwin":
line = "export DYLD_LIBRARY_PATH=\"" + self._r2env_path + "/lib\";" + line
if cmd.strip() == "":
return os.system(line)
print(os.system(line + " -c '" + cmd + "'"))
return os.system(line + " -c '" + cmd + "'")
@staticmethod
def _load_config():
filename = os.path.join(os.path.dirname(__file__), 'config', 'config.json')
config = load_json_file(filename)
ep = os.getenv("R2ENV_PATH")
if ep is not None:
config["r2env_path"] = ep
if not config:
sys.exit(-1)
return config
@staticmethod
def _get_default_path():
# TODO: try to find an .r2env starting in current directory
return os.path.join(Path.home(), ".r2env")
@staticmethod
def _check_package_format(package):
regexp = re.compile(r"\w+\d@(?:\d\.\d\.\d|latest)")
return regexp.match(package)
if package == "":
return True
return True
# regexp = re.compile(r"\w+\d@(?:\d\.\d\.\d|git)")
# return regexp.match(package)
def _get_current_version(self):
version_file = os.path.join(self._r2env_path, self.VERSION_FILE)
+103 -21
View File
@@ -2,11 +2,13 @@
import os
import shutil
import wget
import sys
import time
from r2env.tools import load_json_file, git_fetch, git_clean, print_console, ERROR, exit_if_not_exists
from zipfile import ZipFile
from r2env.tools import load_json_file, git_fetch, git_clean, print_console, ERROR, exit_if_not_exists, host_distname
class PackageManager:
@@ -41,7 +43,7 @@ class PackageManager:
sys.exit(-1)
return profiles
def install_package(self, profile, version, use_meson):
def install_package(self, profile, version, use_meson, use_dist):
log_path = os.path.join(self._r2env_path, self.LOG_DIR)
logfile = os.path.join(log_path, "{}_{}_{}_build.txt".format(profile, version, round(time.monotonic() * 1000)))
source_path = os.path.join(os.path.join(self._r2env_path, self.SOURCE_DIR, profile))
@@ -53,7 +55,12 @@ class PackageManager:
if not os.path.isdir(dst_dir):
os.makedirs(dst_dir)
self._exit_if_package_not_available(profile, version)
if self._build_from_source(profile, version, source_path, dst_dir, logfile, use_meson=use_meson):
if use_dist:
if self._install_from_dist(profile, version, source_path, dst_dir, logfile, use_meson=use_meson):
print_console("[*] Binary package {}@{} installed successfully".format(profile, version))
else:
print_console("Error.")
elif self._build_from_source(profile, version, source_path, dst_dir, logfile, use_meson=use_meson):
print_console("[*] Package {}@{} installed successfully".format(profile, version))
else:
print_console("[x] Something wrong happened during the build process. Check {} for more information.".format
@@ -61,23 +68,97 @@ class PackageManager:
if os.path.isdir(dst_dir):
shutil.rmtree(dst_dir)
def uninstall_package(self, package_name):
def uninstall_package(self, package_name, use_dist):
pkg_found = False
for package in self.list_installed_packages():
if package_name == package:
pkg_found = True
pkg_dir = os.path.join(os.path.join(self._r2env_path, self.PACKAGES_DIR), package_name)
try:
shutil.rmtree(pkg_dir)
print_console("Removed package {}".format(package_name))
except OSError as err:
print_console("[x] Unable to remove package {0}. Error: {1}".format(package_name, err), ERROR)
if use_dist:
kv = package.split("@")
self._uninstall_from_dist(kv[0], kv[1])
else:
pkg_dir = os.path.join(os.path.join(self._r2env_path, self.PACKAGES_DIR), package_name)
try:
shutil.rmtree(pkg_dir)
print_console("Removed package {}".format(package_name))
except OSError as err:
print_console("[x] Unable to remove package {0}. Error: {1}".format(package_name, err), ERROR)
break
if not pkg_found:
print_console("[x] Unable to find installed package {0}".format(package_name), ERROR)
def _build_from_package(self):
pass
def _get_pkgname(self, profile, version, cos):
for pkgv in self._packages[profile]["versions"]:
if pkgv["id"] == version:
for pkgd in pkgv["packages"].keys():
if pkgd == cos:
return pkgv["packages"][pkgd]
return None
def _get_disturl(self, profile, version, cos):
gh = "https://github.com/radareorg/radare2/releases/download/"
f = self._get_pkgname(profile, version, cos)
if f is not None:
return "/".join([gh, version, f])
return None
def _install_from_dist(self, profile, version, source_path, dst_path, logfile, use_meson=False):
print_console("[*] Installing {}@{} package from binary dist".format(profile, version))
dn = host_distname()
disturl = self._get_disturl(profile, version, dn)
pkgname = self._get_pkgname(profile, version, dn)
ofile = "/".join([self._r2env_path, "src", pkgname])
# os.system("wget -O " + ofile + " -qc " + disturl)
wget.download(disturl, ofile);
try:
sysname = os.uname().sysname
except:
sysname = "Windows"
# TODO: checksum
if sysname == "Darwin":
if os.system("sudo installer -pkg " + ofile + " -target /") == 0:
return True
if sysname == "Windows":
with ZipFile(ofile, 'r') as z:
z.extractall()
dst = os.path.sep.join([self._r2env_path, "bin"])
for f in z.namelist():
if f.endswith(".exe") or f.endswith(".dll") and f.find("bin") != -1:
fname = os.path.basename(f)
d = os.path.sep.join([dst, fname])
dname = os.path.dirname(d)
if not os.path.isdir(dname):
os.makedirs(dname, 493) # 0755)
shutil.copyfile(f, d)
print(f)
f = os.path.sep.join([self._r2env_path, "bin", "radare2.exe"])
d = os.path.sep.join([self._r2env_path, "bin", "r2.exe"])
shutil.copyfile(f, d)
if sysname == "Linux" and os.path.exists("/usr/bin/dpkg"):
if os.system("sudo dpkg -i " + ofile) == 0:
return True
return False
def _uninstall_from_dist(self, profile, version):
print_console("[*] Uninstalling {}@{} package from binary dist".format(profile, version))
try:
sysname = os.uname().sysname
except:
sysname = "Windows"
if sysname == "Darwin":
pkgname = "org.radare.radare2"
os.system("pkgutil --pkg-info " + pkgname)
os.system("cd / && pkgutil --only-files --files "+pkgname+" | tr '\\n' '\\0' | xargs -n 1 -0 sudo rm -f")
os.system("cd / && pkgutil --only-dirs --files "+pkgname+" | tail -r | tr '\\n' '\\0' | xargs -n 1 -0 sudo rmdir 2>/dev/null")
os.system("sudo pkgutil --forget " + pkgname)
if sysname == "Linux" and os.path.exists("/usr/bin/dpkg"):
try:
pkgname = profile.split("@")[0]
except:
pkgname = profile
if os.system("sudo dpkg -r " + pkgname) == 0:
return True
return True
def _build_from_source(self, profile, version, source_path, dst_path, logfile, use_meson=False):
exit_if_not_exists(['git'])
@@ -87,28 +168,29 @@ class PackageManager:
print_console("[-] Cleaning Repo")
git_clean(source_path)
if use_meson:
return self._build_using_meson(source_path, dst_path, logfile)
return self._build_using_acr(source_path, dst_path, logfile)
return self._build_using_meson(source_path, dst_path, logfile, self._r2env_path)
return self._build_using_acr(source_path, dst_path, logfile, self._r2env_path)
@staticmethod
def _build_using_acr(source_path, dst_path, logfile):
def _build_using_acr(source_path, dst_path, logfile, r2env_path):
"""Only works in Unix systems"""
exit_if_not_exists(['make'])
print_console("[-] Building package using acr for Termux...")
print_console("[-] Building package using acr...")
extra_flags = ""
if os.path.isfile("/default.prop"):
extra_flags = " --with-compiler=termux"
cmd = "(cd {0} && rm -rf shlr/capstone && ./configure {1}" \
cmd = "(export PKG_CONFIG_PATH=\"{4}\";cd {0} && rm -rf shlr/capstone && ./configure {1}" \
" --with-rpath --prefix={2} 2>&1 && make -j4 2>&1" \
"&& make install) > {3}".format(source_path, extra_flags, dst_path, logfile)
"&& make install) > {3}".format(source_path, extra_flags, dst_path, logfile, r2env_path + "/lib/pkgconfig")
print(cmd)
return os.system(cmd) == 0
@staticmethod
def _build_using_meson(source_path, dst_path, logfile):
def _build_using_meson(source_path, dst_path, logfile, r2env_path):
exit_if_not_exists(['meson', 'ninja'])
print_console("[-] Building package using meson ...")
cmd = "(cd {0} && rm -rf build && meson . build --buildtype=release --prefix={1} -Dlocal=true 2>&1" \
"&& ninja -C build && ninja -C build install) > {2}".format(source_path, dst_path, logfile)
cmd = "(export PKG_CONFIG_PATH=\"{4}\";cd {0} && rm -rf build && meson . build --buildtype=release --prefix={1} -Dlocal=true 2>&1" \
"&& ninja -C build && ninja -C build install) > {2}".format(source_path, dst_path, logfile,r2env_path + "/lib/pkgconfig")
return os.system(cmd) == 0
def _exit_if_package_not_available(self, profile, version):
+73 -39
View File
@@ -8,18 +8,31 @@ from r2env.core import R2Env
HELP_MESSAGE = """
Usage: r2env [action] [args...]
Usage: r2env [-flags] [action] [args...]
Flags:
-h, --help - show this help.
-v, --version - display r2env version.
-m, --meson - use meson instead of acr.
-p, --package - install the dist package instead of building
-l, --list - list available and installed packages
Actions:
init - create .r2env in current directory
config - display current .r2env settings
install [pkg] - build and install given package. Use --meson to use it as the build system.
uninstall [pkg] - remove selected package
use [pkg] - use r2 package defined. pkg should be a release version or latest.
version - show the current Radare version and its origin
versions - List all Radare versions installed
list - list all Radare packages available to r2env
shell - open a new shell with PATH env var set
init - create ~/.r2env directory.
config - display current .r2env settings.
add [pkg] - build and install given package. See -p and -m
use [pkg] - stow a specific version to be the default.
rm [pkg] - remove package from ~/.r2env
path - show path of current r2 in use.
list - list all packages available to r2env.
shell - enter a new shell with PATH env var set.
purge - remove ~/.r2env
Environment
R2ENV_PATH - specify different path other than ~/.r2env
"""
@@ -28,60 +41,81 @@ def show_help():
print_console(HELP_MESSAGE)
actions_with_argument = ["install", "uninstall", "use"]
actions_with_arguments = ["shell"]
def show_version():
print_console(R2Env().version())
actions_with_argument = ["add", "install", "rm", "uninstall"]
actions_with_arguments = ["sh", "shell", "use"]
actions = {
"init": R2Env().init,
"version": R2Env().get_r2_path,
"config": R2Env().show_config,
"list": R2Env().list_available_packages,
"install": R2Env().install,
"v": show_version,
"version": show_version,
"path": R2Env().get_r2_path,
"sh": R2Env().shell,
"shell": R2Env().shell,
"config": R2Env().show_config,
"ls": R2Env().list_packages,
"list": R2Env().list_packages,
"add": R2Env().install,
"install": R2Env().install,
"installed": R2Env().list_installed_packages,
"uninstall": R2Env().uninstall,
"rm": R2Env().uninstall,
"use": R2Env().use,
"versions": R2Env().list_installed_packages,
"purge": R2Env().purge,
"h": show_help,
"help": show_help
}
def run_action(action, args, use_meson):
if action not in actions:
print_console("[X] Action not found", ERROR)
def run_action(argp):
action = ""
args = []
if len(argp.args) > 0:
action = argp.args[0]
if len(argp.args) > 1:
args = argp.args[1:]
if argp.version:
print_console(R2Env().version())
elif argp.list:
actions["list"]()
elif action == "":
show_help()
elif action not in actions:
print_console("Invalid action", ERROR)
elif action in actions_with_arguments:
actions[action](" ".join(args))
elif action in actions_with_argument:
exit_if_not_argument_is_set(args, action)
if action == "install":
actions[action](args[0], use_meson=use_meson)
else:
actions[action](args[0])
actions[action](args[0], use_meson=argp.meson, use_dist=argp.package)
else:
actions[action]()
def exit_if_not_argument_is_set(args, action):
if len(args) < 1:
if action == "use":
print_console("[x] Package not defined. Please use 'r2env use' with one installed package. ", ERROR)
actions["versions"]()
if action in ["use", "rm", "uninstall"]:
print_console("[x] Package not defined.", ERROR)
R2Env().list_installed_packages()
else:
print_console("[x] Missing package argument. ( as for example: radare2@latest)", ERROR)
print_console("[x] Missing package argument. ( as for example: radare2@latest)", ERROR)
print_console("[x] Missing package argument.", ERROR)
R2Env().list_available_packages()
sys.exit(-1)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("action", help="run specified action. (Run r2env help for more information)",
action="store", default=["help"])
parser.add_argument('args', metavar='args', nargs='*', type=str, help='Specified arguments')
parser.add_argument("-v", "--version", help="Show r2env version", action="store_true")
parser.add_argument("-m", "--meson", help="Use meson as your build system.", action="store_true")
args = parser.parse_args()
if args.version:
print_console(R2Env().version())
return
run_action(args.action, args.args, args.meson)
parser.add_argument("args", help="run specified action. (Run r2env help for more information)",
action="store", nargs="*", default=[])
#parser.add_argument('args', metavar='args', nargs='+', type=str, help='Specified arguments')
parser.add_argument("-v", "--version", dest="version", help="Show r2env version", action="store_true")
parser.add_argument("-m", "--meson", dest="meson", help="Use meson instead of acr to compile", action="store_true")
parser.add_argument("-p", "--package", dest="package", help="Use binary package for target system if available", action="store_true")
parser.add_argument("-l", "--list", dest="list", help="List available and installed packages", action="store_true")
parser.print_help = show_help
argp = parser.parse_args()
run_action(argp)
if __name__ == "__main__":
+31 -1
View File
@@ -19,6 +19,9 @@ def print_console(msg, level=INFO, formatter=0):
tabs, color = ["", ""]
for _ in range(formatter):
tabs += " "
if os.name == 'nt':
print(tabs + msg)
return
if level == ERROR:
color = Fore.RED
elif level == WARNING:
@@ -34,13 +37,40 @@ def host_platform():
return "unix"
# TODO :improve to support all archs
def host_distname():
try:
sysname = os.uname().sysname
machine = os.uname().machine
except:
sysname = "w64"
machine = "amd64"
if sysname == "Darwin":
if machine == "x86_64":
return "mac_x64"
if machine == "arm64":
return "mac_arm64"
return None
if sysname == "Linux":
if not os.path.exists("/usr/bin/dpkg"):
return None
if machine == "x86_64":
return "deb_x64"
return "deb_i386"
if os.name == "nt":
return "w64"
if os.path.isfile("/default.prop"):
return "android"
return None
def git_fetch(url, version, source_path):
if os.path.isdir(os.path.join(source_path, ".git")):
repo = Repo(source_path)
repo.remotes.origin.pull("master")
else:
repo = Repo.clone_from(url, source_path)
if version != "latest":
if version != "git":
repo.git.checkout(version)
+1 -1
View File
@@ -1 +1 @@
0.3.0
0.4.1
+1
View File
@@ -1,3 +1,4 @@
dploy>=0.1.2
colorama>=0.4.4
wget
GitPython
+5
View File
@@ -0,0 +1,5 @@
-r build.txt
pip
pbr
setuptools
twine
+4 -3
View File
@@ -1,11 +1,12 @@
[metadata]
license_file = LICENSE
version = 0.2.2
name = r2env
author = 'pancake, murphy'
author_email = '[email protected], [email protected]'
author = pancake
# author_email = '[email protected], [email protected]'
author_email = [email protected]
description = radare2 multiple version and environment installation tool
long_description = file:README.md
long_description_content_type = text/markdown
url = https://www.radare.org/
project_urls =
Source = https://github.com/radareorg/r2env