feat: Initial implementation of LobeChat updater script
This commit introduces the `lobechat-updater` script to update a local LobeChat instance automatically.
This commit is contained in:
commit
0a4061b499
5 changed files with 124 additions and 0 deletions
19
LICENSE
Normal file
19
LICENSE
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Copyright (c) 2024 Kumi Mitterer <lobechat-updater@kumi.email>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
37
README.md
Normal file
37
README.md
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# LobeChat Updater
|
||||||
|
|
||||||
|
This is a simple script that updates the LobeChat application. It is designed to be run on a server, and will automatically update the application when a new version is tagged.
|
||||||
|
|
||||||
|
The script assumes that you use a systemd service to run LobeChat. If you do not, you will need to modify the script to suit your needs.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Clone this repository to your server.
|
||||||
|
```bash
|
||||||
|
git clone https://git.private.coffee/kumi/lobechat-updater.git
|
||||||
|
cd lobechat-updater
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Install the `lobechat-updater` to `/usr/local/bin/`:
|
||||||
|
```bash
|
||||||
|
sudo install lobechat-updater /usr/local/bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Install the systemd service and timer:
|
||||||
|
```bash
|
||||||
|
sudo cp contrib/lobechat-updater.service /etc/systemd/system/
|
||||||
|
sudo cp contrib/lobechat-updater.timer /etc/systemd/system/
|
||||||
|
sudo systemctl enable --now lobechat-updater.timer
|
||||||
|
```
|
||||||
|
|
||||||
|
This will install the updater script to `/usr/local/bin/lobechat-updater`, and will set up a systemd timer to run the updater every 5 minutes.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Modify the `LOBECHAT_DIR` variable in `/usr/local/bin/lobechat-updater` to point to the directory where LobeChat is installed. By default, this is `/opt/lobechat`. If the user running LobeChat is not `lobechat`, you will also need to modify the `LOBECHAT_USER` variable.
|
||||||
|
|
||||||
|
To change the update interval, edit the `OnBootSec` and `OnUnitActiveSec` lines in `/etc/systemd/system/lobechat-updater.timer`.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
7
contrib/lobechat-updater.service
Normal file
7
contrib/lobechat-updater.service
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Lobechat Updater Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/bin/lobechat-updater
|
10
contrib/lobechat-updater.timer
Normal file
10
contrib/lobechat-updater.timer
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Run Lobechat Updater every 5 minutes
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=5min
|
||||||
|
OnUnitActiveSec=5min
|
||||||
|
Unit=lobechat-updater.service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
51
lobechat-updater
Normal file
51
lobechat-updater
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Modify the following variables to match your setup
|
||||||
|
LOBECHAT_USER="lobechat"
|
||||||
|
LOBECHAT_DIR="/opt/lobechat"
|
||||||
|
|
||||||
|
# No need to modify anything below this line
|
||||||
|
|
||||||
|
# Create a temporary file to store the latest tag
|
||||||
|
TEMP_FILE=$(sudo -u $LOBECHAT_USER mktemp /tmp/lobechat_update.XXXXXX)
|
||||||
|
|
||||||
|
# Run the following commands as the lobechat user
|
||||||
|
sudo -u $LOBECHAT_USER bash << EOF
|
||||||
|
cd $LOBECHAT_DIR
|
||||||
|
|
||||||
|
# Fetch the latest tags
|
||||||
|
git fetch --tags
|
||||||
|
|
||||||
|
# Get the current and latest tags
|
||||||
|
current_tag=\$(git describe --tags --abbrev=0)
|
||||||
|
latest_tag=\$(git describe --tags \`git rev-list --tags --max-count=1\`)
|
||||||
|
|
||||||
|
# Check if the latest tag is different from the current tag
|
||||||
|
if [ "\$current_tag" != "\$latest_tag" ]; then
|
||||||
|
echo "New tag found: \$latest_tag. Updating..."
|
||||||
|
git checkout .
|
||||||
|
git checkout \$latest_tag
|
||||||
|
|
||||||
|
# Activate nvm
|
||||||
|
source ~/.nvm/nvm.sh
|
||||||
|
|
||||||
|
# Update and build the project
|
||||||
|
pnpm up
|
||||||
|
pnpm build
|
||||||
|
|
||||||
|
# Write the latest tag to the temporary file
|
||||||
|
echo "\$latest_tag" > $TEMP_FILE
|
||||||
|
else
|
||||||
|
echo "Already at the latest version: \$current_tag."
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Check if the temporary file contains the latest tag
|
||||||
|
if [ -s $TEMP_FILE ]; then
|
||||||
|
latest_tag=$(cat $TEMP_FILE)
|
||||||
|
echo "Restarting the lobechat service for the new tag: $latest_tag"
|
||||||
|
sudo systemctl restart lobechat
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up the temporary file
|
||||||
|
rm -f $TEMP_FILE
|
Loading…
Reference in a new issue