From 359e57e9007e3358426682b2455463f682712084 Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 6 Aug 2026 22:09:42 +0400 Subject: [PATCH] new install --- etc/vim/vimrc.rookie | 2 +- install.sh | 61 ++++++++++++---------------------------- init.sh => lib/init.bash | 30 +++++++++----------- 3 files changed, 32 insertions(+), 61 deletions(-) rename init.sh => lib/init.bash (55%) diff --git a/etc/vim/vimrc.rookie b/etc/vim/vimrc.rookie index 9980b7d..1067dbd 100644 --- a/etc/vim/vimrc.rookie +++ b/etc/vim/vimrc.rookie @@ -2,7 +2,7 @@ " --------------- " Open File and Go to Line under Cursor -nnoremap gf gF +nmap gf gF " Move Along Words inoremap B diff --git a/install.sh b/install.sh index 90334c1..1d6823c 100755 --- a/install.sh +++ b/install.sh @@ -2,56 +2,31 @@ ## CONSTANTS -readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz" readonly DESTINATION=/opt/miaou-bash -readonly REQUIRED_PKGS=(file jq) +readonly MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz" ## FUNCTIONS -function push_directory { - pushd "$1" || (echo "unable to push directory <$1>" && exit 1) -} +function bootstrap { + if [[ ! -d "$DESTINATION" ]]; then + local temp_dir + temp_dir=$(mktemp -d) + pushd "$temp_dir" || return 2 + curl --no-progress-meter -O $MAIN_TAR_GZ_URL + tar -xzf main.tar.gz --directory "$DESTINATION" + popd || return 3 + fi + + local source_bin="$MIAOU_BASH_DIR/bin/miaou-bash" + local dest_bin="/usr/bin/miaou-bash" + cmp -s "$source_bin" "$dest_bin" || cp -f "$source_bin" "$dest_bin" -function pop_directory { - popd || (echo "unable to pop from previous directory" && exit 1) + export MIAOU_BASH_DIR="$DESTINATION" } ## MAIN -[[ "$UUID" -ne 0 ]] && echo 'root privilege required' && exit 1 - -if [[ -v MIAOU_BASH_DIR ]]; then - miaou-bash "$MIAOU_BASH_DIR/init.sh" -else - MIAOU_BASH_DIR="$DESTINATION" - export MIAOU_BASH_DIR - cd "$(mktemp -d)" - curl --no-progress-meter -O $MAIN_TAR_GZ_URL -fi - -if [[ $PWD != "$DESTINATION" ]]; then - # download and fullfill /opt/miaou-bash, then run it from folder - - if [[ -L /opt/miaou-bash ]]; then - /opt/miaou-bash/install.sh - else - rm -rf "$DESTINATION" - - pushd "$(mktemp -d)" - curl --no-progress-meter -O $MAIN_TAR_GZ_URL - tar -xzf main.tar.gz - mv miaou-bash /opt/ - pop_directory - rm -rf "$TEMP" - - push_directory /opt/miaou-bash && ./install.sh - - fi +[[ "$UID" -ne 0 ]] && echo 'root privilege required' && exit 1 -else - MIAOU_BASH_DIR=$CURDIR - export MIAOU_BASH_DIR - source "$MIAOU_BASH_DIR/lib/functions.bash" - "$MIAOU_BASH_DIR/tools/idem_apt_install" "${REQUIRED_PKGS[@]}" - ./init.sh -fi +[[ -v MIAOU_BASH_DIR ]] || bootstrap +miaou-bash "$MIAOU_BASH_DIR/lib/init.bash" diff --git a/init.sh b/lib/init.bash similarity index 55% rename from init.sh rename to lib/init.bash index d05515a..0faf49a 100755 --- a/init.sh +++ b/lib/init.bash @@ -1,14 +1,17 @@ -#!/bin/bash +#!/usr/bin/env miaou-bash # CONSTANTS -MIAOU_BASH_DIR=${MIAOU_BASH_DIR:-/opt/miaou-bash} -ORIGINAL="ORIGINAL" -PREDEFINED_CONFIG_FILES=(/etc/bash.bashrc /etc/inputrc) -readonly MIAOU_BASH_DIR ORIGINAL +readonly REQUIRED_PKGS=(file jq vim) +readonly ORIGINAL="ORIGINAL" +readonly PREDEFINED_CONFIG_FILES=(/etc/bash.bashrc /etc/inputrc) # FUNCTIONS +function required_packages { + "$MIAOU_BASH_DIR/tools/idem_apt_install" "${REQUIRED_PKGS[@]}" +} + function no_more_skeleton { [[ -e /etc/skel/.bashrc ]] && rm /etc/skel/.bashrc && echo "skeleton .bashrc removed!" true @@ -17,13 +20,12 @@ function no_more_skeleton { function predefine_config_files { for i in "${PREDEFINED_CONFIG_FILES[@]}"; do local miaou_file - miaou_file="${MIAOU_BASH_DIR}/$(basename "$i")" + miaou_file="${MIAOU_BASH_DIR}/etc/$(basename "$i")" if [[ -L "$i" ]]; then if [[ "$(readlink "$i")" == "${miaou_file}" ]]; then echo "$i => MIAOU_BASH_DIR already set!" else - rm "$i" - ln -s "${miaou_file}" "$i" + ln -sf "${miaou_file}" "$i" echo "$i => MIAOU_BASH_DIR freshly defined." fi else @@ -34,17 +36,11 @@ function predefine_config_files { done } -function bin_miaou_bash { - [[ ! -e /usr/bin/miaou-bash ]] && - ln -s "$MIAOU_BASH_DIR/bin/miaou-bash" /usr/bin/ && - echo "miaou-bash globally defined!" -} - # MAIN -set -TEeu -o pipefail -[ "$(id -u)" -ne 0 ] && echo 'root privilege required' && exit 1 +[ "$UID" -ne 0 ] && echo 'root privilege required' && exit 1 +source "$MIAOU_BASH_DIR/lib/functions.bash" +required_packages no_more_skeleton predefine_config_files -bin_miaou_bash