71 lines
2.2 KiB
Bash
71 lines
2.2 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
# Exit on any error
|
||
|
|
set -e
|
||
|
|
|
||
|
|
# Check if running as root
|
||
|
|
if [ "$EUID" -ne 0 ]; then
|
||
|
|
echo "Please run as root"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Create icecast-bot user and group if they don't exist
|
||
|
|
if ! getent group icecast-bot >/dev/null; then
|
||
|
|
groupadd icecast-bot
|
||
|
|
fi
|
||
|
|
if ! getent passwd icecast-bot >/dev/null; then
|
||
|
|
useradd -r -g icecast-bot -s /bin/false icecast-bot
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Create necessary directories
|
||
|
|
mkdir -p /etc/icecast-irc-bot
|
||
|
|
mkdir -p /var/log/icecast-irc-bot
|
||
|
|
mkdir -p /opt/icecast-irc-bot
|
||
|
|
|
||
|
|
# Set ownership
|
||
|
|
chown icecast-bot:icecast-bot /etc/icecast-irc-bot
|
||
|
|
chown icecast-bot:icecast-bot /var/log/icecast-irc-bot
|
||
|
|
chown icecast-bot:icecast-bot /opt/icecast-irc-bot
|
||
|
|
|
||
|
|
# Create and activate virtual environment
|
||
|
|
python3 -m venv /opt/icecast-irc-bot/venv
|
||
|
|
export VIRTUAL_ENV="/opt/icecast-irc-bot/venv"
|
||
|
|
export PATH="$VIRTUAL_ENV/bin:$PATH"
|
||
|
|
unset PYTHONHOME
|
||
|
|
|
||
|
|
# Install Python dependencies in virtual environment
|
||
|
|
pip3 install --upgrade pip
|
||
|
|
pip3 install hatchling
|
||
|
|
pip3 install -r requirements.txt
|
||
|
|
pip3 install .
|
||
|
|
|
||
|
|
# Install manager script
|
||
|
|
cp icecast-irc-bot-manager.py /usr/local/bin/icecast-irc-bot-manager
|
||
|
|
chmod +x /usr/local/bin/icecast-irc-bot-manager
|
||
|
|
|
||
|
|
# Update manager script shebang to use venv Python
|
||
|
|
sed -i "1c#\!$VIRTUAL_ENV/bin/python3" /usr/local/bin/icecast-irc-bot-manager
|
||
|
|
|
||
|
|
# Install service file
|
||
|
|
cp icecast-irc-bot-manager.service /etc/systemd/system/
|
||
|
|
systemctl daemon-reload
|
||
|
|
|
||
|
|
# Copy example config if it doesn't exist
|
||
|
|
if [ ! -f /etc/icecast-irc-bot/config.yaml ]; then
|
||
|
|
cp config.yaml.example /etc/icecast-irc-bot/config.yaml
|
||
|
|
chown icecast-bot:icecast-bot /etc/icecast-irc-bot/config.yaml
|
||
|
|
chmod 640 /etc/icecast-irc-bot/config.yaml
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "Installation complete!"
|
||
|
|
echo
|
||
|
|
echo "Next steps:"
|
||
|
|
echo "1. Configure your bot(s) in /etc/icecast-irc-bot/config.yaml"
|
||
|
|
echo "2. Start the service: systemctl start icecast-irc-bot-manager"
|
||
|
|
echo "3. Enable at boot: systemctl enable icecast-irc-bot-manager"
|
||
|
|
echo
|
||
|
|
echo "Usage:"
|
||
|
|
echo "icecast-irc-bot-manager list # List running bots"
|
||
|
|
echo "icecast-irc-bot-manager start --config FILE # Start a bot"
|
||
|
|
echo "icecast-irc-bot-manager stop BOT_ID # Stop a bot"
|
||
|
|
echo "icecast-irc-bot-manager restart BOT_ID # Restart a bot"
|