-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
66 lines (56 loc) · 1.54 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
#!/bin/bash
echo "Checking prerequisites..."
python_bin="./venv/bin/python"
config_file=""
# Function to show usage
usage() {
echo "Usage: $0 [-c <config_file>] [-x]"
exit 1
}
# Parse command-line options
while getopts ":c" opt; do
case ${opt} in
c ) config_file=$OPTARG
;;
\? ) usage
;;
esac
done
# Check if using pyenv
if [[ "$PYENV_VIRTUAL_ENV" ]]; then
python_bin="python"
echo "Currently, you are in a virtual environment managed by pyenv..."
echo "It is assumed that you have already installed the requirements."
echo "If not, please execute: python -m pip install -r requirements.txt"
# Check if venv exists, create if needed
elif [ ! -f "venv/bin/python" ]; then
echo "Creating virtual environment and installing requirements..."
python -m venv venv
venv/bin/python -m pip install -r requirements.txt
fi
# Check if .token file exists
if [ ! -f ".token" ]; then
echo "Error: .token file not found"
exit 1
fi
# Check if .cookies file exists
if [ ! -f ".cookies" ]; then
echo "Error: .cookies file not found"
exit 1
fi
echo "Prerequisites look good!"
# Load token from .token file
echo "Loading .token..."
tg_token=$(cat .token)
# Building and running
python_cmd="${python_bin} -u tg.py '$tg_token'"
# Load configurations from config file if specified
if [ -n "$config_file" ]; then
python_cmd="${python_cmd} -c '$config_file'"
fi
# Add Twitter replacement option if specified
if [ -n "$twitter_replacement" ]; then
python_cmd="${python_cmd} ${twitter_replacement}"
fi
echo "Ready to run..."
eval $python_cmd