Skip to content
install.sh 4.24 KiB
Newer Older
#!/bin/bash

REPO_URL="http://code.jity.de/Jack12816/linux-environment.git"

if [ -z "$INSTALL_DIR" ]; then
    INSTALL_DIR="$HOME/.linux-environment"
fi

function check_system
{
    if [ -z `which dialog` ]; then
        echo 'The `dialog` binary was not found. Please install the according package.'
        echo
        echo 'Debian/Ubuntu: sudo apt-get install dialog'
        echo 'ArchLinux: sudo pacman -S dialog'
        exit 1
    fi

    if [ -z `which git` ]; then
        echo 'The `git` binary was not found. Please install the according package.'
        echo
        echo 'Debian/Ubuntu: sudo apt-get install git'
        echo 'ArchLinux: sudo pacman -S git'
        exit 1
    fi

    if [ -z `which vim` ]; then
        echo 'The `vim` binary was not found. Please install the according package.'
        echo
        echo 'Debian/Ubuntu: sudo apt-get install vim'
        echo 'ArchLinux: sudo pacman -S vim'
        exit 1
    fi

    if [ -d "$HOME/.bashrc.d" -o -d "$HOME/.linux-environment" ]; then
        dialog --msgbox 'You already installed the project! - No need to do anything here.' 0 0
        exit 1
    fi
}

function confirm_installation
{
    dialog --yesno 'Do you want to continue the installation?' 0 0 || \
        exit 1
}

function clone_project
{
    git clone "$REPO_URL" "$INSTALL_DIR" || \
        (dialog --msgbox 'The downloading of the project failed.' 0 0; exit 1)
}

function backup_path
{
    if [ -e "$1" ]; then
        echo "  Backup ${1}.."
        mv "$1" "${1}.bak"
    fi
}

function install_configs
{
    echo "Backup already existing config files.."
    backup_path "$HOME/.bash_logout"
    backup_path "$HOME/.bash_profile"
    backup_path "$HOME/.ctags"
    backup_path "$HOME/.dir_colors"
    backup_path "$HOME/.gemrc"
    backup_path "$HOME/.gitconfig"
    backup_path "$HOME/.gitignore"
    backup_path "$HOME/.inputrc"
    backup_path "$HOME/.fonts"
    backup_path "$HOME/.vim"
    backup_path "$HOME/.bashrc"
    backup_path "$HOME/.vimrc"

    echo "Setup the configs directory ($HOME/.bashrc.d/).."
    cd "$INSTALL_DIR"
    mkdir -p ~/.bashrc.d
    eval `find config/*.dist \
        | awk '{printf "cp -T " $0; gsub(/\.dist|config\//,""); print " ~/.bashrc.d/" $0 ";"}'`

    echo "Link the dot files to your home.."
    cd dot && cp `pwd`/.* ~; cd ..
    cd dotrc && ln -s `pwd`/.* ~; cd ..

    echo "Update the font cache.."
    fc-cache -fr
}

function configure_project
{
    # Git configuration
    dialog --inputbox 'Enter your fullname for the git configuration.' 0 0 \
        2>/tmp/.git.fullname
    dialog --inputbox 'Enter your email address for the git configuration.' 0 0 \
        2>/tmp/.git.email
    cp "$HOME/.gitconfig.dist" "$HOME/.gitconfig"
    sed -i "s#^    name .*#    name  = `cat /tmp/.git.fullname`#g" "$HOME/.gitconfig"
    sed -i "s#^    email .*#    email = `cat /tmp/.git.email`#g" "$HOME/.gitconfig"

    # Vim configuration
    dialog --checklist 'Choose the bundles for Vim you would like to install.' 0 0 0 \
        "VimRCBundlesDevel" "Generic development stuff" "off" \
        "VimRCBundlesSysAdmin" "Sysadmin stuff like Puppet" "off" \
        "VimRCBundlesHTML" "Some bundles to work with HTML" "off" \
        "VimRCBundlesPython" "Python bundles" "off" \
        "VimRCBundlesPHP" "PHP bundles" "off" \
        "VimRCBundlesJava" "Java bundles" "off" \
        "VimRCBundlesJavaScript" "JavaScript bundles" "off" \
        "VimRCBundlesRuby" "Ruby bundles" "off" \
        2>/tmp/.vimrc.bundles

    for KEY in $(cat /tmp/.vimrc.bundles); do
        sed -i "/$KEY/s/^\" //" "$HOME/.bashrc.d/vim.conf"
    done
}

function install_vim_bundles
{
    dialog --msgbox 'The configuration was done. Now we install the configured Vim bundles.' 0 0
    </dev/tty vim +PluginInstall +qall
function install_php_ctags
{
    dialog --yesno 'Do you want to install Ctags support for PHP?' 0 0 || \
        return 1
    cd "$INSTALL_DIR/dotrc/.vim/tools" && \
        git clone https://github.com/techlivezheng/phpctags.git && \
        cd phpctags && \
        make
}

function installation_done
{
    dialog --msgbox 'The installation was completed.' 0 0
}

# Perform the installation receipt
check_system
confirm_installation
clone_project
install_configs
configure_project
install_vim_bundles