From 98c1d3bb2cca2adbb1e83c6eab1829a925b0dd94 Mon Sep 17 00:00:00 2001 From: Uy Ha Date: Sun, 12 Jun 2022 18:22:05 +0200 Subject: [PATCH 1/3] github/workflows: define an action for nightly builds --- .github/workflows/build.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..0400eeb2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,25 @@ +name: ble.sh build +on: + push: + branches: + - master + +jobs: + builds: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + - name: Package + run: | + make install INSDIR="$(pwd)/ble.sh" + tar -cJf "ble-nightly.tar.xz" ble.sh + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: ble-nightly.tar.xz + tag_name: nightly + prerelease: true + body: Nightly build From 2d12abfa1cfd5643576ff9263f394879fc0ef6f5 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 13 Jun 2022 07:07:56 +0900 Subject: [PATCH 2/3] github/workflows (nightly): do tests, describe the release and preserve old tarballs --- .github/workflows/build.yml | 77 +++++++++++++++++++++++++++++++++---- docs/ChangeLog.md | 1 + note.txt | 11 ++++++ 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0400eeb2..fd9980c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,25 +1,88 @@ -name: ble.sh build +name: nightly build on: push: branches: - master jobs: - builds: + build: runs-on: ubuntu-latest steps: - - name: Checkout + - name: Check out uses: actions/checkout@v3 with: submodules: recursive + - name: Build + run: | + pkgver=nightly-$(date +'%Y%m%d')+$(git rev-parse --short HEAD) + echo "blesh_build_pkgver=$pkgver" >> "$GITHUB_ENV" + make FULLVER="0.4.0-nightly" + sed -i "s/^_ble_base_repository=.*/_ble_base_repository=release:$pkgver/" "out/ble.sh" + - name: Test + run: make check - name: Package run: | - make install INSDIR="$(pwd)/ble.sh" - tar -cJf "ble-nightly.tar.xz" ble.sh + make install INSDIR="./ble-${{ env.blesh_build_pkgver }}" + tar -cJf "ble-${{ env.blesh_build_pkgver }}.tar.xz" "ble-${{ env.blesh_build_pkgver }}" + cp "ble-${{ env.blesh_build_pkgver }}.tar.xz" ble-nightly.tar.xz - name: Release uses: softprops/action-gh-release@v1 with: - files: ble-nightly.tar.xz + files: | + ble-nightly.tar.xz + ble-${{ env.blesh_build_pkgver }}.tar.xz tag_name: nightly prerelease: true - body: Nightly build + body: | + ## Usage + + **Prerequisites** + + Bash 3.0+ and basic POSIX utilities are required. + + **Download ble-nightly.tar.xz** + + Link kept updated for every nightly build: + + ${{ github.event.repository.url }}/releases/download/nightly/ble-nightly.tar.xz + + Permalink to the current nightly build: + + ${{ github.event.repository.url }}/releases/download/nightly/ble-${{ env.blesh_build_pkgver }}.tar.xz + + ```bash + # DOWNLOAD with wget + wget ${{ github.event.repository.url }}/releases/download/nightly/ble-nightly.tar.xz + + # DOWNLOAD with curl + curl -LO ${{ github.event.repository.url }}/releases/download/nightly/ble-nightly.tar.xz + + # DOWNLOAD with wget (this specific nightly build) + wget ${{ github.event.repository.url }}/releases/download/nightly/ble-${{ env.blesh_build_pkgver }}.tar.xz + + # DOWNLOAD with curl (this specific nightly build) + curl -LO ${{ github.event.repository.url }}/releases/download/nightly/ble-${{ env.blesh_build_pkgver }}.tar.xz + ``` + + **Trial & Install** + + ```bash + # TRIAL + tar xJf ble-nightly.tar.xz + source ble-${{ env.blesh_build_pkgver }}/ble.sh + + # INSTALL (quick) + tar xJf ble-nightly.tar.xz + mkdir -p ~/.local/share/blesh + cp -fR ble-${{ env.blesh_build_pkgver }}/* ~/.local/share/blesh/ + echo 'source ~/.local/share/blesh' >> ~/.bashrc + + # INSTALL (more robust) + tar xJf ble-nightly.tar.xz + mkdir -p ~/.local/share/blesh + cp -fR ble-${{ env.blesh_build_pkgver }}/* ~/.local/share/blesh/ + # Add the following line near the top of ~/.bashrc + [[ $- == *i* ]] && source ~/.local/share/blesh/ble.sh --attach=none + # Add the following line at the end of ~/.bashrc + [[ ${BLE_VERSION-} ]] && ble-attach + ``` diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index c42cc4bf..f016e433 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -379,6 +379,7 @@ - main: support `bleopt debug_xtrace` (requested by SuperSandro2000) `#D1810` XXXXXXX - test: clean up check failures by `make check` and `make scan` `#D1812` XXXXXXX - util (`fd#alloc`): limit the search range of free fds `#D1813` XXXXXXX +- github/workflows: define an action for the nightly builds (contributed by uyha) `#D1814` XXXXXXX ## Contrib diff --git a/note.txt b/note.txt index bb4d75b0..b54b3624 100644 --- a/note.txt +++ b/note.txt @@ -6392,6 +6392,17 @@ bash_tips Done (実装ログ) ------------------------------------------------------------------------------- +2022-06-15 + + * github/workflows: nightly build (contributed by uyha) [#D1814] + https://github.com/akinomyoga/ble.sh/pull/197 + + 色々勝手に建て増しした。nightly build のページに情報を載せた。nightly build + の ble-update ではnightly build を取得する様にした。動作確認もした。 + file#hash の取得に使うコマンドは動的ではなくて初期化時に freeze する様にし + た。序でに ble/util/getmtime -> ble/file#mtime に改名して初期化を遅延させる + 様にした (これで初期化時の fork/exec は一つ減っただろう)。 + 2022-06-13 * util (fd#alloc): fd の上限に達した時にどうするか。無限ループになるのではないか [#D1813] From 08e3cef90933b70df317466258e9c2f2abedc50d Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 14 Jun 2022 11:59:28 +0900 Subject: [PATCH 3/3] main (ble-update): download nightly versions for the nightly builds --- README-ja_JP.md | 76 +++++++++++++++++++++++++---- README.md | 85 ++++++++++++++++++++++++++------ ble.pp | 123 ++++++++++++++++++++++++++++++++++++++++++++--- lib/test-util.sh | 4 +- src/util.sh | 84 +++++++++++++++++++++++++++----- 5 files changed, 326 insertions(+), 46 deletions(-) diff --git a/README-ja_JP.md b/README-ja_JP.md index 3d5d87c3..b16710db 100644 --- a/README-ja_JP.md +++ b/README-ja_JP.md @@ -11,7 +11,7 @@ `ble.sh` (*Bash Line Editor*) はピュア Bash スクリプトで書かれたコマンドラインエディタで、標準の GNU Readline を置き換える形で動作します。 現在の開発バージョンは 0.4 です。 -このスクリプトは Bash 3.0 以降で利用できますが、速度・機能などの観点から 4.0 以降ののリリース版 Bash でお使い頂くことがお薦めです。 +このスクリプトは Bash 3.0 以降で利用できますが、速度・機能などの観点から 4.0 以降のリリース版 Bash でお使い頂くことがお薦めです。 現時点では、文字コードとして `UTF-8` のみの対応です。 このスクリプトは [**BSD License**](LICENSE.md) (3条項 BSD ライセンス) の下で提供されます。 @@ -25,10 +25,15 @@ ## 簡単設定 -`ble.sh` インストールには `git`, `make` (GNU make), and `gawk` が必要です。 +`ble.sh` をお使いいただくには Bash 3.0 以上 (及び POSIX の基本的なコマンド) が必要です。 +`ble.sh` を取得するには主に2つの方法があります: `git` を用いてソースを取得しビルドする方法と `curl` または `wget` を用いて nightly ビルドをダウンロードする方法です。 詳細は、試用またはインストールに関しては [節1.1](#get-from-source) と [節1.2](#get-from-tarball) を、 `~/.bashrc` の設定に関しては [節1.3](#set-up-bashrc) を御覧ください。 -以下、GNU make が `gmake` として提供されているシステム (BSD など) では `make` を `gmake` に置き換えて実行してください。 + +
git を用いてソースを取得し ble.sh を生成 + +この方法では `git`, `make` (GNU make), 及び `gawk` が必要です。 +以下、GNU make が `gmake` として提供されているシステム (BSD など) では、`make` を `gmake` に置き換えて実行してください。 ```bash # 簡単お試し (インストールせずにお試しいただけます) @@ -42,7 +47,56 @@ source ble.sh/out/ble.sh git clone --recursive https://github.com/akinomyoga/ble.sh.git make -C ble.sh install PREFIX=~/.local echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc +``` + +
curl を用いて nightly ビルドをダウンロード + +この方法では `curl`, `tar` (オプション `J` に対応), 及び `xz` (XZ Utils) が必要です。 + +```bash +# 簡単お試し (インストールせずにお試しいただけます) + +curl -L https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - +source ble-nightly*/ble.sh + +# インストール & .bashrc 簡単設定 (動かない場合は節1.3を御参照下さい) + +curl -L https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - +mkdir -p ~/.local/share/blesh +mv ble-nightly* ~/.local/share/blesh +echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc +``` +
+ +
wget を用いて nightly ビルドをダウンロード + +この方法では `wget`, `tar` (オプション `J` に対応), 及び `xz` (XZ Utils) が必要です。 + +```bash +# 簡単お試し (インストールせずにお試しいただけます) +wget -O - https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - +source ble-nightly*/ble.sh + +# インストール & .bashrc 簡単設定 (動かない場合は節1.3を御参照下さい) + +wget -O - https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - +mkdir -p ~/.local/share/blesh +mv ble-nightly* ~/.local/share/blesh +echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc +``` +
+ +
パッケージ管理システムを通じてパッケージをインストール (現在 AUR のみ) + +この方法では対応するパッケージ管理ツールのみが必要です。 + +- [AUR (Arch Linux)](https://github.com/akinomyoga/ble.sh/wiki/Manual-A1-Installation#user-content-AUR) `blesh-git` (devel), `blesh` (stable 0.3.3) +
+ +
既存の ble.sh を更新 + +```bash # 更新 (ble.sh をロードした状態で) ble-update @@ -50,16 +104,18 @@ ble-update # 更新 (ble.sh 外部から) bash /path/to/ble.sh --update +``` +
+ +
ble.sh のパッケージ作成 +```bash # パッケージ作成用コマンド git clone --recursive https://github.com/akinomyoga/ble.sh.git make -C ble.sh install DESTDIR=/tmp/blesh-package PREFIX=/usr/local ``` - -パッケージ管理システムを通じて `ble.sh` をインストールする事もできます (現在 AUR のみ)。 - -- [AUR (Arch Linux)](https://github.com/akinomyoga/ble.sh/wiki/Manual-A1-Installation#user-content-AUR) `blesh-git` (devel), `blesh` (stable 0.3.3) +
## 機能概要 @@ -100,7 +156,7 @@ make -C ble.sh install DESTDIR=/tmp/blesh-package PREFIX=/usr/local > > ![ble.sh demo gif](https://github.com/akinomyoga/ble.sh/wiki/images/trial1.gif) -## これまでとこれから +## 来し方行く末 このプロジェクトは初めは `.bashrc` の片隅で行われた小さな実験からスタートしました。 2013年5月に `zsh-syntax-highlighting` のとある記事に触発されたのがきっかけでした。 @@ -121,7 +177,7 @@ Vimモードの実装は2017年9月に始まり2018年3月に一先ず完成と - 2015-12 v0.1 -- 構文着色 [[v0.1.14](https://github.com/akinomyoga/ble.sh/releases/tag/v0.1.14)] - 2018-03 v0.2 -- Vim モード [[v0.2.6](https://github.com/akinomyoga/ble.sh/releases/tag/v0.2.6)] - 2019-02 v0.3 -- 拡張補完 [[v0.3.3](https://github.com/akinomyoga/ble.sh/releases/tag/v0.3.3)] -- 20xx-xx v0.4 (plan) -- プログラム着色 [`master`] +- 20xx-xx v0.4 (plan) -- プログラム着色 [[nightly build](https://github.com/akinomyoga/ble.sh/releases/tag/nightly)] - 20xx-xx v0.5 (plan) -- TUI設定画面 - 20xx-xx v0.6 (plan) -- エラー診断? @@ -186,7 +242,7 @@ Make 変数 `DESTDIR` または `PREFIX` が指定されている時、`ble.sh` ダウンロード・試用・インストールの方法については各リリースページの説明を御覧ください。 現在、安定版は開発版に比べてかなり古いので様々な機能が欠けている事にご注意下さい。 -- 開発版 [v0.4.0-devel2](https://github.com/akinomyoga/ble.sh/releases/tag/v0.4.0-devel2) (2020-12) +- 開発版 [v0.4.0-devel2](https://github.com/akinomyoga/ble.sh/releases/tag/v0.4.0-devel2) (2020-12), [nightly build](https://github.com/akinomyoga/ble.sh/releases/tag/nightly) - 安定版 [v0.3.3](https://github.com/akinomyoga/ble.sh/releases/tag/v0.3.3) (2019-02 fork) 拡張補完 - 安定版 [v0.2.6](https://github.com/akinomyoga/ble.sh/releases/tag/v0.2.6) (2018-03 fork) Vim モード - 安定版 [v0.1.14](https://github.com/akinomyoga/ble.sh/releases/tag/v0.1.14) (2015-12 fork) 構文着色 diff --git a/README.md b/README.md index aaf9514b..ecd67622 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,15 @@ In fact, I personally read it verbosely as /biːɛliː dɑt ɛseɪtʃ/ in my hea ## Quick instructions -Installation requires the commands `git`, `make` (GNU make), and `gawk` (in addition to `bash` and POSIX standard utilities). -For detailed descriptions, see [Sec 1.1](#get-from-source) and [Sec 1.2](#get-from-tarball) for trial/installation, -[Sec 1.3](#set-up-bashrc) for the setup of your `~/.bashrc`. -Please replace `make` with `gmake` if your system provides GNU make as `gmake` (such as in BSD). +To use `ble.sh`, Bash 3.0+ and POSIX standard utilities are required. +There are two ways to get `ble.sh`: to download and build `ble.sh` using `git`, or to download the nightly build using `curl` or `wget`. +For the detailed descriptions, see [Sec 1.1](#get-from-source) and [Sec 1.2](#get-from-tarball) for trial/installation, +and [Sec 1.3](#set-up-bashrc) for the setup of your `~/.bashrc`. + +
Download and generate ble.sh using git + +This requires the commands `git`, `make` (GNU make), and `gawk` (GNU awk). +In the following, please replace `make` with `gmake` if your system provides GNU make as `gmake` (such as in BSD). ```bash # TRIAL without installation @@ -44,7 +49,57 @@ source ble.sh/out/ble.sh git clone --recursive https://github.com/akinomyoga/ble.sh.git make -C ble.sh install PREFIX=~/.local echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc +``` +
+ +
Download the nightly build with curl + +This requires the commands `curl`, `tar` (with the support for the `J` flag), and `xz` (XZ Utils). + +```bash +# TRIAL without installation + +curl -L https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - +source ble-nightly*/ble.sh + +# Quick INSTALL to BASHRC (If this doesn't work, please follow Sec 1.3) + +curl -L https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - +mkdir -p ~/.local/share/blesh +mv ble-nightly* ~/.local/share/blesh +echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc +``` +
+ +
Download the nightly build with wget + +This requires the commands `wget`, `tar` (with the support for the `J` flag), and `xz` (XZ Utils). + +```bash +# TRIAL without installation +wget -O - https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - +source ble-nightly*/ble.sh + +# Quick INSTALL to BASHRC (If this doesn't work, please follow Sec 1.3) + +wget -O - https://github.com/akinomyoga/ble.sh/releases/download/nightly/ble-nightly.tar.xz | tar xJf - +mkdir -p ~/.local/share/blesh +mv ble-nightly* ~/.local/share/blesh +echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc +``` +
+ +
Install a package using a package manager (currently only AUR packages) + +This only requires the corresponding package manager. + +- [AUR (Arch Linux)](https://github.com/akinomyoga/ble.sh/wiki/Manual-A1-Installation#user-content-AUR) `blesh-git` (devel), `blesh` (stable 0.3.3) +
+ +
Update an existing copy of ble.sh + +```bash # UPDATE (in a ble.sh session) ble-update @@ -52,16 +107,18 @@ ble-update # UPDATE (outside ble.sh sessions) bash /path/to/ble.sh --update +``` +
+ +
Create a package of ble.sh +```bash # PACKAGE (for package maintainers) git clone --recursive https://github.com/akinomyoga/ble.sh.git make -C ble.sh install DESTDIR=/tmp/blesh-package PREFIX=/usr/local ``` - -You may also install `ble.sh` through package-management systems (currently only AUR): - -- [AUR (Arch Linux)](https://github.com/akinomyoga/ble.sh/wiki/Manual-A1-Installation#user-content-AUR) `blesh-git` (devel), `blesh` (stable 0.3.3) +
## Features @@ -120,7 +177,7 @@ I started working on the enhancement of the completion in August, 2018 and relea - 2015-12 v0.1 -- Syntax highlighting [[v0.1.14](https://github.com/akinomyoga/ble.sh/releases/tag/v0.1.14)] - 2018-03 v0.2 -- Vim mode [[v0.2.6](https://github.com/akinomyoga/ble.sh/releases/tag/v0.2.6)] - 2019-02 v0.3 -- Enhanced completion [[v0.3.3](https://github.com/akinomyoga/ble.sh/releases/tag/v0.3.3)] -- 20xx-xx v0.4 (plan) -- programmable highlighting [`master`] +- 20xx-xx v0.4 (plan) -- programmable highlighting [[nightly build](https://github.com/akinomyoga/ble.sh/releases/tag/nightly)] - 20xx-xx v0.5 (plan) -- TUI configuration - 20xx-xx v0.6 (plan) -- error diagnostics? @@ -185,7 +242,7 @@ To set up `.bashrc` see [Sec. 1.3](#set-up-bashrc). For download, trial and install, see the description at each release page. The stable versions are significantly old compared to the devel version, so many features are unavailable. -- Devel [v0.4.0-devel2](https://github.com/akinomyoga/ble.sh/releases/tag/v0.4.0-devel2) (2020-12) +- Devel [v0.4.0-devel2](https://github.com/akinomyoga/ble.sh/releases/tag/v0.4.0-devel2) (2020-12), [nightly build](https://github.com/akinomyoga/ble.sh/releases/tag/nightly) - Stable [v0.3.3](https://github.com/akinomyoga/ble.sh/releases/tag/v0.3.3) (2019-02 fork) Enhanced completions - Stable [v0.2.6](https://github.com/akinomyoga/ble.sh/releases/tag/v0.2.6) (2018-03 fork) Vim mode - Stable [v0.1.14](https://github.com/akinomyoga/ble.sh/releases/tag/v0.1.14) (2015-12 fork) Syntax highlighting @@ -250,7 +307,7 @@ make INSDIR="$HOME/.local/share/blesh" install ## 1.6 Uninstall -Basically you can simply delete the installed directory and the settings that user added. +Basically you can simply delete the installed directory and the settings that the user added. - Close all the `ble.sh` sessions (the Bash interactive sessions with `ble.sh`) - Remove the added lines in `.bashrc`. @@ -261,7 +318,7 @@ Basically you can simply delete the installed directory and the settings that us # 2 Basic settings -Here some of the settings for `~/.blerc` are picked up. +Here, some of the settings for `~/.blerc` are picked up. You can find useful settings also in [Q\&A](https://github.com/akinomyoga/ble.sh/wiki/Q&A), [Recipes](https://github.com/akinomyoga/ble.sh/wiki/Recipes) and [`contrib` repository](https://github.com/akinomyoga/blesh-contrib). @@ -519,7 +576,7 @@ If you want to accept the suggestion and immediately run the command, you can us ## 3.4 Use `sabbrev` (static abbrev expansions) By registering words to `sabbrev`, the words can be expanded to predefined strings. -When the cursor is just after a registered word, typing SP causes `sabbrev` expansion. +When the cursor is just after a registered word, typing SP causes the `sabbrev` expansion. For example, with the following settings, when you type SP after the string `command L`, the command line will be expanded to `command | less`. ```bash @@ -527,7 +584,7 @@ For example, with the following settings, when you type SP after the ble-sabbrev L='| less' ``` -The sabbrev names that starts from `\` are also recommended since it is unlikely to conflict with the real words that is a part of the executed command. +The sabbrev names that starts with `\` plus alphabetical letters are also recommended since it is unlikely to conflict with real words that are a part of the executed command. ```bash # blerc diff --git a/ble.pp b/ble.pp index d5599046..7436b885 100644 --- a/ble.pp +++ b/ble.pp @@ -869,15 +869,20 @@ function ble/bin/.default-utility-path { builtin eval "function ble/bin/$cmd { command $cmd \"\$@\"; }" done } -## @fn ble/bin/.freeze-utility-path commands... +## @fn ble/bin/.freeze-utility-path [-n] commands... ## PATH が破壊された後でも ble が動作を続けられる様に、 ## 現在の PATH で基本コマンドのパスを固定して ble/bin/* から使える様にする。 ## ## 実装に ble/util/assign を使用しているので ble-core 初期化後に実行する必要がある。 ## function ble/bin/.freeze-utility-path { - local cmd path q=\' Q="'\''" fail= + local cmd path q=\' Q="'\''" fail= flags= for cmd; do + if [[ $cmd == -n ]]; then + flags=n$flags + continue + fi + [[ $flags == *n* ]] && ble/bin#has "ble/bin/$cmd" && continue ble/bin#has "ble/bin/.frozen:$cmd" && continue if ble/util/assign path "builtin type -P -- $cmd 2>/dev/null" && [[ $path ]]; then builtin eval "function ble/bin/$cmd { '${path//$q/$Q}' \"\$@\"; }" @@ -1418,6 +1423,7 @@ function ble-reload { source "$_ble_base/ble.sh"; } #%$ pwd=$(pwd) q=\' Q="'\''" bash -c 'echo "_ble_base_repository=$q${pwd//$q/$Q}$q"' #%$ echo "_ble_base_branch=$(git rev-parse --abbrev-ref HEAD)" +_ble_base_repository_url=https://github.com/akinomyoga/ble.sh function ble-update/.check-install-directory-ownership { if [[ ! -O $_ble_base ]]; then ble/uti/print 'ble-update: install directory is owned by another user:' >&2 @@ -1465,13 +1471,103 @@ function ble-update/.reload { ((ext==6)) && ext=0 return "$ext" } +function ble-update/.download-nightly-build { + if ! ble/bin#has tar xz; then + local command + for command in tar xz; do + ble/bin#has "$command" || + ble/util/print "ble-update (nightly): '$command' command is not available." >&2 + done + return 1 + fi + + if ((EUID!=0)) && ! ble-update/.check-install-directory-ownership; then + # _ble_base が自分の物でない時は sudo でやり直す + sudo "$BASH" "$_ble_base/ble.sh" --update && + ble-update/.reload 6 + return $? + fi + + local tarname=ble-nightly.tar.xz + local url_tar=$_ble_base_repository_url/releases/download/nightly/$tarname + ( + shopt -u failglob + shopt -s nullglob + + # mkcd "$_ble_base/src" + if ! ble/bin/mkdir -p "$_ble_base/src"; then + ble/util/print "ble-update (nightly): failed to create the directory '$_ble_base/src'" >&2 + return 1 + fi + if ! builtin cd "$_ble_base/src"; then + ble/util/print "ble-update (nightly): failed to enter the directory '$_ble_base/src'" >&2 + return 1 + fi + + local ret + ble/file#hash "$tarname"; local ohash=$ret + + # download "$url_tar" "$tarname" + # Note: アップロードした直後は暫く 404 Not Found になるようなので何回か再試 + # 行する。 + local retry max_retry=5 + for ((retry=0;retry<=max_retry;retry++)); do + if ((retry>0)); then + local wait=$((retry<3?retry*10:30)) + ble/util/print "ble-update (nightly): retry downloading in $wait seconds... ($retry/$max_retry)" >&2 + ble/util/sleep "$wait" + fi + + if ble/bin#has wget; then + wget -N "$url_tar" && break + elif ble/bin#has curl; then + curl -LRo "$tarname" -z "$tarname" "$url_tar" && break + else + ble/util/print "ble-update (nightly): command 'wget' nor 'curl' is available." >&2 + return 1 + fi + done + if ((retry>max_retry)); then + ble/util/print "ble-update (nightly): failed to download the archive from '$url_tar'." >&2 + return 7 + fi + + # 前回ダウンロードした物と同じ場合は省略 + ble/file#hash "$tarname"; local nhash=$ret + [[ $ohash == "$nhash" ]] && return 6 + + # tar xJf "$tarname" + ble/bin/rm -rf ble-nightly*/ + if ! tar xJf "$tarname"; then + ble/util/print 'ble-update (nightly): failed to extract the tarball. Removing possibly broken tarball.' >&2 + ble/bin/rm -rf "$tarname" + return 1 + fi + + # cp -T ble-nightly* "$_ble_base" + local extracted_dir + extracted_dir=(ble-nightly*/) + if ((${#extracted_dir[@]}!=1)); then + if ((${#extracted_dir[@]}==0)); then + ble/util/print 'ble-update (nightly): the directory "ble-nightly*" not found in the tarball.' >&2 + else + ble/util/print 'ble-update (nightly): multiple directories "ble-nightly*" found in the tarball.' >&2 + ble/bin/rm -rf ble-nightly*/* + fi + return 1 + fi + ble/bin/cp -Rf "$extracted_dir"/* "$_ble_base/" || return 1 + ble/bin/rm -rf "$extracted_dir" + ) && + ble-update/.reload +} function ble-update { if (($#)); then ble/base/print-usage-for-no-argument-command 'Update and reload ble.sh.' "$@" return "$?" fi - if [[ $_ble_base_package_type ]] && ble/is-function ble/base/package:"$_ble_base_package_type"/update; then + if [[ ${_ble_base_package_type-} ]] && ble/is-function ble/base/package:"$_ble_base_package_type"/update; then ble/util/print "ble-update: delegate to '$_ble_base_package_type' package manager..." >&2 ble/base/package:"$_ble_base_package_type"/update; local ext=$? if ((ext==125)); then @@ -1482,11 +1578,22 @@ function ble-update { fi fi + if [[ ${_ble_base_repository-} == release:nightly-* ]]; then + if ble-update/.download-nightly-build; local ext=$?; ((ext==0||ext==6||ext==7)); then + if ((ext==6)); then + ble/util/print 'ble-update (nightly): Already up to date.' >&2 + elif ((ext==7)); then + ble/util/print 'ble-update (nightly): Remote temporarily unavailable. Try it again later.' >&2 + fi + return 0 + fi + fi + # check make local MAKE= - if type gmake &>/dev/null; then + if ble/bin#has gmake; then MAKE=gmake - elif type make &>/dev/null && make --version 2>&1 | ble/bin/grep -qiF 'GNU Make'; then + elif ble/bin#has make && make --version 2>&1 | ble/bin/grep -qiF 'GNU Make'; then MAKE=make else ble/util/print "ble-update: GNU Make is not available." >&2 @@ -1497,7 +1604,7 @@ function ble-update { if ! ble/bin#has git gawk; then local command for command in git gawk; do - type "$command" &>/dev/null || + ble/bin#has "$command" || ble/util/print "ble-update: '$command' command is not available." >&2 done return 1 @@ -1507,7 +1614,7 @@ function ble-update { [[ ! -d $insdir_doc && -d ${_ble_base%/*}/doc/blesh ]] && insdir_doc=${_ble_base%/*}/doc/blesh - if [[ $_ble_base_repository && $_ble_base_repository != release:* ]]; then + if [[ ${_ble_base_repository-} && $_ble_base_repository != release:* ]]; then if [[ ! -e $_ble_base_repository/.git ]]; then ble/util/print "ble-update: git repository not found at '$_ble_base_repository'." >&2 elif [[ ! -O $_ble_base_repository ]]; then @@ -1542,7 +1649,7 @@ function ble-update { # _ble_base/src 内部に clone して make install local branch=${_ble_base_branch:-master} ( ble/bin/mkdir -p "$_ble_base/src" && builtin cd "$_ble_base/src" && - git clone --recursive --depth 1 https://github.com/akinomyoga/ble.sh "$_ble_base/src/ble.sh" -b "$branch" && + git clone --recursive --depth 1 "$_ble_base_repository_url" "$_ble_base/src/ble.sh" -b "$branch" && builtin cd ble.sh && "$MAKE" all && "$MAKE" INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install ) && ble-update/.reload diff --git a/lib/test-util.sh b/lib/test-util.sh index 6a6ad4d0..e52cf045 100644 --- a/lib/test-util.sh +++ b/lib/test-util.sh @@ -1614,9 +1614,9 @@ ble/util/msleep/.calibrate-loop &>/dev/null ) -# # ble/util/getmtime +# # ble/file#mtime # ( -# ble/test 'ble/util/getmtime a' +# ble/test 'ble/file#mtime a' # ) # ble/util/buffer diff --git a/src/util.sh b/src/util.sh index 21cb07e8..bc2537c5 100644 --- a/src/util.sh +++ b/src/util.sh @@ -4224,24 +4224,84 @@ function ble/util/pager { builtin eval -- "$pager \"\$@\"" } -## @fn ble/util/getmtime filename +## @fn ble/file#mtime filename ## ファイル filename の mtime を取得し標準出力に出力します。 ## ミリ秒も取得できる場合には第二フィールドとしてミリ秒を出力します。 ## @param[in] filename ファイル名を指定します。 ## -if ble/bin/date -r / +%s &>/dev/null; then - function ble/util/getmtime { ble/bin/date -r "$1" +'%s %N' 2>/dev/null; } -elif ble/bin/.freeze-utility-path stat; then - # 参考: http://stackoverflow.com/questions/17878684/best-way-to-get-file-modified-time-in-seconds - if ble/bin/stat -c %Y / &>/dev/null; then - function ble/util/getmtime { ble/bin/stat -c %Y "$1" 2>/dev/null; } - elif ble/bin/stat -f %m / &>/dev/null; then - function ble/util/getmtime { ble/bin/stat -f %m "$1" 2>/dev/null; } +function ble/file#mtime { + # fallback: print current time + function ble/file#mtime { ble/util/strftime '%s %N'; } || return 1 + + if ble/bin/date -r / +%s &>/dev/null; then + function ble/file#mtime { ble/bin/date -r "$1" +'%s %N' 2>/dev/null; } + elif ble/bin/.freeze-utility-path stat; then + # 参考: http://stackoverflow.com/questions/17878684/best-way-to-get-file-modified-time-in-seconds + if ble/bin/stat -c %Y / &>/dev/null; then + function ble/file#mtime { ble/bin/stat -c %Y "$1" 2>/dev/null; } + elif ble/bin/stat -f %m / &>/dev/null; then + function ble/file#mtime { ble/bin/stat -f %m "$1" 2>/dev/null; } + fi + fi + + ble/file#mtime "$@" +} + +function ble/file#hash { + local file=$1 size + if ! ble/util/assign size 'ble/bin/wc -c "$file" 2>/dev/null'; then + ret=error:$RANDOM + return 1 fi + ble/string#split-words size "$size" + ble/file#hash/.impl +} +if ble/bin/.freeze-utility-path -n git; then + function ble/file#hash/.impl { + ble/util/assign ret 'ble/bin/git hash-object "$file"' + ret="size:$size;hash:$ret" + } +elif ble/bin/.freeze-utility-path -n openssl; then + function ble/file#hash/.impl { + ble/util/assign ret 'ble/bin/openssl sha1 -r "$file"' + ble/string#split-words ret "$ret" + ret="size:$size;sha1:$ret" + } +elif ble/bin/.freeze-utility-path -n sha1sum; then + function ble/file#hash/.impl { + ble/util/assign ret 'ble/bin/sha1sum "$file"' + ble/string#split-words ret "$ret" + ret="size:$size;sha1:$ret" + } +elif ble/bin/.freeze-utility-path -n sha1; then + function ble/file#hash/.impl { + ble/util/assign ret 'ble/bin/sha1 -r "$file"' + ble/string#split-words ret "$ret" + ret="size:$size;sha1:$ret" + } +elif ble/bin/.freeze-utility-path -n md5sum; then + function ble/file#hash/.impl { + ble/util/assign ret 'ble/bin/md5sum "$file"' + ble/string#split-words ret "$ret" + ret="size:$size;md5:$ret" + } +elif ble/bin/.freeze-utility-path -n md5; then + function ble/file#hash/.impl { + ble/util/assign ret 'ble/bin/md5 -r "$file"' + ble/string#split-words ret "$ret" + ret="size:$size;md5:$ret" + } +elif ble/bin/.freeze-utility-path -n cksum; then + function ble/file#hash/.impl { + ble/util/assign ret 'ble/bin/cksum "$file"' + ble/string#split-words ret "$ret" + ret="size:$size;cksum:$ret" + } +else + function ble/file#hash/.impl { + ret="size:$size" + } fi -# fallback: print current time -ble/is-function ble/util/getmtime || - function ble/util/getmtime { ble/util/strftime '%s %N'; } #------------------------------------------------------------------------------ ## @fn ble/util/buffer text