diff --git a/README.md b/README.md index efedfd1..1b2381e 100644 --- a/README.md +++ b/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 diff --git a/lib/init.bash b/lib/init.bash index 0faf49a..187e62a 100755 --- a/lib/init.bash +++ b/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!" - else - ln -sf "${miaou_file}" "$i" - echo "$i => MIAOU_BASH_DIR freshly defined." - fi +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 - mv "$i" "$i.$ORIGINAL" - ln -s "${miaou_file}" "$i" - echo "$i => MIAOU_BASH_DIR freshly defined + .ORIGINAL backuped" + echo "link $source/$filename already enabled!" + fi + else + if [[ -f "$destination/$filename" ]]; then + mv "$destination/$filename" "$destination/$filename.$BACKUP" + echo "$destination/$filename.$BACKUP saved!" fi - done + ln -s "$source/$filename" "$destination" + echo "link $source/$filename created" + fi +} + +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