Browse Source

fi_users_bashrc

main
pvincent 3 weeks ago
parent
commit
6aea0e3a06
  1. 3
      etc/skel/.bashrc
  2. 5
      install2.sh
  3. 45
      lib/initiate.bash

3
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

5
install2.sh

@ -1,7 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
## CONSTANTS ## 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" MAIN_TAR_GZ_URL="https://git.artcode.re/miaou/miaou-bash/archive/main.tar.gz"
## FUNCTIONS ## FUNCTIONS

45
lib/initiate.bash

@ -25,10 +25,24 @@ function install_required_packages {
. "$MIAOU_BASH_DIR"/tools/pkg_add "${REQUIRED_PKGS[@]}" . "$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 fi
} }
@ -116,6 +130,17 @@ function fix_terminfo_ghostty {
fi 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 </etc/passwd
fi
}
function ghostty_global_config { function ghostty_global_config {
! command -v ghostty >/dev/null && return ! command -v ghostty >/dev/null && return
@ -137,13 +162,11 @@ function ghostty_global_config {
echo "config-file = $global_config" >/etc/skel/.config/ghostty/config echo "config-file = $global_config" >/etc/skel/.config/ghostty/config
fi 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 local user_ghostty_config="$user_home"/.config/ghostty/config.ghostty
if [[ ! -f "$user_ghostty_config" ]]; then if [[ ! -f "$user_ghostty_config" ]]; then
sudo -u "$user" -- mkdir -p "$user_home"/.config/ghostty sudo -u "$user" -- mkdir -p "$user_home"/.config/ghostty
echo -e "# global config\nconfig-file = /etc/ghostty/config\n" | echo -e "# global config\nconfig-file = /etc/ghostty/config\n" |
@ -169,7 +192,7 @@ assert_root
DISTRO_LIKE=$(fetch_distro_like) DISTRO_LIKE=$(fetch_distro_like)
install_required_packages install_required_packages
rm_bashrc_skeleton
fix_users_bashrc
fix_terminfo_ghostty fix_terminfo_ghostty
ghostty_global_config ghostty_global_config
link_config_files link_config_files

Loading…
Cancel
Save