2023-07-20 05:54:46 +09:00
|
|
|
#!/usr/bin/env bash
|
2023-08-25 06:19:15 +09:00
|
|
|
set -eu
|
|
|
|
|
2023-10-27 23:39:24 +09:00
|
|
|
function color {
|
|
|
|
if [[ -t 1 ]]; then
|
|
|
|
tput setaf ${1:-7}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-08-25 06:19:15 +09:00
|
|
|
function say {
|
2023-10-27 23:39:24 +09:00
|
|
|
color 5 # magenta
|
2023-08-25 06:19:15 +09:00
|
|
|
echo -e "( ^-^) < $1"
|
2023-10-27 23:39:24 +09:00
|
|
|
color
|
2023-08-25 06:19:15 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function running {
|
2023-10-27 23:39:24 +09:00
|
|
|
color 3 # yellow
|
2023-08-25 06:19:15 +09:00
|
|
|
echo "[running] \$ $1"
|
2023-10-27 23:39:24 +09:00
|
|
|
color
|
2023-07-22 20:25:52 +09:00
|
|
|
}
|
|
|
|
|
2023-09-21 07:58:12 +09:00
|
|
|
say "Start upgrading Firefish!"
|
2023-10-27 23:05:57 +09:00
|
|
|
|
|
|
|
# Confirm that the server is stopped
|
2023-10-29 02:44:22 +09:00
|
|
|
if [[ $# != 1 ]] || [[ $1 != "--skip-all-confirmations" ]]; then
|
2023-10-27 23:05:57 +09:00
|
|
|
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
|
|
|
|
fi
|
2023-08-25 06:19:15 +09:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2023-11-06 06:35:10 +09:00
|
|
|
running "git pull --ff --no-edit --autostash --strategy-option theirs"
|
|
|
|
git pull --ff --no-edit --autostash --strategy-option theirs
|
2023-08-25 06:19:15 +09:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-10-28 20:19:25 +09:00
|
|
|
## show messages
|
|
|
|
for message in neko/messages/*; do
|
|
|
|
file=$(basename -- "${message}")
|
|
|
|
if [[ ! -f "neko/flags/${file}" ]]; then
|
2023-10-29 02:44:22 +09:00
|
|
|
if [[ $# != 1 ]] || [[ $1 != "--skip-all-confirmations" ]]; then
|
|
|
|
say "There is an important notice!"
|
|
|
|
cat "${message}"
|
2023-10-28 21:42:14 +09:00
|
|
|
say "Continue? (Are you ready for upgrading?)"
|
|
|
|
read -r -p "[y/N] > " yn
|
|
|
|
case "${yn}" in
|
|
|
|
[Yy]|[Yy][Ee][Ss])
|
|
|
|
touch "neko/flags/${file}"
|
|
|
|
say "Let's go!"
|
|
|
|
say "To read the message again, run: \$ cat ${message}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
say "Okay, please run this script again when you're ready!"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2023-10-29 02:44:22 +09:00
|
|
|
else
|
|
|
|
touch "neko/flags/${file}"
|
2023-10-28 21:42:14 +09:00
|
|
|
fi
|
2023-10-28 20:19:25 +09:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-08-25 06:19:15 +09:00
|
|
|
## write version info
|
|
|
|
say "Writing version info to package.json..."
|
|
|
|
|
2023-09-21 07:58:12 +09:00
|
|
|
running "sed -i -r 's/\"version\": \"([^+]+).*\",$/\"version\": \"\\1+neko:${NEW_COMMIT:0:7}\",/' package.json"
|
|
|
|
sed -i -r "s/\"version\": \"([^+]+).*\",$/\"version\": \"\\1+neko:${NEW_COMMIT:0:7}\",/" package.json
|
2023-08-25 06:19:15 +09:00
|
|
|
|
|
|
|
say "Done!\n"
|
|
|
|
|
2023-10-27 23:16:07 +09:00
|
|
|
# Upgrade
|
2023-08-25 06:19:15 +09:00
|
|
|
## install dependencies
|
|
|
|
say "Upgrading dependencies..."
|
|
|
|
|
|
|
|
running "corepack prepare pnpm@latest --activate"
|
|
|
|
corepack prepare pnpm@latest --activate
|
|
|
|
|
2023-09-21 07:58:12 +09:00
|
|
|
running "pnpm install --frozen-lockfile"
|
|
|
|
pnpm install --frozen-lockfile
|
2023-08-25 06:19:15 +09:00
|
|
|
|
|
|
|
say "Done!\n"
|
|
|
|
|
|
|
|
## build
|
|
|
|
say "Start building Firefish."
|
|
|
|
say "It takes some time! Why not brew a cup of cofe?"
|
|
|
|
|
2023-10-11 00:05:03 +09:00
|
|
|
running "NODE_OPTIONS=\"--max_old_space_size=3072\" NODE_ENV=\"production\" pnpm run rebuild"
|
|
|
|
NODE_OPTIONS="--max_old_space_size=3072" NODE_ENV="production" pnpm run rebuild
|
2023-08-25 06:19:15 +09:00
|
|
|
|
|
|
|
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."
|
2023-10-11 00:02:17 +09:00
|
|
|
running "cp neko/index.js packages/backend/native-utils/built/index.js"
|
|
|
|
cp neko/index.js packages/backend/native-utils/built/index.js
|
2023-08-25 06:19:15 +09:00
|
|
|
else
|
|
|
|
say "It's going well so far!\n"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## migrate
|
|
|
|
say "Database migration time!"
|
|
|
|
|
2023-10-11 00:05:03 +09:00
|
|
|
running "NODE_OPTIONS=\"--max_old_space_size=3072\" NODE_ENV=\"production\" pnpm run migrate"
|
|
|
|
NODE_OPTIONS="--max_old_space_size=3072" NODE_ENV="production" pnpm run migrate
|
2023-08-25 06:19:15 +09:00
|
|
|
|
|
|
|
say "Done!\n"
|
|
|
|
|
|
|
|
# Done
|
|
|
|
say "Enjoy your sabakan life~"
|