mirror of
https://github.com/tcsenpai/PyXec.git
synced 2025-06-02 17:30:10 +00:00
Initial commit
This commit is contained in:
commit
40df0ed0d5
33
README.md
Normal file
33
README.md
Normal file
@ -0,0 +1,33 @@
|
||||
# PyXec
|
||||
## A Python to standalone binary converter
|
||||
|
||||
#### Currently supported platforms
|
||||
- MacOS (Intel & Apple Silicon)
|
||||
- Linux (theoretically all flavors)
|
||||
- *nix (not tested)
|
||||
|
||||
#### Requirements
|
||||
- bash
|
||||
- brew compatibility (auto installed)
|
||||
- terminal
|
||||
- python3 (must be callable as python3 and not python)
|
||||
- pip3 (as above)
|
||||
|
||||
### What does it do?
|
||||
|
||||
The script reads build.config file to understand which packages are needed and which files to include.
|
||||
|
||||
It then creates a script inlining all the needed data and transform it into a single executable (double click proof!).
|
||||
|
||||
### Warnings
|
||||
|
||||
The resulting executable IS NOT faster than the script, and DOES NOT obfuscate your script.
|
||||
|
||||
It is simply easier to use and more portable than forcing your customers or friends to open terminal and install stuff.
|
||||
|
||||
Also, the script installs brew, vim and shc. If you are not ok with it, well this is not your tool.
|
||||
|
||||
Last warning: due to tar.gz inlining, be aware that large files might crash the whole stuff.
|
||||
|
||||
### Usage
|
||||
Edit build.config to set your parameters, then launch build.sh and test it into builds/
|
5
build.config
Normal file
5
build.config
Normal file
@ -0,0 +1,5 @@
|
||||
package="MemorabilAI"
|
||||
script=gui.py
|
||||
include="memo.config memo.config.example sessions"
|
||||
modules="pysimplegui openai"
|
||||
forced="false"
|
171
build.sh
Executable file
171
build.sh
Executable file
@ -0,0 +1,171 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Sourcing configuration file
|
||||
. ./build.config
|
||||
|
||||
# SECTION Directory preparation
|
||||
|
||||
# Forced overwriting mode
|
||||
if [ -z "$forced" ]; then
|
||||
rm -rf data
|
||||
rm -rf dist
|
||||
rm -rf build
|
||||
mkdir data
|
||||
mkdir dist
|
||||
mkdir build
|
||||
else
|
||||
# Ask before overwriting
|
||||
if [ -z "$(ls -A build/ || echo '')" ]; then
|
||||
mkdir build
|
||||
else
|
||||
echo "WARNING: build directory already exists. Overwrite?"
|
||||
read -p "(y/N) " -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
||||
then
|
||||
rm -rf build
|
||||
mkdir build
|
||||
REPLY=""
|
||||
else
|
||||
echo "ERROR: build directory already exists"
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$(ls -A dist/ || echo '')" ]; then
|
||||
mkdir dist
|
||||
else
|
||||
echo "WARNING: dist directory already exists. Overwrite? (y/N)"
|
||||
read -p "(y/N) " -n 1 -r
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
||||
then
|
||||
rm -rf dist
|
||||
mkdir dist
|
||||
REPLY=""
|
||||
else
|
||||
echo "ERROR: dist directory already exists"
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$(ls -A data/ || echo '')" ]; then
|
||||
mkdir data
|
||||
else
|
||||
echo "WARNING: data directory already exists. Overwrite? (y/N)"
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
||||
then
|
||||
rm -rf data
|
||||
mkdir data
|
||||
REPLY=""
|
||||
else
|
||||
echo "ERROR: data directory already exists"
|
||||
exit -1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# !SECTION
|
||||
|
||||
# SECTION Data copy
|
||||
|
||||
# Copying main script
|
||||
cp $script data/
|
||||
|
||||
# If specified, copy included files
|
||||
if [ -z "$include" ]; then
|
||||
echo "[!] No includes"
|
||||
else
|
||||
for inc in $include
|
||||
do
|
||||
cp -r $inc data/
|
||||
done
|
||||
fi
|
||||
|
||||
# If specified, build modules installation part
|
||||
if [ -z "$modules" ]; then
|
||||
pipinsall="# No packages to install"
|
||||
else
|
||||
pipinstall="pip3 install"
|
||||
for mod in $modules
|
||||
do
|
||||
pipinstall=$pipinstall" "$mod
|
||||
done
|
||||
fi
|
||||
|
||||
# Move into build folder
|
||||
mv data build/
|
||||
cd build/
|
||||
|
||||
# !SECTION
|
||||
|
||||
# SECTION Inline data
|
||||
|
||||
# Compress folder
|
||||
tar -cvzf data.tar.gz data
|
||||
|
||||
# Read plain hex from gzipped data
|
||||
hexdata=$(xxd -c 10000000000 -p data.tar.gz)
|
||||
|
||||
# Just some output
|
||||
echo $hexdata
|
||||
|
||||
# !SECTION
|
||||
|
||||
# SECTION Writing the script
|
||||
|
||||
# Prepare first segment
|
||||
read -r -d '' ONE << EOM
|
||||
#!/bin/bash \n
|
||||
cd "\$(dirname "\$0")";\n
|
||||
EOM
|
||||
|
||||
# Prepare inlined section
|
||||
MIDDLE="hexdata=$hexdata;\n"
|
||||
|
||||
# Prepare last segment
|
||||
# For in depth explanation wait a day i can write proper documentation
|
||||
read -r -d '' TWO << EOM
|
||||
export NONINTERACTIVE=1;\n
|
||||
export HOMEBREW_BREW_GIT_REMOTE="...";\n
|
||||
export HOMEBREW_CORE_GIT_REMOTE="...";\n
|
||||
/bin/bash -c "\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)";\n
|
||||
|
||||
brew install vim;\n
|
||||
brew install python-tk;\n
|
||||
|
||||
echo \$hexdata | xxd -r -p > restored.tar.gz;\n
|
||||
tar -xvf restored.tar.gz
|
||||
rm -rf restored.tar.gz
|
||||
|
||||
$pipinstall
|
||||
|
||||
cd data
|
||||
|
||||
python3 $script;\n
|
||||
|
||||
rm -rf data\n
|
||||
|
||||
exit\n
|
||||
|
||||
EOM
|
||||
|
||||
# Just outputting
|
||||
echo -e $ONE
|
||||
echo -e $MIDDLE
|
||||
echo -e $TWO
|
||||
|
||||
# Writing the final script
|
||||
echo -e "$ONE\n$MIDDLE\n$TWO" > run.sh
|
||||
|
||||
# !SECTION
|
||||
|
||||
# SECTION Creating executable
|
||||
|
||||
# Making it executable
|
||||
chmod +x run.sh
|
||||
# C conversion and compilation
|
||||
shc -f run.sh
|
||||
# Cleanup
|
||||
cd ..
|
||||
mv build/run.sh.x dist/$package
|
||||
|
||||
# !SECTION
|
Loading…
x
Reference in New Issue
Block a user