-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·95 lines (78 loc) · 2.77 KB
/
run.sh
File metadata and controls
executable file
·95 lines (78 loc) · 2.77 KB
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
#!/bin/bash
# Variables
SCRIPT_DIR=$(realpath "$(dirname "$0")")
VENV_PATH="$SCRIPT_DIR/venv"
SCRIPT_PATH="$SCRIPT_DIR/main.py"
WRAPPER_SCRIPT_PATH="$SCRIPT_DIR/wrapper_script.sh"
REQUIREMENTS_PATH="$SCRIPT_DIR/requirements.txt"
# Check if Python is installed
if ! command -v python3 &> /dev/null; then
echo "Error: Python 3 is not installed. Please install Python 3 and try again."
exit 1
fi
# Create virtual environment if it doesn't exist
if [ ! -d "$VENV_PATH" ]; then
echo "Creating virtual environment..."
python3 -m venv "$VENV_PATH"
fi
# Check if activate script is present in the correct location
if [ ! -f "$VENV_PATH/bin/activate" ]; then
echo "Error: activate script not found. Retrying to create virtual environment..."
rm -rf "$VENV_PATH"
python3 -m venv "$VENV_PATH"
# Double-check if the activate script is now present
if [ ! -f "$VENV_PATH/bin/activate" ]; then
echo "Error: Failed to create virtual environment. Please check your Python installation and permissions."
exit 1
fi
fi
# Ensure the virtual environment is accessible
if [ ! -x "$VENV_PATH/bin/python" ]; then
echo "Error: Virtual environment seems corrupted. Attempting to recreate..."
rm -rf "$VENV_PATH"
python3 -m venv "$VENV_PATH"
if [ ! -x "$VENV_PATH/bin/python" ]; then
echo "Error: Failed to create a working virtual environment. Please check your system configuration."
exit 1
fi
fi
# Activate virtual environment
source "$VENV_PATH/bin/activate"
# Install requirements
if [ -f "$REQUIREMENTS_PATH" ]; then
echo "Installing Python requirements..."
pip install -r "$REQUIREMENTS_PATH"
else
echo "Warning: requirements.txt not found. Skipping pip install."
fi
# Install Playwright and its dependencies
echo "Installing Playwright and its dependencies..."
playwright install
playwright install-deps
# Function to create cron job
create_cron_job() {
echo "Creating cron job..." # Debug statement
# Check if cron job already exists
cron_exists=$(crontab -l | grep -F $SCRIPT_PATH)
if [ -z "$cron_exists" ]; then
# Add a cron job to run the Python script every day at midnight
(crontab -l 2>/dev/null; echo "0 0 * * * $VENV_PATH/bin/python $SCRIPT_PATH") | crontab -
echo "Cron job created to run every day at midnight."
else
echo "Cron job already exists."
fi
}
# Check if the Python script exists
if [ ! -f "$SCRIPT_PATH" ]; then
echo "Error: Python script not found at $SCRIPT_PATH"
exit 1
fi
# Ensure the wrapper script is executable
if [ -f "$WRAPPER_SCRIPT_PATH" ]; then
chmod +x "$WRAPPER_SCRIPT_PATH"
else
echo "Warning: Wrapper script not found at $WRAPPER_SCRIPT_PATH. Skipping chmod."
fi
# Create the cron job
create_cron_job
echo "Setup complete."