diff --git a/packages/accessories.sh b/packages/accessories.sh index 611ec33..dc852e6 100755 --- a/packages/accessories.sh +++ b/packages/accessories.sh @@ -7,14 +7,14 @@ POTIONS_HOME="$USER_HOME_FOLDER/.potions" ZDOTDIR=$POTIONS_HOME update_repositories() { - echo "Updating repositories..." + log "Updating repositories..." if is_macos; then brew update elif is_termux; then pkg update elif is_wsl || is_linux; then if is_apt_package_manager; then - echo "If you do not need sudo for any reason, modify this script!" + log "If you do not need sudo for any reason, modify this script!" sudo apt-get update else exit_with_message "No supported package manager have been found! Consider move to another environment supported! Or create a patch! :)" @@ -83,46 +83,44 @@ is_apt_package_manager() { # Function to check and create directory ensure_directory() { - local dir="$1" - if [ -d "$dir" ]; then - log "Directory '$dir' already exists." + local dir="$1" + if [ -d "$dir" ]; then + log "Directory '$dir' already exists." + else + log "Directory '$dir' does not exist. Creating..." + mkdir -p "$dir" + if [ $? -eq 0 ]; then + log "Successfully created directory '$dir'." else - log "Directory '$dir' does not exist. Creating..." - mkdir -p "$dir" - if [ $? -eq 0 ]; then - log "Successfully created directory '$dir'." - else - log "Error: Failed to create directory '$dir'." >&2 - exit 1 - fi + exit_with_message "Error: Failed to create directory '$dir'." fi + fi } ensure_files() { - local dir="$1" - shift - local files=("$@") - - for file in "${files[@]}"; do - local filepath="$dir/$file" - if [ -f "$filepath" ]; then - echo "File '$filepath' already exists." - else - echo "File '$filepath' does not exist. Creating..." - touch "$filepath" - if [ $? -eq 0 ]; then - echo "Successfully created file '$filepath'." - else - echo "Error: Failed to create file '$filepath'." >&2 - exit 1 - fi - fi - done + local dir="$1" + shift + local files=("$@") + + for file in "${files[@]}"; do + local filepath="$dir/$file" + if [ -f "$filepath" ]; then + log "File '$filepath' already exists." + else + log "File '$filepath' does not exist. Creating..." + touch "$filepath" + if [ $? -eq 0 ]; then + log "Successfully created file '$filepath'." + else + exit_with_message "Error: Failed to create file '$filepath'." + fi + fi + done } # Beautifully message and go! exit_with_message() { - echo $1 - echo "Terminating Potions Routines..." + log $1 + log "Terminating Potions Routines..." exit 1 } diff --git a/packages/common/antidote.sh b/packages/common/antidote.sh index fab3c85..f210935 100755 --- a/packages/common/antidote.sh +++ b/packages/common/antidote.sh @@ -5,10 +5,10 @@ source "$(dirname "$0")/packages/accessories.sh" # Function to install Antidote install_package() { if [ -d "${ZDOTDIR:-$POTIONS_HOME}/.antidote" ]; then - echo "Antidote is already installed." + log "Antidote is already installed." else - echo "Installing Antidote..." - git clone --depth=1 https://github.com/mattmc3/antidote.git ${POTIONS_HOME:-$POTIONS_HOME}/.antidote + log "Installing Antidote..." + git clone --depth=1 https://github.com/mattmc3/antidote.git ${ZDOTDIR:-$POTIONS_HOME}/.antidote fi } diff --git a/packages/common/curl.sh b/packages/common/curl.sh index 241d6b2..c46dae8 100755 --- a/packages/common/curl.sh +++ b/packages/common/curl.sh @@ -5,17 +5,17 @@ source "$(dirname "$0")/packages/accessories.sh" # Function to install curl install_package() { if command_exists curl; then - echo "curl is already installed." + log "curl is already installed." else - echo "Installing curl..." + log "Installing curl..." if is_macos; then - safe_source "$(dirname "$0")/packages/macos/curl.sh" + unpack_it 'macos/curl' elif is_termux; then - safe_source "$(dirname "$0")/packages/termux/curl.sh" + unpack_it 'termux/curl' elif is_wsl; then - safe_source "$(dirname "$0")/packages/wsl/curl.sh" + unpack_it 'wsl/curl' elif is_linux; then - safe_source "$(dirname "$0")/packages/debian/curl.sh" + unpack_it 'debian/curl' fi fi } diff --git a/packages/common/git.sh b/packages/common/git.sh index c6cf524..eaf83b8 100755 --- a/packages/common/git.sh +++ b/packages/common/git.sh @@ -5,9 +5,9 @@ source "$(dirname "$0")/packages/accessories.sh" # Function to install Git install_package() { if command_exists git; then - echo "Git is already installed." + log "Git is already installed." else - echo "Installing Git..." + log "Installing Git..." if is_macos; then safe_source "$(dirname "$0")/packages/macos/git.sh" elif is_termux; then diff --git a/packages/common/openvpn.sh b/packages/common/openvpn.sh index 7eb8b13..8dcd6fc 100755 --- a/packages/common/openvpn.sh +++ b/packages/common/openvpn.sh @@ -5,17 +5,17 @@ source "$(dirname "$0")/packages/accessories.sh" # Function to install OpenVPN install_package() { if command_exists openvpn; then - echo "OpenVPN is already installed." + log "OpenVPN is already installed." else - echo "Installing ..." + log "Installing OpenVPN..." if is_macos; then - safe_source "$(dirname "$0")/packages/macos/openvpn.sh" + unpack_it 'macos/openvpn' elif is_termux; then - safe_source "$(dirname "$0")/packages/termux/openvpn.sh" + unpack_it 'termux/openvpn' elif is_wsl; then - safe_source "$(dirname "$0")/packages/wsl/openvpn.sh" + unpack_it 'wsl/openvpn' elif is_linux; then - safe_source "$(dirname "$0")/packages/debian/openvpn.sh" + unpack_it 'debian/openvpn' fi fi } diff --git a/packages/common/tmux.sh b/packages/common/tmux.sh index 947eac1..f0409f4 100755 --- a/packages/common/tmux.sh +++ b/packages/common/tmux.sh @@ -2,27 +2,26 @@ source "$(dirname "$0")/packages/accessories.sh" - # Function to install TMUX install_package() { if command_exists tmux; then - echo "TMUX is already installed." + log "TMUX is already installed." else - echo "Installing TMUX..." + log "Installing TMUX..." if is_macos; then - safe_source "$(dirname "$0")/packages/macos/tmux.sh" + unpack_it 'macos/tmux' elif is_termux; then - safe_source "$(dirname "$0")/packages/termux/tmux.sh" + unpack_it 'termux/tmux' elif is_wsl; then - safe_source "$(dirname "$0")/packages/wsl/tmux.sh" + unpack_it 'wsl/tmux' elif is_linux; then - safe_source "$(dirname "$0")/packages/debian/tmux.sh" + unpack_it 'debian/tmux' fi fi } prepare_package() { - mkdir -p $POTIONS_HOME/tmux/plugins + ensure_directory "$POTIONS_HOME/tmux/plugins" } configure_package() { diff --git a/packages/common/vim-plug.sh b/packages/common/vim-plug.sh index fa89c9a..06e3ea2 100755 --- a/packages/common/vim-plug.sh +++ b/packages/common/vim-plug.sh @@ -5,17 +5,17 @@ source "$(dirname "$0")/packages/accessories.sh" # Function to install Vim-Plug install_package() { if [ -d "${XDG_DATA_HOME:-$USER_HOME_FOLDER/.local/share}/nvim/site/autoload" ]; then - echo "Vim-Plug is already installed." + log "Vim-Plug is already installed." else - echo "Installing Vim-Plug..." + log "Installing Vim-Plug..." sh -c 'curl -fLo "${XDG_DATA_HOME:-$USER_HOME_FOLDER/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' fi } configure_package() { - mkdir -p $USER_HOME_FOLDER/.config/nvim - mkdir -p $POTIONS_HOME/plugged + ensure_directory "$USER_HOME_FOLDER/.config/nvim" + ensure_directory "$POTIONS_HOME/plugged" echo "source $POTIONS_HOME/nvim/init.vim" > ~/.config/nvim/init.vim } diff --git a/packages/common/wget.sh b/packages/common/wget.sh index c97ddba..f70f8d0 100755 --- a/packages/common/wget.sh +++ b/packages/common/wget.sh @@ -5,17 +5,17 @@ source "$(dirname "$0")/packages/accessories.sh" # Function to install wget install_package() { if command_exists wget; then - echo "wget is already installed." + log "wget is already installed." else - echo "Installing wget..." + log "Installing wget..." if is_macos; then - safe_source "$(dirname "$0")/packages/macos/wget.sh" + unpack_it 'macos/wget' elif is_termux; then - safe_source "$(dirname "$0")/packages/termux/wget.sh" + unpack_it 'termux/wget' elif is_wsl; then - safe_source "$(dirname "$0")/packages/wsl/wget.sh" + unpack_it 'wsl/wget' elif is_linux; then - safe_source "$(dirname "$0")/packages/debian/wget.sh" + unpack_it 'debian/wget' fi fi } diff --git a/packages/common/zsh.sh b/packages/common/zsh.sh index 2724f2f..0341451 100755 --- a/packages/common/zsh.sh +++ b/packages/common/zsh.sh @@ -5,17 +5,17 @@ source "$(dirname "$0")/packages/accessories.sh" # Function to install Zsh install_package() { if command_exists zsh; then - echo "Zsh is already installed." + log "Zsh is already installed." else - echo "Installing Zsh..." + log "Installing Zsh..." if is_macos; then - safe_source "$(dirname "$0")/packages/macos/zsh.sh" + unpack_it 'macos/zsh' elif is_termux; then - safe_source "$(dirname "$0")/packages/termux/zsh.sh" + unpack_it 'termux/zsh' elif is_wsl; then - safe_source "$(dirname "$0")/packages/wsl/zsh.sh" + unpack_it 'wsl/zsh' elif is_linux; then - safe_source "$(dirname "$0")/packages/debian/zsh.sh" + unpack_it 'debian/zsh' fi fi } @@ -27,7 +27,9 @@ configure_package() { source .zshenv fi - chsh -s zsh + if is_termux; then + chsh -s zsh + fi } install_package