|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# SOC Installer Script v0.0.1 |
| 4 | +# GitHub: https://github.com/OthersideAI/self-operating-computer |
| 5 | +# Issues: https://github.com/OthersideAI/self-operating-computer/issues |
| 6 | +# Requires: bash, curl/wget, python3, pip, git |
| 7 | +# |
| 8 | +# Please open an issue if you notice any bugs. |
| 9 | +# |
| 10 | +# |
| 11 | +# This script is create by centopw |
| 12 | +# |
| 13 | +# |
| 14 | +clear |
| 15 | +echo -e "\e[0m\c" |
| 16 | +LOG_FILE="install_log.txt" |
| 17 | +# shellcheck disable=SC2016 |
| 18 | +echo ' |
| 19 | +
|
| 20 | + $$$$$$\ $$$$$$\ $$$$$$\ |
| 21 | +$$ __$$\ $$ __$$\ $$ __$$\ |
| 22 | +$$ / \__|$$ / $$ |$$ / \__| |
| 23 | +\$$$$$$\ $$ | $$ |$$ | |
| 24 | + \____$$\ $$ | $$ |$$ | |
| 25 | +$$\ $$ |$$ | $$ |$$ | $$\ |
| 26 | +\$$$$$$ | $$$$$$ |\$$$$$$ | |
| 27 | + \______/ \______/ \______/ |
| 28 | + |
| 29 | + Self-Operating-Computer |
| 30 | +--- Created by OthersideAI --- |
| 31 | + |
| 32 | +' |
| 33 | + |
| 34 | + |
| 35 | +# Function to log errors |
| 36 | +log_error() { |
| 37 | + echo "Error at $(date): $1" >> "$LOG_FILE" |
| 38 | +} |
| 39 | + |
| 40 | +# Function to check if a command exists |
| 41 | +command_exists() { |
| 42 | + command -v "$1" &> /dev/null |
| 43 | +} |
| 44 | + |
| 45 | +# Function to install packages based on the operating system |
| 46 | +install_packages() { |
| 47 | + if [ "$os" == "Linux" ]; then |
| 48 | + # Use the appropriate package manager for Linux |
| 49 | + if command_exists apt-get; then |
| 50 | + sudo apt-get install -y "$1" || { log_error "Unable to install $1."; exit 1; } |
| 51 | + elif command_exists yum; then |
| 52 | + sudo yum install -y "$1" || { log_error "Unable to install $1."; exit 1; } |
| 53 | + else |
| 54 | + log_error "Unsupported package manager. Please install $1 manually." |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + elif [ "$os" == "Darwin" ]; then |
| 58 | + # Use Homebrew for macOS |
| 59 | + if command_exists brew; then |
| 60 | + brew install "$1" || { log_error "Unable to install $1."; exit 1; } |
| 61 | + else |
| 62 | + log_error "Homebrew not found. Please install Homebrew and then $1 manually." |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + elif [ "$os" == "MINGW64_NT-10.0" ]; then |
| 66 | + # Use Chocolatey for Windows |
| 67 | + if command_exists choco; then |
| 68 | + choco install "$1" -y || { log_error "Unable to install $1."; exit 1; } |
| 69 | + else |
| 70 | + log_error "Chocolatey not found. Please install Chocolatey and then $1 manually." |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + else |
| 74 | + log_error "Unsupported operating system. Please install $1 manually." |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | +} |
| 78 | + |
| 79 | +# Function to run a script and log errors |
| 80 | +run_script() { |
| 81 | + eval "$1" || { log_error "Error running $1."; exit 1; } |
| 82 | +} |
| 83 | + |
| 84 | +# Check the operating system |
| 85 | +os=$(uname -s) |
| 86 | + |
| 87 | +# Check if Python is installed |
| 88 | +if ! command_exists python3; then |
| 89 | + echo "Python not found. Installing Python..." |
| 90 | + install_packages python3 |
| 91 | +fi |
| 92 | + |
| 93 | +# Check if pip is installed |
| 94 | +if ! command_exists pip; then |
| 95 | + echo "pip not found. Installing pip..." |
| 96 | + install_packages python3-pip |
| 97 | +fi |
| 98 | + |
| 99 | +# Check if git is installed |
| 100 | +if ! command_exists git; then |
| 101 | + echo "Git not found. Installing Git..." |
| 102 | + install_packages git |
| 103 | +fi |
| 104 | + |
| 105 | +# Create a Python virtual environment |
| 106 | +run_script "python3 -m venv venv" |
| 107 | + |
| 108 | +# Activate the virtual environment |
| 109 | +source venv/bin/activate || { log_error "Unable to activate the virtual environment."; exit 1; } |
| 110 | + |
| 111 | +# Install project requirements |
| 112 | +run_script "pip install -r requirements.txt" |
| 113 | + |
| 114 | +# Install Project and Command-Line Interface |
| 115 | +run_script "pip install ." |
| 116 | + |
| 117 | +# Check if the .env file exists and the OPENAI_API_KEY is set in it |
| 118 | +if [ -f .env ] && grep -q "OPENAI_API_KEY" .env; then |
| 119 | + echo "OpenAI API key found in .env file. Skipping prompt..." |
| 120 | +else |
| 121 | + # Prompt user for Open AI key |
| 122 | + read -p "Enter your OpenAI API key: " openai_key |
| 123 | + |
| 124 | + # Set the API key as an environment variable |
| 125 | + export OPENAI_API_KEY="$openai_key" |
| 126 | + |
| 127 | + # Create a new .env file |
| 128 | + touch .env |
| 129 | + |
| 130 | + # Write the API key to the .env file |
| 131 | + echo "OPENAI_API_KEY='$openai_key'" > .env |
| 132 | +fi |
| 133 | + |
| 134 | +# Notify the user about the last step |
| 135 | +echo "Final Step: As a last step, the Terminal app will ask for permission for 'Screen Recording' and 'Accessibility' in the 'Security & Privacy' page of Mac's 'System Preferences.'" |
| 136 | + |
| 137 | +echo "Operating system: $os" |
| 138 | + |
| 139 | +if [ "$os" == "Darwin" ]; then |
| 140 | + echo "Attempting to open Security & Privacy settings..." |
| 141 | + open /System/Library/PreferencePanes/Security.prefPane |
| 142 | + read -p "Have you granted the necessary permissions in the Security & Privacy settings? (y/n): " confirm |
| 143 | + if [ "$confirm" != "y" ]; then |
| 144 | + echo "Please grant the necessary permissions and then rerun the script." |
| 145 | + exit 1 |
| 146 | + fi |
| 147 | +else |
| 148 | + echo "Not a macOS system, skipping..." |
| 149 | +fi |
| 150 | + |
| 151 | +# End of the script |
| 152 | +echo "Installation complete. Enjoy using the Self-Operating Computer Framework!" |
| 153 | + |
| 154 | +# Run the framework |
| 155 | +run_script "operate" |
0 commit comments