# SPDX-License-Identifier: GPL-3.0-or-later
#
# Copyright (C) 2019 Nathan Chancellor
#
# Generic server environment setup script (usually for something like Vultr or Packet)
#
# Install zsh before hand and use 'chsh -s /bin/zsh $(whoami)'

function bootstrap() {(
    # Get list of packages to be installed
    # Debian/Ubuntu
    if command -v apt &>/dev/null; then
        PACKAGES=( bison
                   build-essential
                   ca-certificates
                   clang
                   cmake
                   curl
                   doxygen
                   file
                   flex
                   gcc
                   gettext
                   git
                   g++
                   libauthen-sasl-perl
                   libcurl4-openssl-dev
                   libedit-dev
                   libemail-valid-perl
                   libelf-dev
                   libevent-dev
                   libexpat1-dev
                   libio-socket-ssl-perl
                   libmailtools-perl
                   libncurses-dev
                   libnet-smtp-ssl-perl
                   libpcre2-dev
                   libssl-dev
                   locales
                   make
                   mosh
                   most
                   ninja-build
                   python3
                   python3-dev
                   sudo
                   swig
                   texinfo
                   tmux
                   u-boot-tools
                   vim
                   zsh
                   zlib1g-dev )

        if [[ $(whoami) = "root" ]]; then
            APT=( apt )
        else
            APT=( sudo apt )
        fi

        "${APT[@]}" update || exit ${?}
        "${APT[@]}" upgrade -y || exit ${?}
        "${APT[@]}" install -y --no-install-recommends "${PACKAGES[@]}" || exit ${?}
        sudo dpkg-reconfigure locales
    fi

    source <(curl -LSs https://github.com/nathanchance/scripts/raw/master/common) &>/dev/null || return 1

    SCRIPTS=${HOME}/scripts
    [[ -d ${SCRIPTS} ]] || { git clone https://github.com/nathanchance/scripts "${SCRIPTS}" || die "Error cloning scripts!"; }
    source "${SCRIPTS}"/env/setup && global_gitignore && create_zshrc
    source "${SCRIPTS}"/funcs/bldupdbin && { bldupdbin || exit ${?}; }
    path_push "${HOME}/usr/bin"
    source "${SCRIPTS}"/funcs/git && git_setup
    source "${SCRIPTS}"/funcs/pure && pure_prompt

    DOTFILES=${HOME}/dotfiles
    [[ -d ${DOTFILES} ]] || { git clone https://github.com/nathanchance/dotfiles "${DOTFILES}" || die "Error cloning dotfiles!"; }
    zsh "${DOTFILES}"/common/vim/vim_setup.sh
    cp -v "${DOTFILES}"/server/.tmux.conf "${HOME}"
)}

function generic_aliases() { true; }
function generic_setup() { true; }
# vi: filetype=zsh