-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
95 lines (78 loc) · 2.81 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
#!/bin/bash
set -e
# Function to display an error message and exit
error_exit() {
echo "Error: $1" >&2
exit 1
}
# Variables
APP_DIR="/opt/evmaccs"
VENV_POINT=".venv"
VENV_DIR="$APP_DIR/$VENV_POINT"
REPO_URL="https://github.com/0ndrec/cli-evm-accs.git"
REPO_DIR="$APP_DIR/app"
EXECUTABLE="/usr/local/bin/evmaccs"
# Check if script is run as root, else use sudo
if [[ $EUID -ne 0 ]]; then
echo "This script requires root privileges. Attempting to use sudo..."
if ! command -v sudo >/dev/null 2>&1; then
error_exit "sudo is required but not installed. Please install sudo or run as root."
fi
exec sudo bash "$0" "$@"
fi
# Delete old application directory
if [[ -d "$APP_DIR" ]]; then
echo "Clearing old application directory..."
rm -rf "$APP_DIR" || error_exit "Failed to clear old application directory."
fi
# Clone the repository
if [[ ! -d "$REPO_DIR" ]]; then
echo "Cloning repository..."
git clone "$REPO_URL" "$REPO_DIR" || error_exit "Failed to clone repository."
fi
# Upgrade packages
apt-get update -y > /dev/null|| error_exit "Failed to update package list."
# Install Python3 if not installed
if ! command -v python3 >/dev/null 2>&1; then
echo "Python3 not found. Installing..."
apt-get install -y python3 || error_exit "Failed to install Python3."
else
echo "Python3 is already installed."
fi
# Install virtualenv if not installed, and pip
apt-get install -y python3-pip > /dev/null || error_exit "Failed to install pip."
apt-get install -y python3-venv > /dev/null || error_exit "Failed to install virtualenv."
# Create application directory
if [[ ! -d "$APP_DIR" ]]; then
mkdir -p "$APP_DIR" || error_exit "Failed to create application directory at $APP_DIR."
fi
# Create virtual environment
if [[ ! -d "$VENV_DIR" ]]; then
echo "Creating Python virtual environment..."
cd "$APP_DIR" && python3 -m venv "$VENV_POINT" || error_exit "Failed to create virtual environment."
else
echo "Virtual environment already exists at $VENV_DIR."
fi
if source "$VENV_DIR/bin/activate"; then
echo "Virtual environment activated."
else
error_exit "Failed to activate virtual environment."
fi
# Install dependencies
if [[ -f "$REPO_DIR/requirements.txt" ]]; then
echo "Installing Python dependencies..."
pip install -r "$REPO_DIR/requirements.txt" > /dev/null || error_exit "Failed to install dependencies."
else
echo "No requirements.txt found. Skipping dependency installation."
fi
# Create executable script
echo "Creating executable at $EXECUTABLE..."
cat << EOF > "$EXECUTABLE"
#!/bin/bash
source "$VENV_DIR/bin/activate"
echo "Starting evmaccs..."
python "$REPO_DIR/main.py" "\$@"
deactivate
EOF
chmod +x "$EXECUTABLE" || error_exit "Failed to make $EXECUTABLE executable."
echo "Installation complete. You can now run the application using the 'evmaccs' command."