forked from naskya/firefish
feat: improve update script (close #73)
This commit is contained in:
parent
d9927c027e
commit
f2215e511d
2 changed files with 127 additions and 18 deletions
24
README.md
24
README.md
|
@ -89,11 +89,19 @@ Repository url where you want to install:
|
||||||
|
|
||||||
## アップデート
|
## アップデート
|
||||||
|
|
||||||
`update.sh` を実行します。
|
1. サーバーのバックアップを取る
|
||||||
|
1. サーバーを停止する
|
||||||
```sh
|
```sh
|
||||||
$ ./update.sh
|
$ sudo systemctl stop yourserver.example.com
|
||||||
```
|
```
|
||||||
|
1. `update.sh` を実行し、表示される指示に従う
|
||||||
|
```sh
|
||||||
|
$ ./update.sh
|
||||||
|
```
|
||||||
|
1. サーバーを起動して動作を確認する
|
||||||
|
```sh
|
||||||
|
$ sudo systemctl start yourserver.example.com
|
||||||
|
```
|
||||||
|
|
||||||
## Firefish(フォーク元)からの乗り換え
|
## Firefish(フォーク元)からの乗り換え
|
||||||
|
|
||||||
|
@ -121,9 +129,10 @@ $ ./update.sh
|
||||||
$ cp -r calckey.old/custom calckey
|
$ cp -r calckey.old/custom calckey
|
||||||
$ cp -r calckey.old/.config calckey
|
$ cp -r calckey.old/.config calckey
|
||||||
```
|
```
|
||||||
1. ビルドする
|
1. 新しい Firefish のディレクトリに入ってビルドする
|
||||||
```sh
|
```sh
|
||||||
$ ./calckey/update.sh
|
$ cd calckey
|
||||||
|
$ ./update.sh
|
||||||
```
|
```
|
||||||
1. サーバーを起動して動作を確認する
|
1. サーバーを起動して動作を確認する
|
||||||
```sh
|
```sh
|
||||||
|
@ -131,6 +140,7 @@ $ ./update.sh
|
||||||
```
|
```
|
||||||
1. 元々 Firefish がインストールされていたディレクトリを削除する
|
1. 元々 Firefish がインストールされていたディレクトリを削除する
|
||||||
```sh
|
```sh
|
||||||
|
$ cd ..
|
||||||
$ rm -rf calckey.old
|
$ rm -rf calckey.old
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
121
update.sh
121
update.sh
|
@ -1,15 +1,114 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
function copy_missing_file {
|
set -eu
|
||||||
[ -f "packages/backend/native-utils/built/index.js" ] || \
|
|
||||||
cp packages/index.js packages/backend/native-utils/built/index.js
|
function say {
|
||||||
|
tput setaf 5
|
||||||
|
echo -e "( ^-^) < $1"
|
||||||
|
tput setaf 7
|
||||||
}
|
}
|
||||||
|
|
||||||
git checkout -- package.json packages/backend/assets && \
|
function running {
|
||||||
git pull --ff && \
|
tput setaf 3
|
||||||
COMMIT=$(git rev-parse --short HEAD) && \
|
echo "[running] \$ $1"
|
||||||
sed -i -r "s/\"version\": \"([^+]+).*\",$/\"version\": \"\\1+neko:${COMMIT}\",/" package.json && \
|
tput setaf 7
|
||||||
corepack prepare pnpm@latest --activate && \
|
}
|
||||||
pnpm i && \
|
|
||||||
NODE_ENV=production pnpm run rebuild && \
|
say "Start updating!"
|
||||||
copy_missing_file && \
|
say "Did you stop your server?"
|
||||||
|
read -r -p "[Y/n] > " yn
|
||||||
|
case "${yn}" in
|
||||||
|
[Nn]|[Nn][Oo])
|
||||||
|
say "You must stop your server first!"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
say "uwu~ erai erai!\n"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Pull changes
|
||||||
|
## git pull
|
||||||
|
OLD_COMMIT=$(git rev-parse --short HEAD)
|
||||||
|
say "Currently we're on \`${OLD_COMMIT}\`"
|
||||||
|
|
||||||
|
say "Pulling changes from the remote repo..."
|
||||||
|
|
||||||
|
running "git checkout -- package.json packages/backend/assets"
|
||||||
|
git checkout -- package.json packages/backend/assets
|
||||||
|
|
||||||
|
running "git pull --ff --no-edit --autostash --strategy-option theirs"
|
||||||
|
git pull --ff --no-edit --autostash --strategy-option theirs
|
||||||
|
|
||||||
|
NEW_COMMIT=$(git rev-parse --short HEAD)
|
||||||
|
say "Pulled successfully! Now we're on \`${NEW_COMMIT}\`\n"
|
||||||
|
|
||||||
|
## check if the update script itself is updated
|
||||||
|
say "Checking if the update script itself has been changed by this update..."
|
||||||
|
if [[ $(git diff ${OLD_COMMIT} ${NEW_COMMIT} update.sh) != "" ]]; then
|
||||||
|
say "Oh meow, that seems to be the case."
|
||||||
|
say "I'm sorry to bother you, but please run this script again!"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
say "This script seems to be up-to-date!\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## write version info
|
||||||
|
say "Writing version info to package.json..."
|
||||||
|
|
||||||
|
running "sed -i -r 's/\"version\": \"([^+]+).*\",$/\"version\": \"\\1+neko:${NEW_COMMIT}\",/' package.json"
|
||||||
|
sed -i -r "s/\"version\": \"([^+]+).*\",$/\"version\": \"\\1+neko:${NEW_COMMIT}\",/" package.json
|
||||||
|
|
||||||
|
say "Done!\n"
|
||||||
|
|
||||||
|
# upgrade
|
||||||
|
## install dependencies
|
||||||
|
say "Upgrading dependencies..."
|
||||||
|
|
||||||
|
running "corepack prepare pnpm@latest --activate"
|
||||||
|
corepack prepare pnpm@latest --activate
|
||||||
|
|
||||||
|
running "pnpm install"
|
||||||
|
pnpm install
|
||||||
|
|
||||||
|
say "Done!\n"
|
||||||
|
|
||||||
|
## build
|
||||||
|
say "Start building Firefish."
|
||||||
|
say "It takes some time! Why not brew a cup of cofe?"
|
||||||
|
|
||||||
|
running "NODE_ENV=production pnpm run rebuild"
|
||||||
|
NODE_ENV=production pnpm run rebuild
|
||||||
|
|
||||||
|
say "Done! We're almost there.\n"
|
||||||
|
|
||||||
|
## prevent migration errors
|
||||||
|
if [[ ! -f packages/backend/native-utils/built/index.js ]]; then
|
||||||
|
say "Something went wrong orz... Gonnya try fixing that."
|
||||||
|
pushd
|
||||||
|
running "pushd; cd packages/backend/native-utils; NODE_ENV=production pnpm build; popd"
|
||||||
|
cd packages/backend/native-utils
|
||||||
|
NODE_ENV=production pnpm build
|
||||||
|
popd
|
||||||
|
|
||||||
|
if [[ ! -f packages/backend/native-utils/built/index.js ]]; then
|
||||||
|
say "Something is still broken... I'll take another measure."
|
||||||
|
running "cp packages/index.js packages/backend/native-utils/built/index.js"
|
||||||
|
cp packages/index.js packages/backend/native-utils/built/index.js
|
||||||
|
say "Let's see if it works...\n"
|
||||||
|
else
|
||||||
|
say "The issue seems to be fixed!\n"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
say "It's going well so far!\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## migrate
|
||||||
|
say "Database migration time!"
|
||||||
|
|
||||||
|
running "pnpm run migrate"
|
||||||
pnpm run migrate
|
pnpm run migrate
|
||||||
|
|
||||||
|
say "Done!\n"
|
||||||
|
|
||||||
|
# Done
|
||||||
|
say "Enjoy your sabakan life~"
|
||||||
|
|
Loading…
Reference in a new issue