Skip to content

Commit

Permalink
main (ble-update): support package updates and "sudo" updates
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed May 15, 2021
1 parent 750ca38 commit 0bc2660
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 59 deletions.
48 changes: 36 additions & 12 deletions GNUmakefile
Expand Up @@ -85,6 +85,17 @@ $(OUTDIR)/lib/init-msys1.sh: lib/init-msys1.sh lib/init-msys1-helper.c | $(OUTDI
#$(OUTDIR)/lib/init-msleep.sh: lib/init-msleep.sh lib/init-msleep.c | $(OUTDIR)/lib
# $(MWGPP) $< > $@

#------------------------------------------------------------------------------
# documents

outdirs += $(OUTDIR)/doc
outfiles-doc += $(OUTDIR)/doc/README.md
outfiles-doc += $(OUTDIR)/doc/README-ja_JP.md
outfiles-doc += $(OUTDIR)/doc/CONTRIBUTING.md
outfiles-doc += $(OUTDIR)/doc/LICENSE.md
$(OUTDIR)/doc/%: % | $(OUTDIR)/doc
cp -p $< $@

#------------------------------------------------------------------------------
# contrib

Expand All @@ -105,30 +116,43 @@ $(OUTDIR)/contrib/%.bash: contrib/%.bash | contrib/.git $(OUTDIR)/contrib
$(outdirs):
mkdir -p $@

build: contrib/.git $(outfiles)
build: contrib/.git $(outfiles) $(outfiles-doc)
.PHONY: build

all: build

#------------------------------------------------------------------------------
# target "install"

ifneq ($(filter-out %/,$(DESTDIR)),)
DESTDIR := $(DESTDIR)/
endif

ifneq ($(DESTDIR)$(PREFIX),)
DATA_HOME := $(DESTDIR)$(PREFIX)/share
else ifneq ($(XDG_DATA_HOME),)
DATA_HOME := $(XDG_DATA_HOME)
ifneq ($(INSDIR),)
ifeq ($(INSDIR_DOC),)
INSDIR_DOC := $(INSDIR)/doc
endif
else
DATA_HOME := $(HOME)/.local/share
ifneq ($(filter-out %/,$(DESTDIR)),)
DESTDIR := $(DESTDIR)/
endif

ifneq ($(DESTDIR)$(PREFIX),)
DATA_HOME := $(DESTDIR)$(PREFIX)/share
else ifneq ($(XDG_DATA_HOME),)
DATA_HOME := $(XDG_DATA_HOME)
else
DATA_HOME := $(HOME)/.local/share
endif

INSDIR = $(DATA_HOME)/blesh
INSDIR_DOC = $(DATA_HOME)/doc/blesh
endif

INSDIR = $(DATA_HOME)/blesh
install: $(outfiles:$(OUTDIR)/%=$(INSDIR)/%) $(INSDIR)/cache.d $(INSDIR)/tmp
install: \
$(outfiles:$(OUTDIR)/%=$(INSDIR)/%) \
$(outfiles-doc:$(OUTDIR)/doc/%=$(INSDIR_DOC)/%) \
$(INSDIR)/cache.d $(INSDIR)/tmp
$(INSDIR)/%: $(OUTDIR)/%
bash make_command.sh install "$<" "$@"
$(INSDIR_DOC)/%: $(OUTDIR)/doc/%
bash make_command.sh install "$<" "$@"
$(INSDIR)/cache.d $(INSDIR)/tmp:
mkdir -p $@ && chmod a+rwxt $@
.PHONY: install
Expand Down
4 changes: 4 additions & 0 deletions README-ja_JP.md
Expand Up @@ -44,6 +44,10 @@ 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) maintained by [`@oc1024`](https://github.com/oc1024)

## 機能概要

- **構文着色**: `fish``zsh-syntax-highlighting` のような文法構造に従った着色を行います。
Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,10 @@ 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) maintained by [`@oc1024`](https://github.com/oc1024)

## Features

- **Syntax highlighting**: Highlight command lines input by users as in `fish` and `zsh-syntax-highlighting`.
Expand Down
147 changes: 114 additions & 33 deletions ble.pp
Expand Up @@ -50,16 +50,16 @@
{
#%$ echo "_ble_init_version=$FULLVER+$(git show -s --format=%h)"
_ble_init_exit=
_ble_init_test=
_ble_init_command=
for _ble_init_arg; do
case $_ble_init_arg in
--version)
_ble_init_exit=1
echo "ble.sh -- Bash Line Editor (ble-$_ble_init_version)" ;;
_ble_init_exit=0
echo "ble.sh (Bash Line Editor), version $_ble_init_version" ;;
--help)
_ble_init_exit=1
_ble_init_exit=0
printf '%s\n' \
"# ble.sh -- Bash Line Editor (ble-$_ble_init_version)" \
"# ble.sh (Bash Line Editor), version $_ble_init_version" \
'usage: source ble.sh [OPTION...]' \
'' \
'OPTION' \
Expand All @@ -70,6 +70,10 @@
' Show version and exit' \
' --test' \
' Run test and exit' \
' --update' \
' Run test and exit' \
' --clear-cache' \
' Run test and exit' \
'' \
' --rcfile=BLERC' \
' --init-file=BLERC' \
Expand All @@ -93,16 +97,17 @@
' --debug-bash-output' \
' Internal settings for debugging' \
'' ;;
--test)
_ble_init_test=1 ;;
--test) _ble_init_command=test ;;
--update) _ble_init_command=update ;;
--clear-cache) _ble_init_command=clear-cache ;;
esac
done
if [ -n "$_ble_init_exit" ]; then
unset _ble_init_version
unset _ble_init_arg
unset _ble_init_exit
unset _ble_init_test
return 1 2>/dev/null || exit 1
unset _ble_init_command
return 0 2>/dev/null || exit 0
fi
} 2>/dev/null # set -x 対策 #D0930

