dev: refactor "running" command

This commit is contained in:
naskya 2023-11-18 16:37:55 +09:00
parent 7190d9ea90
commit c15a63ff8a
Signed by: naskya
GPG key ID: 164DFF24E2D40139
4 changed files with 48 additions and 50 deletions

View file

@ -4,16 +4,16 @@ set -eu
. neko/update/utils . neko/update/utils
pull() { pull() {
say "Pulling the image..." say 'Pulling the image...'
docker pull docker.io/naskya/firefish docker pull docker.io/naskya/firefish
} }
if ! pull; then if ! pull; then
say "awawa, the image may not be compatible with your environment..." say 'awawa, the image may not be compatible with your environment...'
say "Gonnya try building the image locally!" say 'Gonnya try building the image locally!'
say "It takes some time! Why not brew a cup of cofe?" say 'It takes some time! Why not brew a cup of cofe?'
docker build --tag docker.io/naskya/firefish --build-arg VERSION="$(version)" . docker build --tag docker.io/naskya/firefish --build-arg VERSION="$(version)" .
fi fi
say "Done!" say 'Done!'

View file

@ -4,58 +4,56 @@ set -eu
. neko/update/utils . neko/update/utils
# Confirm that the server is stopped # Confirm that the server is stopped
if [ $# != 1 ] || [ "$1" != "--skip-all-confirmations" ]; then if [ "$#" != '1' ] || [ "$1" != '--skip-all-confirmations' ]; then
say "Did you stop your server?" say 'Did you stop your server?'
printf "[Y/n] > " printf '[Y/n] > '
read -r yn read -r yn
case "${yn}" in case "${yn}" in
[Nn]|[Nn][Oo]) [Nn]|[Nn][Oo])
say "You must stop your server first!" say 'You must stop your server first!'
exit 1 exit 1
;; ;;
*) *)
say "uwu~ erai erai!" say 'uwu~ erai erai!'
br br
;; ;;
esac esac
fi fi
# write version info # write version info
say "Writing version info to package.json..." say 'Writing version info to package.json...'
running "sed \"s/\\\"version\\\": \\\"\\([^+][^+]*\\).*\\\",$/\\\"version\\\": \\\"\\\\1+neko:$(version)\\\",/\" package.json > package.json.new && mv -- package.json.new package.json" run "$(cat - << EOC
sed "s/\"version\": \"\([^+][^+]*\).*\",$/\"version\": \"\\1+neko:$(version)\",/" package.json > package.json.new && mv -- package.json.new package.json sed "s/\"version\": \"\([^+][^+]*\).*\",$/\"version\": \"\\1+neko:$(version)\",/" package.json > package.json.new && mv -- package.json.new package.json
EOC
)"
say "Done!" say 'Done!'
br br
# install dependencies # install dependencies
say "Upgrading dependencies..." say 'Upgrading dependencies...'
running "corepack prepare pnpm@latest --activate" run 'corepack prepare pnpm@latest --activate'
corepack prepare pnpm@latest --activate run 'pnpm install --frozen-lockfile'
running "pnpm install --frozen-lockfile" say 'Done!'
pnpm install --frozen-lockfile
say "Done!"
br br
# build # build
say "Start building Firefish." say 'Start building Firefish.'
say "It takes some time! Why not brew a cup of cofe?" 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" run '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." say "Done! We're almost there."
br br
# prevent migration errors # prevent migration errors
if [ ! -f packages/backend/native-utils/built/index.js ]; then if [ ! -f packages/backend/native-utils/built/index.js ]; then
say "Something went wrong orz... Gonnya try fixing that." say 'Something went wrong orz... Gonnya try fixing that.'
running "cp neko/index.js packages/backend/native-utils/built/index.js" run 'cp neko/index.js packages/backend/native-utils/built/index.js'
cp neko/index.js packages/backend/native-utils/built/index.js cp neko/index.js packages/backend/native-utils/built/index.js
else else
say "It's going well so far!" say "It's going well so far!"
@ -63,10 +61,8 @@ else
fi fi
# migrate # migrate
say "Database migration time!" say 'Database migration time!'
run 'NODE_OPTIONS="--max_old_space_size=3072" NODE_ENV="production" pnpm run migrate'
running "NODE_OPTIONS=\"--max_old_space_size=3072\" NODE_ENV=\"production\" pnpm run migrate" say 'Done!'
NODE_OPTIONS="--max_old_space_size=3072" NODE_ENV="production" pnpm run migrate
say "Done!"
br br

View file

