2021-12-28 16:39:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# semi automatic misskey updates
|
|
|
|
# This script may trash your instance, use with caution, make backups...
|
|
|
|
#
|
|
|
|
|
|
|
|
### You will need to adjust Paths ###
|
|
|
|
# Store containers log
|
|
|
|
LOG=/var/log/docker/misskey.log
|
|
|
|
# Misskey (git) code directory
|
|
|
|
CODE=/usr/local/misskey/code
|
|
|
|
# Misskey (containers volumes) data directory
|
|
|
|
DATA=/usr/local/misskey/data
|
|
|
|
# Docker compose file name
|
|
|
|
COMPOSE=docker-compose.yml
|
|
|
|
# Backup destination directory
|
|
|
|
DST=/usr/local/backup
|
|
|
|
# Automatically stop, update and start the running instance
|
2022-01-01 21:23:22 +00:00
|
|
|
AUTOUPDATE=1
|
|
|
|
TMP=/tmp/.update_misskey.$$
|
2021-12-28 16:39:59 +00:00
|
|
|
###
|
|
|
|
|
|
|
|
if [ ! -d $CODE ] || [ ! -d $DATA ]; then
|
|
|
|
echo "Error, you may need to adjust path in this script"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-01-01 21:23:22 +00:00
|
|
|
# Take some care before upgrading
|
2021-12-28 16:39:59 +00:00
|
|
|
echo "Backing up current code... (you really should have done yourself a data backup before upgrading, something like backup_postgres.sh)"
|
2022-01-01 21:23:22 +00:00
|
|
|
echo "$CODE will be archived in $DST/backup-code.tgz"
|
2021-12-28 16:39:59 +00:00
|
|
|
tar -czf $DST/backup-code.tgz $CODE
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: something went wrong during backup..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Updating codebase with git..."
|
2022-01-01 21:23:22 +00:00
|
|
|
cd $CODE
|
|
|
|
|
|
|
|
git stash
|
|
|
|
|
|
|
|
git checkout master
|
|
|
|
|
|
|
|
# Compare version before/after pulling files
|
|
|
|
currentVersion=`grep version package.json | awk '{ print $2 }' | sed 's/\"//g' | sed 's/,//'`
|
|
|
|
|
|
|
|
git pull | tee -a $TMP
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error, bailing out"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
grep -q "Already up to date." $TMP
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Your Misskey code is already up to date, version:$currentVersion."
|
|
|
|
rm -f $TMP
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
rm -f $TMP
|
|
|
|
|
|
|
|
latestVersion=`grep version package.json | awk '{ print $2 }' | sed 's/\"//g' | sed 's/,//'`
|
|
|
|
echo "Upgrade needed, current:$currentVersion latest:$latestVersion."
|
|
|
|
|
|
|
|
git submodule update --init
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error, bailing out"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
git stash pop
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error, bailing out"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-12-28 16:39:59 +00:00
|
|
|
echo "Building new images... (it will take some time)"
|
|
|
|
docker-compose --project-directory=$DATA --file $DATA/$COMPOSE build
|
|
|
|
|
|
|
|
#sudo docker-compose stop && sudo docker-compose up -d
|
|
|
|
if [ $AUTOUPDATE -eq 0 ]; then
|
|
|
|
echo "Stop and restart the instance using:"
|
|
|
|
echo "stop_misskey.sh"
|
|
|
|
echo "start_misskey.sh"
|
|
|
|
else
|
|
|
|
echo "Automatically updating the instance, fingers crossed"
|
2022-01-01 21:23:22 +00:00
|
|
|
echo -n "Stopping..."
|
2021-12-28 16:39:59 +00:00
|
|
|
stop_misskey.sh
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: something went wrong when stopping the instance"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-01-01 21:23:22 +00:00
|
|
|
echo "done."
|
|
|
|
echo -n "Starting..."
|
2021-12-28 16:39:59 +00:00
|
|
|
start_misskey.sh
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: something went wrong when starting the instance"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-01-01 21:23:22 +00:00
|
|
|
echo "done."
|
2021-12-28 16:39:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|