Browse Source

install2

main
pvincent 3 weeks ago
parent
commit
29b3ff8b45
  1. 6
      bin/miaou-bash
  2. 9
      etc/bash.bashrc
  3. 32
      install2.sh
  4. 2
      lib/initiate.bash
  5. 3
      test/stub/scenario.bash

6
bin/miaou-bash

@ -615,6 +615,10 @@ function usage {
echo "$(basename "$0") <SCRIPT> [...SCRIPT_ARGS] | --version | --help | --self-upgrade | --initiate | --uninstall" echo "$(basename "$0") <SCRIPT> [...SCRIPT_ARGS] | --version | --help | --self-upgrade | --initiate | --uninstall"
} }
function version {
cat "${MIAOU_BASH_DIR:-/opt/miaou-bash}/.semver_git_tag"
}
function parse_options { function parse_options {
HEREDOC=false HEREDOC=false
if [[ $# == 0 ]]; then if [[ $# == 0 ]]; then
@ -628,7 +632,7 @@ function parse_options {
elif [[ $# == 1 ]]; then elif [[ $# == 1 ]]; then
case "$1" in case "$1" in
--help) usage && builtin exit ;; --help) usage && builtin exit ;;
--version) cat "${MIAOU_BASH_DIR:-/opt/miaou-bash}/.semver_git_tag" && builtin exit ;;
--version) version && builtin exit ;;
--self-upgrade) self_upgrade && builtin exit ;; --self-upgrade) self_upgrade && builtin exit ;;
--uninstall) uninstall && builtin exit ;; --uninstall) uninstall && builtin exit ;;
-*) >&2 echo "ERROR: option '$1' unknown!" && usage && builtin exit 2 ;; -*) >&2 echo "ERROR: option '$1' unknown!" && usage && builtin exit 2 ;;

9
etc/bash.bashrc

@ -202,11 +202,10 @@ if ! shopt -oq posix; then
fi fi
fi fi
# prevent CTRL+S to freeze in vim, CTRL+Q to unfreeze!
stty -ixon
# release CTRL+U to readline processing => undo
stty kill undef
if [[ -t 0 ]]; then
stty -ixon # prevent CTRL+S to freeze in vim, CTRL+Q to unfreeze!
stty kill undef # release CTRL+U to readline processing => undo
fi
PROMPT_COMMAND='__prompt_command' # Func to gen PS1 after CMDs PROMPT_COMMAND='__prompt_command' # Func to gen PS1 after CMDs

32
install2.sh

@ -1,4 +1,5 @@
#!/usr/bin/bash -E #!/usr/bin/bash -E
# shellcheck disable=all
## CONSTANTS ## CONSTANTS
@ -9,36 +10,41 @@ MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz"
function bootstrap { function bootstrap {
cd "$(mktemp -d)" || exit 3 cd "$(mktemp -d)" || exit 3
curl -s -O $MAIN_TAR_GZ_URL curl -s -O $MAIN_TAR_GZ_URL
tar -xzf main.tar.gz --directory "$(dirname $MIAOU_BASH_DIR)"
tar -xzf main.tar.gz --directory $(dirname "$MIAOU_BASH_DIR")
. "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR/lib/initiate.bash"
} }
function assert_supported_distro { function assert_supported_distro {
grep -E '^ID=debian|^ID_LIKE=debian' /etc/os-release ||
grep -E '^ID=arch|^ID_LIKE=arch' /etc/os-release
if ! grep -E '^ID=debian|^ID_LIKE=debian' /etc/os-release &&
! grep -E '^ID=arch|^ID_LIKE=arch' /etc/os-release; then
local distro=$(grep -oP '^ID=\K(.*)' /etc/os-release)
>&2 echo "unsupported GNU/Linux distribution: $distro"
>&2 echo 'only debian-like OR arch-like currently supported'
exit 2
fi
}
function once_installed {
[[ -d "$MIAOU_BASH_DIR" &&
-L /etc/inputrc &&
"$(readlink /etc/inputrc)" == "$MIAOU_BASH_DIR"/etc/inputrc ]]
} }
## MAIN ## MAIN
set -Eeuo pipefail set -Eeuo pipefail
! assert_supported_distro && echo 'unsupported distro: debian-like OR arch-like expected' && exit 2
assert_supported_distro
deployment_type_adjective="${1:-installed}" deployment_type_adjective="${1:-installed}"
[[ ! -v MIAOU_BASH_DIR ]] && MIAOU_BASH_DIR=/opt/miaou-bash && export MIAOU_BASH_DIR [[ ! -v MIAOU_BASH_DIR ]] && MIAOU_BASH_DIR=/opt/miaou-bash && export MIAOU_BASH_DIR
if [[ "$UID" -ne 0 ]]; then if [[ "$UID" -ne 0 ]]; then
sudo -vp 'root privilege required: '
sudo -vp 'root privilege required (SUDO): '
curl -s https://git.artcode.re/miaou/miaou-bash/raw/branch/main/install2.sh | sudo bash curl -s https://git.artcode.re/miaou/miaou-bash/raw/branch/main/install2.sh | sudo bash
echo DONE with root, now refresh bash login
source /etc/profile source /etc/profile
source /etc/bash.bashrc
exec bash -l
else
if [[ -d "$MIAOU_BASH_DIR" && -L /etc/inputrc && "$(readlink /etc/inputrc)" == "$MIAOU_BASH_DIR"/etc/inputrc ]]; then
elif once_installed; then
. "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR/lib/self-upgrade.bash" . "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR/lib/self-upgrade.bash"
else else
bootstrap bootstrap
. "$MIAOU_BASH_DIR"/bin/miaou-bash "$MIAOU_BASH_DIR/lib/initiate.bash"
echo "miaou-bash successfully $deployment_type_adjective" echo "miaou-bash successfully $deployment_type_adjective"
exec bash -l
fi
fi fi

2
lib/initiate.bash

@ -96,7 +96,7 @@ function link_config_files {
function force_reload { function force_reload {
bind -f /etc/inputrc 2>/dev/null # arch: dismiss harmless warning bind -f /etc/inputrc 2>/dev/null # arch: dismiss harmless warning
source /etc/bash.bashrc
source /etc/profile
} }
function in_azerty_zone { function in_azerty_zone {

3
test/stub/scenario.bash

@ -22,8 +22,7 @@ EOF
} }
function do_pipe1 { function do_pipe1 {
# miaou-bash < <(...)
source /dev/stdin < <(echo 'echo PIPE1')
source <(echo 'echo PIPE1')
} }
function do_pipe2 { function do_pipe2 {

Loading…
Cancel
Save