Expand All @@ -119,7 +124,7 @@
return 1 2>/dev/null || exit 1
fi 3>&2 >/dev/null 2>&1 # set -x 対策 #D0930

if [[ $- != *i* && ! $_ble_init_test ]]; then
if [[ $- != *i* && ! $_ble_init_command ]]; then
{ ((${#BASH_SOURCE[@]})) && [[ ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} == *bashrc ]]; } ||
builtin echo "ble.sh: This is not an interactive session." >&3
return 1 2>/dev/null || builtin exit 1
Expand Down Expand Up @@ -309,7 +314,7 @@ function ble/base/reinforce-bash-options {
builtin bind -m emacs '"\C-?": backward-delete-char'
fi

if [[ ! -o emacs && ! -o vi && ! $_ble_init_test ]]; then
if [[ ! -o emacs && ! -o vi && ! $_ble_init_command ]]; then
builtin echo "ble.sh: ble.sh is not intended to be used with the line-editing mode disabled (--noediting)." >&2
ble/base/restore-bash-options
ble/base/restore-builtin-wrappers
Expand Down Expand Up @@ -790,14 +795,63 @@ function ble/base/print-usage-for-no-argument-command {
return 0
}
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)"
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
ls -ld "$_ble_base"
return 1
elif [[ ! -r $_ble_base || ! -w $_ble_base || ! -x $_ble_base ]]; then
ble/uti/print 'ble-update: install directory permission denied:' >&2
ls -ld "$_ble_base"
return 1
fi
}
function ble-update/.make {
local sudo=
if [[ $1 == --sudo ]]; then
sudo=1
shift
fi

if ! "$MAKE" -q "$@"; then
if [[ $sudo ]]; then
sudo "$MAKE" "$@"
else
"$MAKE" "$@"
fi
else
# インストール先に更新がなくても現在の session でロードされている ble.sh が
# 古いかもしれないのでチェックしてリロードする。
return 6
fi
}
function ble-update/.reload {
if [[ $- == *i* && $_ble_attached ]]; then
ble-reload
fi
}
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
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
ble/util/print 'ble-update: fallback to the default update process.' >&2
elif [[ $ext -eq 0 || $ext -eq 6 && $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]]; then
ble-update/.reload
return $?
else
return "$ext"
fi
fi

# check make
local MAKE=
if type gmake &>/dev/null; then
Expand All @@ -819,33 +873,52 @@ function ble-update {
return 1
fi

local insdir_doc=$_ble_base/doc
[[ ! -d $insdir_doc && -d ${_ble_base%/*}/doc/blesh ]] &&
insdir_doc=${_ble_base%/*}/doc/blesh

if [[ $_ble_base_repository && $_ble_base_repository != release:* ]]; then
if [[ -e $_ble_base_repository/.git ]]; 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
ble/util/print "ble-update: git repository is owned by another user:" >&2
ls -ld "$_ble_base_repository"
elif [[ ! -r $_ble_base_repository || ! -w $_ble_base_repository || ! -x $_ble_base_repository ]]; then
ble/util/print 'ble-update: git repository permission denied:' >&2
ls -ld "$_ble_base_repository"
else
( ble/util/print "cd into $_ble_base_repository..." >&2 &&
builtin cd "$_ble_base_repository" &&
git pull && git submodule update --recursive --remote &&
{ ! "$MAKE" -q || builtin exit 6; } && "$MAKE" all &&
if [[ $_ble_base != "$_ble_base_repository"/out ]]; then
"$MAKE" INSDIR="$_ble_base" install
if [[ $_ble_base == "$_ble_base_repository"/out ]]; then
ble-update/.make all
elif ((EUID!=0)) && ! ble-update/.check-install-directory-ownership; then
ble-update/.make all
ble-update/.make --sudo INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install
else
ble-update/.make INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install
fi ); local ext=$?
if ((ext==6)); then
[[ $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]] && ble-reload
return 0
if [[ $ext -eq 0 || $ext -eq 6 && $_ble_base/ble.sh -nt $_ble_base_run/$$.load ]]; then
ble-update/.reload
return $?
fi
((ext==0)) && ble-reload
return "$ext"
fi

ble/util/print 'ble-update: git repository not found' >&2
fi

if [[ $_ble_base_branch ]]; then
# release version
local branch=$_ble_base_branch

if ((EUID!=0)) && ! ble-update/.check-install-directory-ownership; then
# _ble_base が自分の物でない時は sudo でやり直す
sudo "$BASH" "$_ble_base/ble.sh" --update &&
ble-update/.reload
return $?
else
# _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" &&
builtin cd ble.sh && "$MAKE" all && "$MAKE" INSDIR="$_ble_base" install ) &&
ble-reload
builtin cd ble.sh && "$MAKE" all &&
"$MAKE" INSDIR="$_ble_base" INSDIR_DOC="$insdir_doc" install ) &&
ble-update/.reload
return "$?"
fi
return 1
Expand Down Expand Up @@ -933,7 +1006,7 @@ function ble/dispatch {
(palette) ble-color-show "$@" ;;
(help|--help) ble/dispatch/.help "$@" ;;
(version|--version) ble/util/print "ble.sh, version $BLE_VERSION (noarch)" ;;
(check|--test) ble/base/test "$@" ;;
(check|--test) ble/base/sub:test "$@" ;;
(*)
if ble/is-function ble/bin/ble; then
ble/bin/ble "$cmd" "$@"
Expand Down Expand Up @@ -1213,11 +1286,13 @@ function ble/base/process-blesh-arguments {
}

function ble/base/initialize/.clean-up {
local ext=$? # preserve exit status

# 一時グローバル変数消去
builtin unset -v _ble_init_version
builtin unset -v _ble_init_arg
builtin unset -v _ble_init_exit
builtin unset -v _ble_init_test
builtin unset -v _ble_init_command

# 状態復元
if [[ $_ble_init_original_IFS_set ]]; then
Expand All @@ -1233,9 +1308,10 @@ function ble/base/initialize/.clean-up {
ble/base/restore-builtin-wrappers
builtin eval -- "$_ble_bash_FUNCNEST_restore"
fi
return "$ext"
}

function ble/base/test {
function ble/base/sub:test {
local error=
if ((!_ble_make_command_check_count)); then
echo "MACHTYPE: $MACHTYPE"
Expand All @@ -1247,11 +1323,16 @@ function ble/base/test {
source "$_ble_base"/lib/test-canvas.sh || error=1
[[ ! $error ]]
}
function ble/base/sub:update { ble-update; }
function ble/base/sub:clear-cache {
(shopt -u failglob; ble/bin/rm -rf "$_ble_base_cache"/*)
}

if [[ $_ble_init_test ]]; then
if ! ble/base/test; then
ble-import -f lib/_package
if [[ $_ble_init_command ]]; then
if ! ble/base/sub:"$_ble_init_command"; then
ble/base/initialize/.clean-up 2>/dev/null # set -x 対策 #D0930
{ return 1 || exit 1; } 2>/dev/null # set -x 対策 #D0930
{ return $? || exit $?; } 2>/dev/null # set -x 対策 #D0930
fi
else
ble/base/process-blesh-arguments "$@"
Expand Down
2 changes: 2 additions & 0 deletions make_command.sh
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

umask 022

function mkd {
[[ -d $1 ]] || mkdir -p "$1"
}
Expand Down
13 changes: 7 additions & 6 deletions memo/ChangeLog.md
Expand Up @@ -29,8 +29,9 @@
- edit: support `nsearch` options (motivated by Alyetama, rashil2000, carv-silva) `#D1517` 9125795
- syntax: support the deprecated redirection `>& file` `#D1539` b9b0de4
- complete: complete file descriptors and heredoc words after redirections `#D1539` b9b0de4
- main: support `blehook ATTACH DETACH`, `BLE_ONLOAD`, `BLE_ATTACHED` `#D1543` 0000000
- main: support `ble` `#D1544` 0000000
- main: support `blehook ATTACH DETACH`, `BLE_ONLOAD`, `BLE_ATTACHED` `#D1543` 750ca38
- main: support `ble` `#D1544` 750ca38
- main (`ble-update`): support package updates and `sudo` updates (motivated by huresche, oc1024) `#D1548` 0000000

## Changes

Expand Down Expand Up @@ -61,10 +62,10 @@
- syntax (`ble/syntax:bash/simple-word/eval`): optimize large array passing (motivated by timjrd) `#D1522` c89aa23
- main: accept non-regular files as `blerc` and add option `--norc` `#D1530` 7244e2f
- prompt: let `stderr` pass through to tty in evaluating `PS0` (reported by tycho-kirchner) `#D1541` 24a88ce
- prompt: adjust behavior of `LINENO` and prompt sequence `\#` (reported by tycho-kirchner) `#D1542` 0000000
- edit (`widget:display-shell-version`): include `ble.sh` version `#D1545` 0000000
- complete (`ble-sabbrev`): support colored output `#D1546` 0000000
- complete (`ble-bind`): support colored output `#D1547` 0000000
- prompt: adjust behavior of `LINENO` and prompt sequence `\#` (reported by tycho-kirchner) `#D1542` 8b0257e
- edit (`widget:display-shell-version`): include `ble.sh` version `#D1545` 750ca38
- complete (`ble-sabbrev`): support colored output `#D1546` 750ca38
- complete (`ble-bind`): support colored output `#D1547` 750ca38

## Fixes

Expand Down

0 comments on commit 0bc2660

Please sign in to comment.