├── LICENSE ├── README.md └── ubuntu-22.04.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2022 Jesse.Trade 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jesse stack installer scripts for Ubuntu 2 | 3 | Bash scripts used to install the following stack for running Jesse on fresh Ubuntu installations: 4 | 5 | - Python >= `3.11` for Ubuntu 22.04 LTS 6 | - PostgreSQL >= `13` 7 | - Redis >= `5` 8 | - pip >= `21.0.1` 9 | - Oh My Zsh 10 | - Screen 11 | 12 | ## Installation 13 | 14 | Make sure your Ubuntu installation is fresh and execute the appropriate command for your release. 15 | 16 | For Ubuntu 22.04 LTS: 17 | 18 | ```sh 19 | source <(curl -fsSL https://raw.githubusercontent.com/jesse-ai/stack-installer/master/ubuntu-22.04.sh) 20 | ``` 21 | 22 | ### Screen usage 23 | 24 | `screen` is a must-have for using Jesse's live trade on a remote server. It is used to keep the terminal session alive so you don't have to keep your terminal app (and computer) open all the time! 25 | 26 | ```sh 27 | sudo apt-get install -y screen 28 | ``` 29 | 30 | You can read more about how to use `screen` at [this blog post](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-screen-on-an-ubuntu-cloud-server), but below commands are all that you need: 31 | 32 | ```sh 33 | # create and attach to a new screen window 34 | screen -S name_of_the_window 35 | 36 | # list all open screens 37 | screen -ls 38 | 39 | # reattach to a previously opened window 40 | screen -r name_of_the_window 41 | ``` 42 | -------------------------------------------------------------------------------- /ubuntu-22.04.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################# 4 | # Jesse AI Installation Script 5 | # Supported Systems: Ubuntu 22.04 LTS 6 | # Version: 2.0 7 | # Last Updated: 2024-12-01 8 | # 9 | # Requirements: 10 | # - Ubuntu 22.04 or 24.04 11 | # - Root access 12 | # - Minimum 2GB RAM 13 | # 14 | # Usage: 15 | # 1. Save this script as install-jesse.sh 16 | # 2. Make it executable: chmod +x install-jesse.sh 17 | # 3. Run as root: sudo ./install-jesse.sh 18 | # 19 | # This script will: 20 | # - Install Python 3.11 and required dependencies 21 | # - Set up PostgreSQL database 22 | # - Install and configure Redis 23 | # - Install TA-Lib 24 | # - Install and configure Jesse 25 | # - Set up shell environment (bash and zsh) 26 | ############################################# 27 | 28 | # Error handling functions 29 | log_error() { 30 | local timestamp=$(date '+%Y-%m-%d %H:%M:%S') 31 | echo "[ERROR] ${timestamp} - $1" >&2 32 | echo "[ERROR] ${timestamp} - $1" >> "${LOG_FILE}" 33 | echo "Check the logs at ${LOG_FILE} for details" 34 | } 35 | 36 | log_info() { 37 | local timestamp=$(date '+%Y-%m-%d %H:%M:%S') 38 | echo "[INFO] ${timestamp} - $1" 39 | echo "[INFO] ${timestamp} - $1" >> "${LOG_FILE}" 40 | } 41 | 42 | check_command() { 43 | if ! command -v "$1" &> /dev/null; then 44 | log_error "Failed to install $1" 45 | exit 1 46 | fi 47 | } 48 | 49 | # Trap errors 50 | set -eE 51 | trap 'log_error "Script failed on line $LINENO"' ERR 52 | 53 | # Log directory setup 54 | LOG_DIR="/var/log/jesse" 55 | LOG_FILE="${LOG_DIR}/jesse_install.log" 56 | mkdir -p ${LOG_DIR} 57 | 58 | # Logging setup 59 | exec 1> >(tee -a "${LOG_FILE}") 60 | exec 2>&1 61 | 62 | # Define variables 63 | PYTHON_VERSION=3.11 64 | PYTHON_CMD="python${PYTHON_VERSION}" 65 | PIP_CMD="${PYTHON_CMD} -m pip" 66 | VENV_PATH="/opt/jesse_env" 67 | JESSE_PATH="/opt/jesse" 68 | start=$(date +%s) 69 | 70 | # Check if running as root 71 | if [ "$EUID" -ne 0 ]; then 72 | log_error "Please run as root" 73 | exit 1 74 | fi 75 | 76 | # Version detection and validation 77 | UBUNTU_VERSION=$(lsb_release -rs) 78 | if [[ "$UBUNTU_VERSION" != "22.04" && "$UBUNTU_VERSION" != "24.04" ]]; then 79 | log_error "This script is for Ubuntu 22.04 or 24.04. Detected version: $UBUNTU_VERSION" 80 | exit 1 81 | fi 82 | 83 | log_info "Detected Ubuntu version: $UBUNTU_VERSION" 84 | 85 | # Version-specific warnings 86 | if [[ "$UBUNTU_VERSION" == "24.04" ]]; then 87 | log_info "Note: Using Ubuntu 24.04. Some package versions may be newer than in documentation." 88 | log_info "Package versions will be logged for reference." 89 | fi 90 | 91 | # System requirements check 92 | total_memory=$(free -m | awk '/^Mem:/{print $2}') 93 | if [ $total_memory -lt 2048 ]; then 94 | log_error "Insufficient memory. Minimum 2GB RAM required, detected: ${total_memory}MB" 95 | exit 1 96 | fi 97 | 98 | # System updates and base dependencies 99 | log_info "Updating Ubuntu system packages..." 100 | apt-get -y update || log_error "Failed to update package list" 101 | apt-get -y upgrade || log_error "Failed to upgrade packages" 102 | apt-get -y dist-upgrade || log_error "Failed to perform distribution upgrade" 103 | 104 | # Install basic dependencies 105 | log_info "Installing basic dependencies..." 106 | apt-get -y install gcc binutils build-essential software-properties-common \ 107 | wget curl git || log_error "Failed to install build essentials" 108 | 109 | # Python installation 110 | log_info "Installing Python ${PYTHON_VERSION}..." 111 | add-apt-repository ppa:deadsnakes/ppa -y || log_error "Failed to add Python repository" 112 | apt-get update -y || log_error "Failed to update after adding Python repository" 113 | apt-get install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-dev \ 114 | python${PYTHON_VERSION}-venv || log_error "Failed to install Python" 115 | 116 | # Verify Python installation 117 | installed_python_version=$(${PYTHON_CMD} --version) 118 | if [[ ! "$installed_python_version" =~ "Python ${PYTHON_VERSION}" ]]; then 119 | log_error "Python ${PYTHON_VERSION} installation failed. Got: $installed_python_version" 120 | exit 1 121 | fi 122 | log_info "Python ${PYTHON_VERSION} installed successfully" 123 | 124 | # Set up virtual environment 125 | log_info "Setting up virtual environment at ${VENV_PATH}..." 126 | mkdir -p ${VENV_PATH} || log_error "Failed to create virtual environment directory" 127 | ${PYTHON_CMD} -m venv ${VENV_PATH} || log_error "Failed to create virtual environment" 128 | source ${VENV_PATH}/bin/activate || log_error "Failed to activate virtual environment" 129 | 130 | # Verify virtual environment 131 | if [[ $(which python3) != ${VENV_PATH}* ]]; then 132 | log_error "Virtual environment not properly activated" 133 | exit 1 134 | fi 135 | 136 | # Install core Python packages 137 | log_info "Installing core Python packages..." 138 | python3 -m pip install numpy==1.23.0 Cython || log_error "Failed to install core Python packages" 139 | 140 | # PostgreSQL version based on Ubuntu version 141 | if [[ "$UBUNTU_VERSION" == "24.04" ]]; then 142 | PG_VERSION="15" 143 | else 144 | PG_VERSION="13" 145 | fi 146 | 147 | # Install PostgreSQL 148 | log_info "Installing PostgreSQL ${PG_VERSION}..." 149 | sh -c "echo 'deb https://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main' > /etc/apt/sources.list.d/pgdg.list" || \ 150 | log_error "Failed to add PostgreSQL repository" 151 | wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - || \ 152 | log_error "Failed to add PostgreSQL key" 153 | apt-get update -y || log_error "Failed to update package list" 154 | apt-get install -y postgresql-${PG_VERSION} postgresql-contrib python3-psycopg2 libpq-dev || \ 155 | log_error "Failed to install PostgreSQL" 156 | 157 | # Configure PostgreSQL 158 | log_info "Configuring PostgreSQL..." 159 | sudo -u postgres psql -c "CREATE DATABASE jesse_db;" || log_error "Failed to create database" 160 | sudo -u postgres psql -c "CREATE USER jesse_user WITH PASSWORD 'password';" || log_error "Failed to create database user" 161 | sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE jesse_db TO jesse_user;" || log_error "Failed to grant privileges" 162 | 163 | # Verify PostgreSQL 164 | if ! systemctl is-active --quiet postgresql; then 165 | log_error "PostgreSQL service is not running" 166 | exit 1 167 | fi 168 | log_info "PostgreSQL configured successfully" 169 | 170 | # Install Redis 171 | log_info "Installing Redis..." 172 | apt-get install -y redis-server || log_error "Failed to install Redis" 173 | systemctl enable redis-server || log_error "Failed to enable Redis service" 174 | systemctl start redis-server || log_error "Failed to start Redis service" 175 | 176 | # Verify Redis 177 | if ! systemctl is-active --quiet redis-server; then 178 | log_error "Redis service is not running" 179 | exit 1 180 | fi 181 | redis-cli ping > /dev/null || log_error "Redis is not responding" 182 | log_info "Redis installed and running" 183 | 184 | # Install Screen 185 | log_info "Installing Screen..." 186 | apt-get install -y screen || log_error "Failed to install Screen" 187 | check_command screen 188 | 189 | # Install Jesse and dependencies 190 | log_info "Installing Jesse..." 191 | python3 -m pip install --no-cache-dir -r https://raw.githubusercontent.com/jesse-ai/jesse/master/requirements.txt || \ 192 | log_error "Failed to install Jesse requirements" 193 | python3 -m pip install --no-cache-dir jesse || log_error "Failed to install Jesse" 194 | 195 | # Verify Jesse installation 196 | python3 -c "import jesse; print(f'Jesse version: {jesse.__version__}')" || log_error "Jesse import failed" 197 | log_info "Jesse installed successfully" 198 | 199 | # Install Oh My Zsh and shell configuration 200 | log_info "Installing Oh My Zsh..." 201 | apt-get install -y git zsh || log_error "Failed to install git and zsh" 202 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended || \ 203 | log_error "Failed to install Oh My Zsh" 204 | 205 | # Create and configure Jesse directories 206 | mkdir -p ${JESSE_PATH}/config || log_error "Failed to create Jesse config directory" 207 | chown -R $SUDO_USER:$SUDO_USER ${JESSE_PATH} || log_error "Failed to set Jesse directory permissions" 208 | 209 | # Create dedicated environment file 210 | cat > ${JESSE_PATH}/config/jesse_env << EOL || log_error "Failed to create environment file" 211 | export JESSE_ENV="production" 212 | export JESSE_PATH="${JESSE_PATH}" 213 | export VIRTUAL_ENV="${VENV_PATH}" 214 | export PATH="\${VIRTUAL_ENV}/bin:\${PATH}" 215 | EOL 216 | 217 | # Configure both shells (zsh and bash) 218 | for rcfile in ~/.zshrc ~/.bashrc; do 219 | cp ${rcfile} ${rcfile}.backup-$(date +%Y%m%d) || log_error "Failed to backup ${rcfile}" 220 | cat >> ${rcfile} << EOL || log_error "Failed to update ${rcfile}" 221 | # Jesse Configuration 222 | if [ -f ${JESSE_PATH}/config/jesse_env ]; then 223 | source ${JESSE_PATH}/config/jesse_env 224 | source ${VENV_PATH}/bin/activate 225 | fi 226 | EOL 227 | done 228 | 229 | git clone https://github.com/jesse-ai/project-template /opt/jesse/my-bot 230 | 231 | # Cleanup 232 | log_info "Cleaning up..." 233 | rm -f ta-lib-0.4.0-src.tar.gz || log_error "Failed to remove TA-Lib archive" 234 | rm -rf ta-lib || log_error "Failed to remove TA-Lib directory" 235 | 236 | # Installation summary 237 | end=$(date +%s) 238 | runtime=$((end-start)) 239 | log_info "============================================" 240 | log_info "Installation Summary:" 241 | log_info "--------------------------------------------" 242 | log_info "Installation completed in ${runtime} seconds" 243 | log_info "Ubuntu version: ${UBUNTU_VERSION}" 244 | log_info "Python version: $(python3 --version)" 245 | log_info "Pip version: $(python3 -m pip --version)" 246 | #log_info "Jesse version: $(python3 -c 'import jesse; print(jesse.__version__)')" 247 | log_info "PostgreSQL version: $(psql --version)" 248 | log_info "Redis version: $(redis-cli --version)" 249 | log_info "Log file: ${LOG_FILE}" 250 | log_info "============================================" 251 | log_info "Please log out and back in for all changes to take effect." 252 | --------------------------------------------------------------------------------