-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall.sh
executable file
·140 lines (124 loc) · 4.15 KB
/
install.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
#!/bin/bash
DEBUG=1
function debug() {
if [ "$DEBUG" -eq 1 ]; then
echo "DEBUG: $1"
fi
}
if [[ ! -f "main.py" ]]; then
echo "The script must be run from the project root containing 'main.py'."
exit 1
fi
# Function to check if Python version is correct
check_python_version() {
if command -v python3 &>/dev/null; then
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
debug "Found Python version: $PYTHON_VERSION"
# Use Python for version comparison
python3 - <<EOF
import sys
if sys.version_info < (3, 6):
print("Python version 3.6 or higher is required.")
sys.exit(1)
EOF
echo "Python version $PYTHON_VERSION is sufficient."
else
echo "Python 3 is not installed. Please install Python 3.6 or later."
exit 1
fi
}
# Detect package manager and install prerequisites
install_prerequisites() {
debug "Detecting package manager..."
if command -v apt &>/dev/null; then
debug "Using apt package manager"
sudo apt update
sudo apt install -y python3-pip python3-venv portaudio19-dev
elif command -v yum &>/dev/null; then
debug "Using yum package manager"
sudo yum install -y python3 python3-pip portaudio-devel
elif command -v dnf &>/dev/null; then
debug "Using dnf package manager"
sudo dnf install -y python3 python3-pip portaudio-devel
elif command -v zypper &>/dev/null; then
debug "Using zypper package manager"
sudo zypper install -y python3 python3-pip portaudio-devel
elif command -v pacman &>/dev/null; then
debug "Using pacman package manager"
sudo pacman -Sy python python-pip portaudio
else
echo "Unsupported package manager. Please install Python 3, pip, and venv manually."
exit 1
fi
}
# Function to create virtual environment
create_virtualenv() {
debug "Creating virtual environment..."
if [[ ! -d "venv" ]]; then
python3 -m venv venv
echo "Virtual environment created."
else
echo "Virtual environment already exists."
fi
}
# Function to activate virtual environment
activate_virtualenv() {
debug "Activating virtual environment..."
source venv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; }
}
# Function to install required Python packages
install_python_packages() {
debug "Installing Python packages..."
cat >requirements.txt <<EOL
setuptools==74.1.2
openai==0.28
pyyaml==6.0.1
pynput==1.7.7
httpx==0.28.1
PyJWT==2.10.1
EOL
pip install -r requirements.txt || handle_pyaudio_error
}
# Function to check installed Python packages
check_python_packages() {
debug "Checking installed Python packages..."
REQUIRED_PKG=("setuptools" "openai" "pyyaml" "pynput")
for pkg in "${REQUIRED_PKG[@]}"; do
if ! pip show $pkg &>/dev/null; then
echo "Error: $pkg is not installed correctly."
exit 1
fi
done
}
# Function to create persistent memory file
create_persistent_memory() {
MEMORY_FILE="/tmp/persistent_memory.txt"
echo "Gathering system information for persistent memory..."
echo "Kernel Version: $(uname -r)" >$MEMORY_FILE
echo "OS Info: $(uname -o)" >>$MEMORY_FILE
echo "Architecture: $(uname -m)" >>$MEMORY_FILE
echo "Hostname: $(hostname)" >>$MEMORY_FILE
echo "Persistent memory created in $MEMORY_FILE."
}
# Function to add alias to ~/.bashrc
add_alias_to_bashrc() {
if ! grep -Fxq "# Neo AI Integration" ~/.bashrc; then
echo "" >>~/.bashrc
echo "# Neo AI Integration" >>~/.bashrc
echo "alias neo='source $(pwd)/venv/bin/activate && python3 $(pwd)/main.py'" >>~/.bashrc
echo "Alias added to ~/.bashrc"
else
echo "Alias already present in ~/.bashrc"
echo "May be necessary to add it manually."
fi
}
# Run functions
check_python_version
install_prerequisites
create_virtualenv
activate_virtualenv
install_python_packages
check_python_packages
create_persistent_memory
add_alias_to_bashrc
echo "Installation complete. Please restart your terminal or run 'source ~/.bashrc' to use Neo AI. Enjoy :)"