Server-Dotfiles/deploy.sh

103 lines
2.5 KiB
Bash
Raw Normal View History

2019-05-12 09:47:42 +02:00
#!/usr/bin/env bash
function find_package_manager() {
2019-05-12 11:25:21 +02:00
hash pacman &> /dev/null && echo pacman && return 0
hash apt-get &> /dev/null && echo apt-get && return 0
hash apk &> /dev/null && echo apk && return 0
2019-05-12 09:47:42 +02:00
return 1
}
function install_package() {
package_manager=$(find_package_manager)
if [[ $? -ne 0 ]]; then
2019-05-12 11:29:30 +02:00
echo -e "\033[38;5;1mCould not find package manager\033[0;5;0m" >&2
return 1
2019-05-12 09:47:42 +02:00
fi
2019-05-12 11:25:21 +02:00
case $package_manager in
2019-05-12 09:47:42 +02:00
pacman)
2019-06-01 12:50:37 +02:00
sudo pacman -S --noconfirm $*
2019-05-12 11:29:30 +02:00
return $?
2019-05-12 09:47:42 +02:00
;;
apt-get)
2019-06-01 12:50:37 +02:00
sudo apt-get install -y $*
2019-05-12 11:29:30 +02:00
return $?
2019-05-12 09:47:42 +02:00
;;
apk)
sudo apk add $*
2019-05-12 11:29:30 +02:00
return $?
2019-05-12 09:47:42 +02:00
;;
esac
2019-05-12 11:29:30 +02:00
return 2
2019-05-12 09:47:42 +02:00
}
function check_and_install() {
if hash $1 &> /dev/null; then
2019-05-12 11:29:30 +02:00
echo -e "\033[38;5;2m$1 is already installed.\033[0;5;0m"
2019-05-12 09:47:42 +02:00
else
2019-05-12 11:29:30 +02:00
echo -e "\033[38;5;2mInstalling $1.\033[0;5;0m"
2019-05-12 09:47:42 +02:00
if install_package $1; then
2019-05-12 11:29:30 +02:00
echo -e "\033[38;5;2m$1 installed.\033[0;5;0m"
2019-05-12 09:47:42 +02:00
else
2019-05-12 11:29:30 +02:00
echo -e "\033[38;5;1mInstalling $1 failed.\033[0;5;0m" >&2
2019-05-12 09:47:42 +02:00
fi
fi
}
2019-05-12 10:33:33 +02:00
function stow_cfg() {
echo -e "\033[38;5;2mStowing $1"
stow $1
}
2019-05-12 09:47:42 +02:00
package_manager=$(find_package_manager)
if [[ $? -ne 0 ]]; then
echo -e "\033[38;5;1mCould not find package manager" >&2
else
echo -e "\033[38;5;2mPackage manager: $package_manager"
fi
2019-05-12 10:33:33 +02:00
bd=$(dirname $0)
cd "$bd"
2019-05-12 11:29:30 +02:00
echo -e "\033[38;5;2mBase Directory: $(pwd)\n\033[0;5;0m"
echo -e "\033[38;5;2mInstalling packages\n\033[0;5;0m"
2019-05-12 09:47:42 +02:00
check_and_install stow
check_and_install bash
check_and_install tmux
check_and_install vim
2019-05-12 10:33:33 +02:00
check_and_install curl
2019-05-12 11:25:21 +02:00
check_and_install git
2019-05-12 13:24:00 +02:00
check_and_install jq
2019-05-12 10:33:33 +02:00
2019-05-12 11:29:30 +02:00
echo -e "\n\033[38;5;2mStowing config\033[0;5;0m\n"
2019-05-12 10:33:33 +02:00
2019-05-12 11:25:21 +02:00
mv ~/.tmux.conf{,.old} &> /dev/null
mv ~/.tmux{,.old} &> /dev/null
stow_cfg tmux
mv ~/.vimrc{,.old} &> /dev/null
mv ~/.vim{,.old} &> /dev/null
stow_cfg vim
2019-05-12 11:29:30 +02:00
echo -e "\n\033[38;5;2mSetting up wish\033[0;5;0m\n"
2019-05-12 11:25:21 +02:00
mkdir -p ~/.config/
git clone https://gitlab.com/ceda_ei/wish.git ~/.config/wish
2020-01-19 09:30:02 +01:00
mv ~/.bashrc{,.old} &> /dev/null
mv ~/.bash_profile{,.old} &> /dev/null
stow_cfg bash
2019-05-12 11:29:30 +02:00
echo -e "\n\033[38;5;2mSetting up tmux plugins\033[0;5;0m\n"
2019-05-12 11:25:21 +02:00
mkdir -p ~/.tmux/plugins/
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
~/.tmux/plugins/tpm/bin/install_plugins
2019-05-12 11:29:30 +02:00
echo -e "\n\033[38;5;2mSetting up vim plugins\033[0;5;0m\n"
2019-05-12 11:25:21 +02:00
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
vim +PlugInstall +qall
2019-05-12 13:18:29 +02:00
echo -e "\n\033[38;5;2mSetting up bin-client\033[0;5;0m\n"
git clone https://git.webionite.com/ceda_ei/bin-client ~/bin-client
2019-05-12 11:29:30 +02:00
echo -e "\n\033[38;5;2mComplete\033[0;5;0m\n"