@ -6,14 +6,15 @@ color() {
say() { say() {
color 5 # magenta color 5 # magenta
printf "( ^-^) < %s\n" "$1" printf '( ^-^) < %s\n' "$1"
color color
} }
running() { run() {
color 3 # yellow color 3 # yellow
printf "[running] \$ %s\n" "$1" printf "[running] \$ %s\n" "$1"
color color
/bin/sh -c "$1"
} }
br() { br() {
@ -23,5 +24,5 @@ br() {
version() { version() {
COMMIT_DATE=$(git show --no-patch --pretty="%cs" FETCH_HEAD | sed -e "s/-//g" | cut -c 3-) COMMIT_DATE=$(git show --no-patch --pretty="%cs" FETCH_HEAD | sed -e "s/-//g" | cut -c 3-)
COMMIT_HASH_INITIAL=$(printf "%s" "$(git rev-parse FETCH_HEAD)" | cut -c 1) COMMIT_HASH_INITIAL=$(printf "%s" "$(git rev-parse FETCH_HEAD)" | cut -c 1)
printf "%s.%s" "${COMMIT_DATE}" "${COMMIT_HASH_INITIAL}" printf '%s.%s' "${COMMIT_DATE}" "${COMMIT_HASH_INITIAL}"
} }

View file

@ -3,33 +3,33 @@ set -eu
. neko/update/utils . neko/update/utils
say "Start upgrading Firefish!" say 'Start upgrading Firefish!'
br br
# Pull changes # Pull changes
## git pull ## git pull
OLD_COMMIT=$(git rev-parse HEAD) OLD_COMMIT=$(git rev-parse HEAD)
say "Pulling changes from the remote repo..." say 'Pulling changes from the remote repo...'
running "git checkout -- package.json packages/backend/assets" run 'git checkout -- package.json packages/backend/assets'
git checkout -- package.json packages/backend/assets git checkout -- package.json packages/backend/assets
running "git pull --ff --no-edit --autostash --strategy-option theirs" run 'git pull --ff --no-edit --autostash --strategy-option theirs'
git pull --ff --no-edit --autostash --strategy-option theirs git pull --ff --no-edit --autostash --strategy-option theirs
NEW_COMMIT=$(git rev-parse HEAD) NEW_COMMIT=$(git rev-parse HEAD)
say "Pulled successfully!" say 'Pulled successfully!'
br br
## check if the update script itself is updated ## check if the update script itself is updated
say "Checking if the update script itself has been modified by this update..." say 'Checking if the update script itself has been modified by this update...'
if [ "$(git diff "${OLD_COMMIT}" "${NEW_COMMIT}" update.sh neko/update)" != "" ]; then if [ "$(git diff "${OLD_COMMIT}" "${NEW_COMMIT}" update.sh neko/update)" != '' ]; then
say "Oh meow, that seems to be the case." say 'Oh meow, that seems to be the case.'
say "I'm sorry to bother you, but please run this script again!" say "I'm sorry to bother you, but please run this script again!"
exit 1 exit 1
else else
say "This script seems to be up-to-date!" say 'This script seems to be up-to-date!'
br br
fi fi
@ -37,12 +37,12 @@ fi
for message in neko/messages/*; do for message in neko/messages/*; do
file=$(basename -- "${message}") file=$(basename -- "${message}")
if [ ! -f "neko/flags/${file}" ]; then if [ ! -f "neko/flags/${file}" ]; then
if [ $# != 1 ] || [ "$1" != "--skip-all-confirmations" ]; then if [ "$#" != '1' ] || [ "$1" != '--skip-all-confirmations' ]; then
say "There is an important notice!" say 'There is an important notice!'
cat "${message}" cat "${message}"
say "Continue? (Are you ready for upgrading?)" say 'Continue? (Are you ready for upgrading?)'
printf "[y/N] > " printf '[y/N] > '
read -r yn read -r yn
case "${yn}" in case "${yn}" in
@ -50,6 +50,7 @@ for message in neko/messages/*; do
touch "neko/flags/${file}" touch "neko/flags/${file}"
say "Let's go!" say "Let's go!"
say "To read the message again, run: \$ cat ${message}" say "To read the message again, run: \$ cat ${message}"
br
;; ;;
*) *)
say "Okay, please run this script again when you're ready!" say "Okay, please run this script again when you're ready!"
@ -62,8 +63,8 @@ for message in neko/messages/*; do
fi fi
done done
say "Do you use Docker?" say 'Do you use Docker?'
printf "[y/N] > " printf '[y/N] > '
read -r yn read -r yn
case "${yn}" in case "${yn}" in
@ -76,4 +77,4 @@ case "${yn}" in
esac esac
# Done # Done
say "Enjoy your sabakan life~" say 'Enjoy your sabakan life~'