12
12
# - Creates a Python virtual environment in ./env
13
13
# - Installs project dependencies with pip
14
14
# - Verifies that data/config.yaml exists
15
- # - Generates a systemd user service at ~/.config/systemd/user/ioibot2025 .service
15
+ # - Generates a systemd user service at ~/.config/systemd/user/ioibot .service
16
16
#
17
17
# TO START THE BOT:
18
- # systemctl --user start ioibot2025 .service
18
+ # systemctl --user start ioibot .service
19
19
#
20
20
# TO VIEW LOGS:
21
- # journalctl --user -u ioibot2025 .service -f
21
+ # journalctl --user -u ioibot .service -f
22
22
#
23
23
# NOTES:
24
24
# - You must edit 'data/sample.config.yaml' and save it as 'data/config.yaml'
25
25
# before starting the bot.
26
- # - You must set the environment variables VOTING_USERNAME and VOTING_PASSWORD
27
- # in the systemd service file:
28
- # ~/.config/systemd/user/ioibot2025.service
29
- # These are required for the bot to work properly.
26
+ # - The systemd service file will be created at:
27
+ # ~/.config/systemd/user/ioibot.service
30
28
31
29
set -euo pipefail
32
30
33
31
# Variable names
34
- SERVICE_NAME=" ioibot2025 .service"
32
+ SERVICE_NAME=" ioibot .service"
35
33
SYSTEMD_DIR=" $HOME /.config/systemd/user"
36
34
PROJECT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
37
35
DATA_DIR=" $PROJECT_DIR /data"
38
- VENV=" $PROJECT_DIR /env "
36
+ VENV=" $PROJECT_DIR /venv "
39
37
BOT=" $VENV /bin/ioibot"
40
38
CONFIG=" $DATA_DIR /config.yaml"
41
39
TEMPLATE=" $DATA_DIR /sample.config.yaml"
40
+ INIT_SQL=" $PROJECT_DIR /ioibot/init.sql"
42
41
43
42
if [ ! -d " $VENV " ]; then
44
43
python3 -m venv " $VENV "
48
47
source " $VENV /bin/activate"
49
48
50
49
# Install Python packages
51
- pip install --upgrade pip
52
- pip install flit
53
- pip install -e " .[postgres]"
54
50
pip install -e .
55
51
56
52
if [ ! -f " $CONFIG " ]; then
@@ -64,10 +60,13 @@ if [ ! -f "$CONFIG" ]; then
64
60
fi
65
61
fi
66
62
67
-
68
- # Make sure the bot file is executable
69
- if [ ! -x " $BOT " ]; then
70
- chmod +x " $BOT "
63
+ # Initialize database schema if init.sql exists
64
+ if [ -f " $INIT_SQL " ]; then
65
+ echo " Initializing database schema from $INIT_SQL "
66
+ psql -f " $INIT_SQL "
67
+ else
68
+ echo " $INIT_SQL not found. Skipping database initialization."
69
+ echo " Please initialize your database manually."
71
70
fi
72
71
73
72
# Create systemd user directory
@@ -82,8 +81,6 @@ After=network.target
82
81
83
82
[Service]
84
83
Type=simple
85
- Environment=VOTING_USERNAME=
86
- Environment=VOTING_PASSWORD=
87
84
WorkingDirectory=$DATA_DIR
88
85
ExecStart=$BOT config.yaml
89
86
Restart=always
@@ -94,16 +91,4 @@ WantedBy=default.target
94
91
EOF
95
92
96
93
# Reload systemd so it sees the new service
97
- systemctl --user daemon-reexec || true
98
94
systemctl --user daemon-reload
99
-
100
- echo " "
101
- echo " Please update \" $SYSTEMD_DIR /$SERVICE_NAME \" with your custom configurations if needed."
102
- echo " "
103
- echo " To start the bot run:"
104
- echo " systemctl --user start $SERVICE_NAME "
105
- echo " "
106
- echo " To show logs, run:"
107
- echo " journalctl --user -u $SERVICE_NAME -f"
108
- echo " "
109
-
0 commit comments