Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoupdater #66

Open
chelaxian opened this issue Mar 19, 2024 · 2 comments
Open

autoupdater #66

chelaxian opened this issue Mar 19, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@chelaxian
Copy link

chelaxian commented Mar 19, 2024

i created auto-updater for your project

crontab -e

0 4 * * * ~/updater_tg_gpt.sh

nano ~/updater_tg_gpt.sh

#!/bin/bash

# Find the AwesomeChatGPTBot directory
AWESOME_CHAT_GPT_BOT_PATH=$(find / -type d -name "AwesomeChatGPTBot" 2>/dev/null | awk '!seen[$0]++')

# Check if the directory was found
if [ -z "$AWESOME_CHAT_GPT_BOT_PATH" ]; then
    echo "Directory AwesomeChatGPTBot not found."
    exit 1
fi

# Define the backup config directory path
BACKUP_CONFIG_DIR=$(dirname "$AWESOME_CHAT_GPT_BOT_PATH")/BACKUP-CONFIG

# Create the backup config directory if it doesn't exist
mkdir -p "$BACKUP_CONFIG_DIR"

# Copy the token.txt file from the found directory to BACKUP-CONFIG
cp "$AWESOME_CHAT_GPT_BOT_PATH"/token.txt "$BACKUP_CONFIG_DIR"/

# Backup the Accounts directory and its contents
cp -R "$AWESOME_CHAT_GPT_BOT_PATH"/Accounts "$BACKUP_CONFIG_DIR"/

# Remove the old AwesomeChatGPTBot directory if it exists
if [ -d "$AWESOME_CHAT_GPT_BOT_PATH"-old ]; then
    rm -rf "$AWESOME_CHAT_GPT_BOT_PATH"-old
fi

# Backup current version of AwesomeChatGPTBot before updating
mv "$AWESOME_CHAT_GPT_BOT_PATH" "$AWESOME_CHAT_GPT_BOT_PATH"-old

# Clone the new version of AwesomeChatGPTBot from the repository
git clone https://github.com/Kourva/AwesomeChatGPTBot "$AWESOME_CHAT_GPT_BOT_PATH"

# Copy back the token.txt file
cp "$BACKUP_CONFIG_DIR"/token.txt "$AWESOME_CHAT_GPT_BOT_PATH"/

# Restore the Accounts directory from backup
cp -R "$BACKUP_CONFIG_DIR"/Accounts "$AWESOME_CHAT_GPT_BOT_PATH"/

# Change to the directory with the new version of AwesomeChatGPTBot
cd "$AWESOME_CHAT_GPT_BOT_PATH" || exit

# Provide permissions to the Accounts directory
chmod -R 777 Accounts/

# Run the initialization script
python3 init.py

# Restart the telegram_bot service
systemctl restart telegram_bot.service

chmod 777 ~/updater_tg_gpt.sh

@chelaxian
Copy link
Author

chelaxian commented Mar 19, 2024

cat /etc/systemd/system/telegram_bot.service

[Unit]
Description=Telegram Bot
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/python3 /path/to/project/directory/AwesomeChatGPTBot/main.py
WorkingDirectory=/path/to/project/directory/AwesomeChatGPTBot/
Restart=always
RestartSec=5
User=root
Group=root

[Install]
WantedBy=multi-user.target

something like that

@KourvA
Copy link
Owner

KourvA commented Mar 20, 2024

Wait, that’s awesome! Thank you. I will add them to the repository. Also, I should include a function to check for updates. Perhaps it could be in a file called version.txt.

Additionally, I could make it compatible with other init systems like OpenRC and maybe even Runit.

@KourvA KourvA added the enhancement New feature or request label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants