From 6aea0e3a06a99b0bab2aad77bf38a1890dcd976a Mon Sep 17 00:00:00 2001 From: pvincent Date: Tue, 18 Aug 2026 17:31:03 +0400 Subject: [PATCH] fi_users_bashrc --- etc/skel/.bashrc | 3 +++ install2.sh | 5 ++++- lib/initiate.bash | 45 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 etc/skel/.bashrc diff --git a/etc/skel/.bashrc b/etc/skel/.bashrc new file mode 100644 index 0000000..cce1ced --- /dev/null +++ b/etc/skel/.bashrc @@ -0,0 +1,3 @@ +# Keep these top-most lines for safe scripting +# If not running interactively, don't do anything +[[ $- != *i* ]] && return diff --git a/install2.sh b/install2.sh index 31b6686..31bde06 100755 --- a/install2.sh +++ b/install2.sh @@ -1,7 +1,10 @@ #!/usr/bin/env bash - ## CONSTANTS +#TODO: LATEST_TAG +# LATEST_TAG=$(curl -s https://git.artcode.re/api/v1/repos/miaou/miaou-bash/tags|grep -oPm1 '{"name":".*?",' | head -n1 | cut -d'"' -f4) +# https://git.artcode.re/miaou/miaou-bash/archive/0.3.109.tar.gz + MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz" ## FUNCTIONS diff --git a/lib/initiate.bash b/lib/initiate.bash index c1739f2..4f3424e 100644 --- a/lib/initiate.bash +++ b/lib/initiate.bash @@ -25,10 +25,24 @@ function install_required_packages { . "$MIAOU_BASH_DIR"/tools/pkg_add "${REQUIRED_PKGS[@]}" } -function rm_bashrc_skeleton { - if [[ -e /etc/skel/.bashrc ]]; then - rm /etc/skel/.bashrc - echo "skeleton .bashrc removed!" +function fix_users_bashrc { + # for new users + if ! cmp -s /etc/skill/.bashrc "$MIAOU_BASH_DIR"/etc/skel/.bashrc; then + sudo mv /etc/skill/.bashrc /etc/skill/.bashrc.ORIGINAL + sudo ln -sf "$MIAOU_BASH_DIR"/etc/skel/.bashrc /etc/skel/.bashrc + + # for pre-existant users + build_associative_user_homes + for user in "${!USER_HOMES[@]}"; do + local user_bashrc="${USER_HOMES[$user]}/.bashrc" + [[ ! -f "$user_bashrc" ]] && next + cmp -s "$user_bashrc" "$MIAOU_BASH_DIR"/etc/skell/.bashrc && next + + local backup="$user_bashrc".ORIGINAL + sudo -u "$user" -- mv "$user_bashrc" "$backup" + sudo -u "$user" -- cp "$MIAOU_BASH_DIR"/etc/skell/.bashrc "$user_bashrc" + >&2 echo "WARN: .bashrc for user <$user> has already been diverged, please resolve conflict manually from backup: $backup" + done fi } @@ -116,6 +130,17 @@ function fix_terminfo_ghostty { fi } +function build_associative_user_homes { + if [[ ! -v USER_HOMES ]]; then + declare -gA USER_HOMES + while IFS=: read -r user _ uid _ _ home _; do + if [[ $uid -ge 1000 && $user != 'nobody' ]]; then + USER_HOMES[$user]="$home" + fi + done /dev/null && return @@ -137,13 +162,11 @@ function ghostty_global_config { echo "config-file = $global_config" >/etc/skel/.config/ghostty/config fi - # change ghostty configuration for any normal user UID>=1000 - mapfile -t normal_users < <(awk -F: '$3 >= 1000 && $1 != "nobody" { print $1 }' /etc/passwd) - for user in "${normal_users[@]}"; do - local user_home - user_home=$(getent passwd "$user" | cut -d: -f6) + # change ghostty configuration for any normal user + build_associative_user_homes + for user in "${!USER_HOMES[@]}"; do + local user_home="${USER_HOMES[$user]}" local user_ghostty_config="$user_home"/.config/ghostty/config.ghostty - if [[ ! -f "$user_ghostty_config" ]]; then sudo -u "$user" -- mkdir -p "$user_home"/.config/ghostty echo -e "# global config\nconfig-file = /etc/ghostty/config\n" | @@ -169,7 +192,7 @@ assert_root DISTRO_LIKE=$(fetch_distro_like) install_required_packages -rm_bashrc_skeleton +fix_users_bashrc fix_terminfo_ghostty ghostty_global_config link_config_files