diff --git a/.gitignore b/.gitignore index 2eea525..9acd3a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.env \ No newline at end of file +.env +launch.sh \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 284e18c..dd7bf60 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,7 +4,7 @@ { "label": "Run Project", "type": "shell", - "command": "source ${workspaceFolder}/.deltabotenv/bin/activate && ${workspaceFolder}/.deltabotenv/bin/python ${workspaceFolder}/src/main.py", + "command": "launch.sh", "problemMatcher": [], "group": { "kind": "build", diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index f1f641a..15b6089 --- a/install.sh +++ b/install.sh @@ -1 +1,48 @@ #!/usr/bin/env bash + +# Colors +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +# Print commands +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Creating virtualenv +if ! python3 -m venv .deltabotenv; then + print_error "Python3 returnded a non-zero error code during virtualenv creation" +fi + +# Activate python vitualenv to install librairies +source .deltabotenv/bin/activate + +# Install librairies +if ! pip install discord.py; then + print_error "Pip returned a non-zero error code during installation of discord.py" + exit 1 +fi +if ! pip install python-dotenv; then + print_error "Pip returned a non-zero error code during installation of python-dotenv" + exit 1 +fi + +# Quit python virtualenv +deactivate + +# Create launch file +cat > launch.sh << 'EOF' +# Activate python vitualenv to install librairies +source .deltabotenv/bin/activate + +# Launch bot +.deltabotenv/bin/python3 src/main.py +EOF +chmod +x launch.sh + +echo -e "\nPython configuration created execute launch.sh to launch discord bot."