4 changed files with 4 additions and 132 deletions
@ -1,128 +0,0 @@ |
|||||
#!/usr/bin/env miaou-bash |
|
||||
|
|
||||
# CONSTANTS |
|
||||
|
|
||||
readonly AZERTY_ZONES=( |
|
||||
'Europe/Paris' |
|
||||
'Indian/Reunion' |
|
||||
'Indian/Mayotte' |
|
||||
'America/Cayenne' |
|
||||
'America/Guadeloupe' |
|
||||
'America/Martinique' |
|
||||
'Pacific/Noumea' |
|
||||
'Pacific/Tahiti' |
|
||||
) |
|
||||
readonly REQUIRED_PKGS=(file jq vim git) |
|
||||
readonly BACKUP='ORIGINAL' |
|
||||
|
|
||||
# FUNCTIONS |
|
||||
|
|
||||
function usr_bin_miaou_bash { |
|
||||
local source_bin="$MIAOU_BASH_DIR/bin/miaou-bash" |
|
||||
local dest_bin="/usr/bin/miaou-bash" |
|
||||
if ! [[ -f "$dest_bin" ]]; then |
|
||||
cp -f "$source_bin" "$dest_bin" |
|
||||
echo "/usr/bin/miaou-bash created" |
|
||||
elif ! cmp -s "$source_bin" "$dest_bin"; then |
|
||||
cp -f "$source_bin" "$dest_bin" |
|
||||
echo "/usr/bin/miaou-bash updated" |
|
||||
fi |
|
||||
} |
|
||||
|
|
||||
function install_required_packages { |
|
||||
. "$MIAOU_BASH_DIR"/tools/pkg_add "${REQUIRED_PKGS[@]}" |
|
||||
} |
|
||||
|
|
||||
function no_more_skeleton { |
|
||||
if [[ -e /etc/skel/.bashrc ]]; then |
|
||||
rm /etc/skel/.bashrc |
|
||||
echo "skeleton .bashrc removed!" |
|
||||
fi |
|
||||
} |
|
||||
|
|
||||
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" |
|
||||
fi |
|
||||
else |
|
||||
if [[ -f "$destination/$link_name" ]]; then |
|
||||
mv "$destination/$link_name" "$destination/$link_name.$BACKUP" |
|
||||
echo "$destination/$link_name.$BACKUP saved!" |
|
||||
fi |
|
||||
ln -s "$source/$filename" "$destination/$link_name" |
|
||||
echo "link $source/$link_name created" |
|
||||
fi |
|
||||
} |
|
||||
|
|
||||
function arch_vimrc { |
|
||||
mkdir -p /etc/vim |
|
||||
if ! grep -q '/etc/vim/vimrc.local' /etc/vimrc; then |
|
||||
cat >>/etc/vimrc <<-EOF |
|
||||
" Source a global configuration file if available |
|
||||
if filereadable("/etc/vim/vimrc.local") |
|
||||
source /etc/vim/vimrc.local |
|
||||
endif |
|
||||
EOF |
|
||||
echo "vimrc source /etc/vim/vimrc.local if any" |
|
||||
fi |
|
||||
|
|
||||
} |
|
||||
|
|
||||
function link_config_files { |
|
||||
[[ "$DISTRO_LIKE" == 'arch' ]] && arch_vimrc |
|
||||
|
|
||||
link_etc vimrc.core vim |
|
||||
link_etc vimrc.miaou vim |
|
||||
link_etc vimrc.rookie vim |
|
||||
|
|
||||
if in_azerty_zone 2>/dev/null; then |
|
||||
link_etc vimrc.azerty vim |
|
||||
LINK_NAME=vimrc.local link_etc vimrc.local.azerty vim |
|
||||
else |
|
||||
link_etc vimrc.local vim |
|
||||
fi |
|
||||
link_etc bash.bashrc |
|
||||
link_etc inputrc # last command required to detect successful installation |
|
||||
} |
|
||||
|
|
||||
function bind_inputrc { |
|
||||
bind -f /etc/inputrc 2>/dev/null # arch: dismiss harmless warning |
|
||||
} |
|
||||
|
|
||||
function in_azerty_zone { |
|
||||
[[ -L /etc/localtime ]] || return 1 |
|
||||
|
|
||||
local zone |
|
||||
zone=$(readlink /etc/localtime) |
|
||||
zone="${zone#/usr/share/zoneinfo/}" # remove prefix |
|
||||
for i in "${AZERTY_ZONES[@]}"; do [[ "$zone" == "$i" ]] && return; done |
|
||||
return 1 |
|
||||
} |
|
||||
|
|
||||
function fix_terminfo_ghostty { |
|
||||
if ! infocmp xterm-ghostty >/dev/null 2>&1; then |
|
||||
tic -x "$MIAOU_BASH_DIR"/assets/terminfo/ghostty 2>/dev/null |
|
||||
echo 'terminfo ghostty succesfully compiled' |
|
||||
fi |
|
||||
} |
|
||||
|
|
||||
# MAIN |
|
||||
|
|
||||
source "$MIAOU_BASH_DIR/lib/functions.bash" |
|
||||
assert_root |
|
||||
usr_bin_miaou_bash |
|
||||
DISTRO_LIKE=$(fetch_distro_like) |
|
||||
install_required_packages |
|
||||
no_more_skeleton |
|
||||
fix_terminfo_ghostty |
|
||||
link_config_files |
|
||||
bind_inputrc |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue