From 1be1134f9b78eec9f43e463784aa3357b4ff3435 Mon Sep 17 00:00:00 2001 From: pvincent Date: Fri, 21 Aug 2026 00:54:19 +0400 Subject: [PATCH] initialize rewritten --- lib/initiate.bash | 50 +++++++++++++++++++++------------------------- lib/uninstall.bash | 8 ++++++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/initiate.bash b/lib/initiate.bash index d9843ad..76c14cc 100644 --- a/lib/initiate.bash +++ b/lib/initiate.bash @@ -13,7 +13,7 @@ readonly AZERTY_ZONES=( 'Pacific/Tahiti' ) readonly REQUIRED_PKGS=(file jq vim git) -readonly BACKUP='ORIGINAL' +readonly BACKUP_SUFFIX='.ORIGINAL' # FUNCTIONS @@ -67,25 +67,22 @@ function fix_users_bashrc { } function link_etc { - local filename="$1" subfolder="${2:-}" - local link_name="$filename" - [[ -v LINK_NAME ]] && link_name="$LINK_NAME" - - local source="$MIAOU_BASH_DIR/etc" - local destination="/etc" - [[ -n "$subfolder" ]] && source+="/${subfolder}" && destination+="/${subfolder}" - if [[ -L "$destination/$link_name" ]]; then - if [[ "$(readlink "$destination/$link_name")" != "$source/$filename" ]]; then - ln -sf "$source/$filename" "$destination/$link_name" - echo "link $source/$link_name updated" + local source="$MIAOU_BASH_DIR/etc/$1" + local target="/etc/${2:-$1}" + + if [[ -L "$target" ]]; then + if [[ "$(readlink "$target")" != "$source" ]]; then + sudo ln -sf "$source" "$target" + echo "link $target updated" fi else - if [[ -f "$destination/$link_name" ]]; then - mv "$destination/$link_name" "$destination/$link_name.$BACKUP" - echo "$destination/$link_name.$BACKUP saved!" + if [[ -f "$target" ]]; then + sudo mv "$target" "$target$BACKUP_SUFFIX" + echo "$target$BACKUP_SUFFIX saved!" fi - ln -s "$source/$filename" "$destination/$link_name" - echo "link $source/$link_name created" + sudo mkdir -p "$(dirname "$target")" + sudo ln -s "$source" "$target" + echo "link $target created" fi } @@ -120,17 +117,17 @@ function is_debian_like { function link_config_files { is_arch_like && arch_vimrc && arch_profile - link_etc vimrc.core vim - link_etc vimrc.miaou vim - link_etc vimrc.rookie vim + link_etc vim/vimrc.core + link_etc vim/vimrc.miaou + link_etc vim/vimrc.rookie if in_azerty_zone 2>/dev/null; then - link_etc vimrc.azerty vim - LINK_NAME=vimrc.local link_etc vimrc.local.azerty vim + link_etc vim/vimrc.azerty + link_etc vim/vimrc.local.azerty vim/vimrc.local else - link_etc vimrc.local vim + link_etc vim/vimrc.local fi - link_etc 20-miaou-bash.sh profile.d + link_etc profile.d/20-miaou-bash.sh link_etc bash.bashrc link_etc inputrc # last command required to detect successful installation } @@ -171,8 +168,7 @@ function build_associative_user_homes { function ghostty_global_config { ! command -v ghostty >/dev/null && return # ghostty not yet installed! - sudo mkdir -p /etc/ghostty - link_etc config ghostty + link_etc ghostty/config if [[ ! -f /etc/skell/.config/ghostty/config ]]; then # ghostty config skeleton for new users @@ -206,8 +202,8 @@ function ghostty_global_config { # MAIN source "$MIAOU_BASH_DIR/lib/functions.bash" -assert_root +assert_root DISTRO_LIKE=$(fetch_distro_like) install_required_packages fix_users_bashrc diff --git a/lib/uninstall.bash b/lib/uninstall.bash index fcce83e..72590ac 100644 --- a/lib/uninstall.bash +++ b/lib/uninstall.bash @@ -26,8 +26,12 @@ function uninstall { sudo rm -f /usr/bin/miaou-bash sudo rm -rf /opt/miaou-bash - echo 'MIAOU-BASH fully uninstalled, previous settings have been restored from original' - echo -e "To reset your shell, please run:\n\texec bash -l" + cat <