1
0
Fork 1
mirror of https://example.com synced 2024-11-22 23:16:38 +09:00

dev: make upgrading scripts POSIX compliant

This commit is contained in:
naskya 2023-11-14 23:04:56 +09:00
parent d4173ca92e
commit 5d00801c79
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
4 changed files with 46 additions and 27 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
#!/bin/sh
set -eu
source neko/update/utils
. neko/update/utils
pull() {
say "Pulling the image..."
@ -11,8 +11,9 @@ pull() {
if ! pull; then
say "awawa, the image may not be compatible with your environment..."
say "Gonnya try building the image locally!"
COMMIT_HASH=$(git rev-parse --short HEAD)
docker build --tag docker.io/naskya/firefish --build-arg COMMIT="${COMMIT_HASH:0:7}" .
COMMIT_HASH=$(printf "%s" "$(git rev-parse HEAD)" | cut -c 1-7)
docker build --tag docker.io/naskya/firefish --build-arg COMMIT="${COMMIT_HASH}" .
fi
say "Done!"

View file

@ -1,19 +1,22 @@
#!/usr/bin/env bash
#!/bin/sh
set -eu
source neko/update/utils
. neko/update/utils
# Confirm that the server is stopped
if [ $# != 1 ] || [ "$1" != "--skip-all-confirmations" ]; then
say "Did you stop your server?"
read -r -p "[Y/n] > " yn
printf "[Y/n] > "
read -r yn
case "${yn}" in
[Nn]|[Nn][Oo])
say "You must stop your server first!"
exit 1
;;
*)
say "uwu~ erai erai!\n"
say "uwu~ erai erai!"
br
;;
esac
fi
@ -21,12 +24,12 @@ fi
# write version info
say "Writing version info to package.json..."
COMMIT_HASH=$(git rev-parse --short HEAD)
COMMIT_HASH=$(printf "%s" "$(git rev-parse HEAD)" | cut -c 1-7)
running "sed -e \"s/\\\"version\\\": \\\"\\([^+][^+]*\\).*\\\",$/\\\"version\\\": \\\"\\\\1+neko:${COMMIT_HASH}\\\",/\" package.json > package.json.new && mv -- package.json.new package.json"
sed -e "s/\"version\": \"\([^+][^+]*\).*\",$/\"version\": \"\\1+neko:${COMMIT_HASH}\",/" package.json > package.json.new && mv -- package.json.new package.json
running "sed -i -r 's/\"version\": \"([^+]+).*\",$/\"version\": \"\\1+neko:${COMMIT_HASH:0:7}\",/' package.json"
sed -i -r "s/\"version\": \"([^+]+).*\",$/\"version\": \"\\1+neko:${COMMIT_HASH:0:7}\",/" package.json
say "Done!\n"
say "Done!"
br
# install dependencies
say "Upgrading dependencies..."
@ -37,7 +40,8 @@ corepack prepare pnpm@latest --activate
running "pnpm install"
pnpm install
say "Done!\n"
say "Done!"
br
# build
say "Start building Firefish."
@ -46,7 +50,8 @@ say "It takes some time! Why not brew a cup of cofe?"
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
say "Done! We're almost there.\n"
say "Done! We're almost there."
br
# prevent migration errors
if [ ! -f packages/backend/native-utils/built/index.js ]; then
@ -54,7 +59,8 @@ if [ ! -f packages/backend/native-utils/built/index.js ]; then
running "cp neko/index.js packages/backend/native-utils/built/index.js"
cp neko/index.js packages/backend/native-utils/built/index.js
else
say "It's going well so far!\n"
say "It's going well so far!"
br
fi
# migrate
@ -63,4 +69,5 @@ say "Database migration time!"
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
say "Done!\n"
say "Done!"
br

View file

@ -6,12 +6,16 @@ color() {
say() {
color 5 # magenta
echo -e "( ^-^) < $1"
printf "( ^-^) < %s\n" "$1"
color
}
running() {
color 3 # yellow
echo "[running] \$ $1"
printf "[running] \$ %s\n" "$1"
color
}
br() {
printf "\\n"
}

View file

@ -1,13 +1,14 @@
#!/usr/bin/env bash
#!/bin/sh
set -eu
source neko/update/utils
. neko/update/utils
say "Start upgrading Firefish!"
br
# Pull changes
## git pull
OLD_COMMIT=$(git rev-parse --short HEAD)
OLD_COMMIT=$(git rev-parse HEAD)
say "Pulling changes from the remote repo..."
@ -17,8 +18,9 @@ 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!\n"
NEW_COMMIT=$(git rev-parse HEAD)
say "Pulled successfully!"
br
## check if the update script itself is updated
say "Checking if the update script itself has been modified by this update..."
@ -27,7 +29,8 @@ if [ "$(git diff "${OLD_COMMIT}" "${NEW_COMMIT}" update.sh)" != "" ]; then
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"
say "This script seems to be up-to-date!"
br
fi
## show messages
@ -37,8 +40,11 @@ for message in neko/messages/*; do
if [ $# != 1 ] || [ "$1" != "--skip-all-confirmations" ]; then
say "There is an important notice!"
cat "${message}"
say "Continue? (Are you ready for upgrading?)"
read -r -p "[y/N] > " yn
printf "[y/N] > "
read -r yn
case "${yn}" in
[Yy]|[Yy][Ee][Ss])
touch "neko/flags/${file}"
@ -57,7 +63,8 @@ for message in neko/messages/*; do
done
say "Do you use Docker?"
read -r -p "[y/N] > " yn
printf "[y/N] > "
read -r yn
case "${yn}" in
[Yy]|[Yy][Ee][Ss])