Last active
November 25, 2020 13:34
-
-
Save tcdw/34b171c21451e79d99aa0a7158f0106b to your computer and use it in GitHub Desktop.
[Bash] 更新喵窝资源包并打开启动器。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # - 更新喵窝资源包并打开启动器。 | |
| # - 需要安装 `jq` 才可以工作。 | |
| # - 官网:https://stedolan.github.io/jq/ | |
| # - 包管理器有的话就直接从包管理器装好了。如 macOS + Homebrew,即可 `brew install jq` | |
| PACKDIR_PATH=/Applications/MultiMC.app/Contents/MacOS/instances/Fabric\ 1.16.4/.minecraft/resourcepacks | |
| PACK_REPO=NyaaCat/resourcepack | |
| PACK_URL=https://ci.nyaacat.com/job/resourcepacks/job/master/lastSuccessfulBuild/artifact/nyaacat-resourcepack-latest.zip | |
| CURL_CMD="curl -L --progress-bar --retry 3" | |
| STATUS_PATH=$HOME/.resourcepack-status | |
| boot_launcher() { | |
| # 这个你自己写好了( | |
| open /Applications/MultiMC.app | |
| } | |
| check_update() { | |
| echo "正在获取资源包更新..." | |
| touch $STATUS_PATH | |
| CURRENT=$($CURL_CMD -s "https://api.github.com/repos/$PACK_REPO/commits" | jq -r ".[0].sha") | |
| if [[ $? != 0 ]]; then | |
| echo "获取资源包更新失败。" | |
| return 0 | |
| fi | |
| if [[ $(< $STATUS_PATH) != $CURRENT ]]; then | |
| echo "需要下载最新资源包。" | |
| return 1 | |
| else | |
| echo "不需要下载最新资源包。" | |
| return 0 | |
| fi | |
| } | |
| download_pack() { | |
| echo "正在下载最新资源包..." | |
| $CURL_CMD -o "$PACKDIR_PATH/nyaa.zip" "$PACK_URL" | |
| if [[ $? != 0 ]]; then | |
| echo "下载资源包失败。" | |
| return | |
| fi | |
| echo $CURRENT > $STATUS_PATH | |
| } | |
| main() { | |
| check_update | |
| if [[ $? == 1 ]]; then | |
| download_pack | |
| fi | |
| boot_launcher | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment