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