diff --git a/neko/update/docker.sh b/neko/update/docker.sh index eb57478aa..753d7ce53 100644 --- a/neko/update/docker.sh +++ b/neko/update/docker.sh @@ -4,16 +4,16 @@ set -eu . neko/update/utils pull() { - say "Pulling the image..." + say 'Pulling the image...' docker pull docker.io/naskya/firefish } if ! pull; then - say "awawa, the image may not be compatible with your environment..." - say "Gonnya try building the image locally!" + say 'awawa, the image may not be compatible with your environment...' + 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)" . fi -say "Done!" +say 'Done!' diff --git a/neko/update/native.sh b/neko/update/native.sh index e1ee0acc0..edbb00938 100755 --- a/neko/update/native.sh +++ b/neko/update/native.sh @@ -4,58 +4,56 @@ set -eu . neko/update/utils # Confirm that the server is stopped -if [ $# != 1 ] || [ "$1" != "--skip-all-confirmations" ]; then - say "Did you stop your server?" - printf "[Y/n] > " +if [ "$#" != '1' ] || [ "$1" != '--skip-all-confirmations' ]; then + say 'Did you stop your server?' + printf '[Y/n] > ' read -r yn case "${yn}" in [Nn]|[Nn][Oo]) - say "You must stop your server first!" + say 'You must stop your server first!' exit 1 ;; *) - say "uwu~ erai erai!" + say 'uwu~ erai erai!' br ;; esac fi # 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 +EOC +)" -say "Done!" +say 'Done!' br # install dependencies -say "Upgrading dependencies..." +say 'Upgrading dependencies...' -running "corepack prepare pnpm@latest --activate" -corepack prepare pnpm@latest --activate +run 'corepack prepare pnpm@latest --activate' +run 'pnpm install --frozen-lockfile' -running "pnpm install --frozen-lockfile" -pnpm install --frozen-lockfile - -say "Done!" +say 'Done!' br # build -say "Start building Firefish." -say "It takes some time! Why not brew a cup of cofe?" +say 'Start building Firefish.' +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 +run 'NODE_OPTIONS="--max_old_space_size=3072" NODE_ENV="production" pnpm run rebuild' say "Done! We're almost there." br # prevent migration errors if [ ! -f packages/backend/native-utils/built/index.js ]; then - say "Something went wrong orz... Gonnya try fixing that." - running "cp neko/index.js packages/backend/native-utils/built/index.js" + say 'Something went wrong orz... Gonnya try fixing that.' + run '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!" @@ -63,10 +61,8 @@ else fi # 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" -NODE_OPTIONS="--max_old_space_size=3072" NODE_ENV="production" pnpm run migrate - -say "Done!" +say 'Done!' br diff --git a/neko/update/utils b/neko/update/utils index ca10d4cac..3cad3dcf9 100644 --- a/neko/update/utils +++ b/neko/update/utils @@ -6,14 +6,15 @@ color() { say() { color 5 # magenta - printf "( ^-^) < %s\n" "$1" + printf '( ^-^) < %s\n' "$1" color } -running() { +run() { color 3 # yellow printf "[running] \$ %s\n" "$1" color + /bin/sh -c "$1" } br() { @@ -23,5 +24,5 @@ br() { version() { 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) - printf "%s.%s" "${COMMIT_DATE}" "${COMMIT_HASH_INITIAL}" + printf '%s.%s' "${COMMIT_DATE}" "${COMMIT_HASH_INITIAL}" } diff --git a/update.sh b/update.sh index d17a22b98..32acdcd41 100755 --- a/update.sh +++ b/update.sh @@ -3,33 +3,33 @@ set -eu . neko/update/utils -say "Start upgrading Firefish!" +say 'Start upgrading Firefish!' br # Pull changes ## git pull 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 -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 NEW_COMMIT=$(git rev-parse HEAD) -say "Pulled successfully!" +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..." -if [ "$(git diff "${OLD_COMMIT}" "${NEW_COMMIT}" update.sh neko/update)" != "" ]; then - say "Oh meow, that seems to be the case." +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 + 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!" + say 'This script seems to be up-to-date!' br fi @@ -37,12 +37,12 @@ fi for message in neko/messages/*; do file=$(basename -- "${message}") if [ ! -f "neko/flags/${file}" ]; then - if [ $# != 1 ] || [ "$1" != "--skip-all-confirmations" ]; then - say "There is an important notice!" + if [ "$#" != '1' ] || [ "$1" != '--skip-all-confirmations' ]; then + say 'There is an important notice!' cat "${message}" - say "Continue? (Are you ready for upgrading?)" - printf "[y/N] > " + say 'Continue? (Are you ready for upgrading?)' + printf '[y/N] > ' read -r yn case "${yn}" in @@ -50,6 +50,7 @@ for message in neko/messages/*; do touch "neko/flags/${file}" say "Let's go!" say "To read the message again, run: \$ cat ${message}" + br ;; *) say "Okay, please run this script again when you're ready!" @@ -62,8 +63,8 @@ for message in neko/messages/*; do fi done -say "Do you use Docker?" -printf "[y/N] > " +say 'Do you use Docker?' +printf '[y/N] > ' read -r yn case "${yn}" in @@ -76,4 +77,4 @@ case "${yn}" in esac # Done -say "Enjoy your sabakan life~" +say 'Enjoy your sabakan life~'