-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
173 lines (144 loc) · 4.58 KB
/
installer.sh
File metadata and controls
173 lines (144 loc) · 4.58 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
set -e
echo "=============================================="
echo " NextBus GB API Parser – Installer"
echo "=============================================="
echo
# ------------------------------------------------------------
# Detect OS family
# ------------------------------------------------------------
if [ -f /etc/debian_version ]; then
OS_FAMILY="debian"
echo "Detected Debian-based system."
elif [ -f /etc/redhat-release ]; then
OS_FAMILY="rhel"
echo "Detected RHEL/CentOS/Oracle Linux system."
else
echo "Unsupported OS. Exiting."
exit 1
fi
# ------------------------------------------------------------
# Install Python + pip
# ------------------------------------------------------------
echo
echo "Installing Python3, pip, and full standard library..."
if [ "$OS_FAMILY" = "debian" ]; then
sudo apt update
sudo apt install -y python3 python3-full python3-pip python3-venv git
else
sudo yum install -y python3 python3-pip python3-virtualenv git
fi
# ------------------------------------------------------------
# Clone repo
# ------------------------------------------------------------
echo
echo "Cloning NextBus GB API Parser repo..."
if [ ! -d "NextBus-GB-API-Python-parser" ]; then
git clone https://github.com/valemaio2/NextBus-GB-API-Python-parser
fi
cd NextBus-GB-API-Python-parser
# ------------------------------------------------------------
# Ask user if they want a virtual environment
# ------------------------------------------------------------
echo
read -p "Create Python virtual environment? (y/n): " USE_VENV
if [[ "$USE_VENV" =~ ^[Yy]$ ]]; then
python3 -m venv venv
source venv/bin/activate
echo "Virtual environment activated."
fi
# ------------------------------------------------------------
# Install Python requirements
# ------------------------------------------------------------
echo
echo "Installing Python dependencies..."
pip install -r requirements.txt
# ------------------------------------------------------------
# Interactive config.json builder
# ------------------------------------------------------------
echo
echo "=============================================="
echo " Building config.json"
echo "=============================================="
# -----------------------------
# Collect bus stops
# -----------------------------
STOPS=()
while true; do
read -p "Enter ATCO bus stop code (or press ENTER to stop): " STOP_ID
if [ -z "$STOP_ID" ]; then
if [ ${#STOPS[@]} -eq 0 ]; then
echo "At least one bus stop is required."
continue
fi
break
fi
read -p "Enter a friendly name for this stop: " STOP_NAME
STOPS+=("{\"stop_id\": \"$STOP_ID\", \"stop_name\": \"$STOP_NAME\"}")
done
# -----------------------------
# Collect train stations
# -----------------------------
TRAIN_STATIONS=()
while true; do
read -p "Enter train station CRS code (or press ENTER to stop): " CRS
if [ -z "$CRS" ]; then
if [ ${#TRAIN_STATIONS[@]} -eq 0 ]; then
echo "At least one train station is required."
continue
fi
break
fi
read -p "Enter a friendly name for this station: " CRS_NAME
TRAIN_STATIONS+=("{\"crs\": \"${CRS^^}\", \"name\": \"$CRS_NAME\"}")
done
# -----------------------------
# Number of departures
# -----------------------------
read -p "Number of departures to show (default 5): " NUM
NUM=${NUM:-5}
# -----------------------------
# API credentials
# -----------------------------
echo
echo "Enter your NextBus API credentials:"
read -p "Username: " API_USER
read -s -p "Password: " API_PASS
echo
# -----------------------------
# Write config.json
# -----------------------------
echo
echo "Writing config.json..."
cat > config.json <<EOF
{
"api_username": "$API_USER",
"api_password": "$API_PASS",
"data": "./data",
"html": "./html",
"stops": [
$(IFS=,; echo "${STOPS[*]}")
],
"train_stations": [
$(IFS=,; echo "${TRAIN_STATIONS[*]}")
],
"num_departures": $NUM,
"output_html_file": "buses.html",
"output_html_title": "Live Bus/Train Timetable"
}
EOF
echo "config.json created."
# ------------------------------------------------------------
# Run the pipeline
# ------------------------------------------------------------
echo
echo "Running parser and HTML generator..."
mkdir -p data
python3 train_fetch.py config.json data/
python3 sync.py config.json
python3 generate.py config.json
echo
echo "=============================================="
echo " Installation complete!"
echo " HTML output is in the 'output/' directory."
echo "=============================================="