pvincent 4 days ago
parent
commit
e863bd0c6e
  1. 2
      README.md
  2. 49
      lib/init.bash

2
README.md

@ -31,7 +31,7 @@ Any feedback would be appreciated.
## install
```bash
curl https://git.artcode.re/miaou/miaou-bash/raw/branch/main/install.sh | sudo bash -s`
curl -s https://git.artcode.re/miaou/miaou-bash/raw/branch/main/install.sh | sudo bash -s`
```
## upgrade

49
lib/init.bash

@ -3,8 +3,7 @@
# CONSTANTS
readonly REQUIRED_PKGS=(file jq vim)
readonly ORIGINAL="ORIGINAL"
readonly PREDEFINED_CONFIG_FILES=(/etc/bash.bashrc /etc/inputrc)
readonly BACKUP='ORIGINAL'
# FUNCTIONS
@ -13,33 +12,47 @@ function required_packages {
}
function no_more_skeleton {
[[ -e /etc/skel/.bashrc ]] && rm /etc/skel/.bashrc && echo "skeleton .bashrc removed!"
true
if [[ -e /etc/skel/.bashrc ]]; then
rm /etc/skel/.bashrc
echo "skeleton .bashrc removed!"
fi
}
function predefine_config_files {
for i in "${PREDEFINED_CONFIG_FILES[@]}"; do
local miaou_file
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!"
function link_etc {
local filename="$1" subfolder="${2:-}"
local source="$MIAOU_BASH_DIR/etc"
local destination="/etc"
[[ -n "$subfolder" ]] && source+="/${subfolder}" && destination+="/${subfolder}"
if [[ -L "$destination/$filename" ]]; then
if [[ "$(readlink "$destination/$filename")" != "$source/$filename" ]]; then
ln -sf "$source/$filename" "$destination"
echo "link $source/$filename updated"
else
ln -sf "${miaou_file}" "$i"
echo "$i => MIAOU_BASH_DIR freshly defined."
echo "link $source/$filename already enabled!"
fi
else
mv "$i" "$i.$ORIGINAL"
ln -s "${miaou_file}" "$i"
echo "$i => MIAOU_BASH_DIR freshly defined + .ORIGINAL backuped"
if [[ -f "$destination/$filename" ]]; then
mv "$destination/$filename" "$destination/$filename.$BACKUP"
echo "$destination/$filename.$BACKUP saved!"
fi
ln -s "$source/$filename" "$destination"
echo "link $source/$filename created"
fi
done
}
function predefine_config_files {
link_etc bash.bashrc
link_etc inputrc
link_etc vimrc.azerty vim
link_etc vimrc.core vim
link_etc vimrc.local vim
link_etc vimrc.miaou vim
link_etc vimrc.rookie vim
}
# MAIN
[ "$UID" -ne 0 ] && echo 'root privilege required' && exit 1
source "$MIAOU_BASH_DIR/lib/functions.bash"
required_packages
no_more_skeleton

Loading…
Cancel
Save