diff --git a/bin/miaou-bash b/bin/miaou-bash index 6291471..ef2b99a 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -641,6 +641,7 @@ function parse_options { builtin exit ;; --initiate) + #TODO: remove, self_upgrade does it anyway initiate builtin exit ;; @@ -694,7 +695,7 @@ else [[ -t 2 ]] && MAIN_FD_STDERR=false || MAIN_FD_STDERR=true exec 4>/dev/tty fi - exec 3>/dev/stderr 2>"$MIAOU_BASH_ERROR" + exec 3>&2 2>"$MIAOU_BASH_ERROR" miaou_debug "
" fi diff --git a/etc/bash.bashrc b/etc/bash.bashrc index 29e8490..7d9fbb2 100644 --- a/etc/bash.bashrc +++ b/etc/bash.bashrc @@ -152,8 +152,8 @@ function __vte_urlencode { ### MAIN ###------ -MIAOU_BASH_DIR=/opt/miaou-bash -export MIAOU_BASH_DIR +# If not running interactively, don't do anything +[[ $- != *i* ]] && return ## Add path for TOOLBOX if any [[ -d "/TOOLBOX" ]] && PATH=$PATH:/TOOLBOX || true @@ -161,9 +161,6 @@ export MIAOU_BASH_DIR # Add path to any tools folder in /opt/miaou-* for i in {/opt,$HOME}/miaou-*/tools; do [[ -d "$i" ]] && PATH=$PATH:$i; done || true -# If not running interactively, don't do anything -[[ $- != *i* ]] && return - HOSTNAME=$(hostname -f) # don't put duplicate lines or lines starting with space in the history. diff --git a/etc/profile.d/20-miaou-bash.sh b/etc/profile.d/20-miaou-bash.sh new file mode 100644 index 0000000..011ca10 --- /dev/null +++ b/etc/profile.d/20-miaou-bash.sh @@ -0,0 +1,4 @@ +MIAOU_BASH_DIR=/opt/miaou-bash +export MIAOU_BASH_DIR + +PATH=$PATH:$MIAOU_BASH_DIR/bin diff --git a/install.sh b/install.sh index 3f8a536..4c6995d 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,6 @@ ## CONSTANTS -MIAOU_BASH_DIR=/opt/miaou-bash MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz" ## FUNCTIONS @@ -27,7 +26,11 @@ deployment_type_adjective="${1:-installed}" [[ "$UID" -ne 0 ]] && echo 'root privilege required' && exit 1 ! assert_supported_distro && echo 'unsupported distro: debian-like OR arch-like expected' && exit 2 -export MIAOU_BASH_DIR +if [[ ! -v MIAOU_BASH_DIR ]]; then + MIAOU_BASH_DIR=/opt/miaou-bash + export MIAOU_BASH_DIR +fi + if [[ -d "$MIAOU_BASH_DIR" && -L /etc/inputrc && "$(readlink /etc/inputrc)" == "$MIAOU_BASH_DIR"/etc/inputrc ]]; then . "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR/lib/self-upgrade.bash" else diff --git a/lib/initiate.bash b/lib/initiate.bash index a7251b3..5cf3c9f 100644 --- a/lib/initiate.bash +++ b/lib/initiate.bash @@ -68,8 +68,16 @@ EOF fi } +function is_arch_like { + [[ "$DISTRO_LIKE" == 'arch' ]] +} + +function is_debian_like { + [[ "$DISTRO_LIKE" == 'debian' ]] +} + function link_config_files { - [[ "$DISTRO_LIKE" == 'arch' ]] && arch_vimrc + is_arch_like && arch_vimrc link_etc vimrc.core vim link_etc vimrc.miaou vim @@ -81,6 +89,7 @@ function link_config_files { else link_etc vimrc.local vim fi + link_etc 20-miaou-bash.sh profile.d link_etc bash.bashrc link_etc inputrc # last command required to detect successful installation } @@ -157,7 +166,7 @@ function ghostty_global_config { source "$MIAOU_BASH_DIR/lib/functions.bash" assert_root -usr_bin_miaou_bash + DISTRO_LIKE=$(fetch_distro_like) install_required_packages rm_bashrc_skeleton diff --git a/lib/self-upgrade.bash b/lib/self-upgrade.bash index 10943c2..a9db066 100644 --- a/lib/self-upgrade.bash +++ b/lib/self-upgrade.bash @@ -2,21 +2,19 @@ # CONSTANTS -[[ ! -v MAIN_TAR_GZ_URL ]] && - readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz" - # FUNCTIONS function self_upgrade { - mv "$MIAOU_BASH_DIR" "$MIAOU_BASH_DIR".before_upgrade - if "$MIAOU_BASH_DIR".before_upgrade/install.sh upgraded; then - rm -rf "$MIAOU_BASH_DIR".before_upgrade + local backup="$MIAOU_BASH_DIR".before_upgrade + mv "$MIAOU_BASH_DIR" "$backup" + if "$backup"/install.sh upgraded; then + rm -rf "$backup" echo -n "version: " . "$MIAOU_BASH_DIR"/bin/miaou-bash --version else echo "ERROR: trouble during self-upgrade: revert back" rm -rf "$MIAOU_BASH_DIR" - mv "$MIAOU_BASH_DIR".before_upgrade "$MIAOU_BASH_DIR" + mv "$backup" "$MIAOU_BASH_DIR" fi } @@ -29,6 +27,7 @@ assert_root current=$(miaou-bash --version) latest=$("$MIAOU_BASH_DIR/tools/wget_semver" artcode miaou/miaou-bash) if [[ "$current" == "$latest" ]]; then + . "$MIAOU_BASH_DIR"/bin/miaou-bash --initiate echo "up-to-date version: $current" else self_upgrade diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index 0c19fcf..095dee6 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -10,6 +10,17 @@ readonly TMP_DIRECTORY TMP_OUT TMP_ERR TMP_MIAOU # functions +function assert_stderr { + ((test_count++)) + if [[ -w /dev/stderr ]]; then + echo -n . + return + fi + echo -n F + failures+=("test -w /dev/stderr") + return 1 +} + function assert { ((test_count++)) cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1" @@ -113,7 +124,6 @@ function fail_miaou_count { local regex count="$2" cmd="$MIAOU_BASH_DIR/test/stub/scenario.bash $1" - # mapfile -t stderr <<<"$(miaou-bash ./test/stub/scenario.bash "$1" 2>&1 >/dev/null 3>/dev/null)" if ! $cmd >/dev/null 2>/dev/null 3>"$TMP_MIAOU"; then mapfile -t miaou <"$TMP_MIAOU" if [[ "${#miaou[@]}" == "$count" ]]; then @@ -138,6 +148,8 @@ mkdir -p "$TMP_DIRECTORY" TIMEFORMAT=$'\nelapsed: %Rs' time { + assert_stderr + assert success assert exit_0 assert return_conditional diff --git a/test/stub/ansi_error.bash b/test/stub/ansi_error.bash index 3344ded..0671791 100755 --- a/test/stub/ansi_error.bash +++ b/test/stub/ansi_error.bash @@ -53,7 +53,6 @@ function show_error { >&2 printf '\r' >&2 ansi_block_error "$failure_type" "$failure_payload" "$code" >&2 ansi_traces stack_sources stack_lines stack_functions - # [[ -p /dev/stdout ]] && kill -TERM $$ } function echo_return { diff --git a/tools/pkg_add b/tools/pkg_add index b88885d..8f4a7bf 100755 --- a/tools/pkg_add +++ b/tools/pkg_add @@ -2,8 +2,6 @@ # CONSTANTS -[[ ! -v MIAOU_BASH_DIR ]] && readonly MIAOU_BASH_DIR=/opt/miaou-bash && export MIAOU_BASH_DIR - # functions function usage {