bootstrap/bootstrap.sh

168 lines
3.9 KiB
Bash
Raw Normal View History

2022-02-26 16:39:46 +01:00
#!/bin/bash
2022-08-24 21:04:22 +02:00
NAME="waldek"
EMAIL="waldek@mailbox.org"
2022-08-24 23:24:27 +02:00
DEFAULT_SHELL="xonsh"
2022-08-24 21:04:22 +02:00
DEPENDENCIES_APT="zsh git tig tmux vim-nox htop python3 python3-pip"
DEPENDENCIES_PIP="xonsh[full]"
2022-08-24 21:04:22 +02:00
2022-08-24 23:08:03 +02:00
SOURCES_DIR=~/sources/gitea_irisib
2022-08-24 22:26:28 +02:00
BOOTSTRAP_DIR=~/sources/gitea_irisib/bootstrap
2022-08-24 21:04:22 +02:00
CUSTOM_ZSHRC=$BOOTSTRAP_DIR/custom.zsh
CUSTOM_ENV=$BOOTSTRAP_DIR/env.sh
2022-02-26 16:39:46 +01:00
LOG=/dev/null
2022-08-24 21:04:22 +02:00
if [[ -z $(groups | grep sudo) ]]; then
2022-08-24 21:18:01 +02:00
echo "you need to be in the sudo group to run this script..."
2022-03-21 11:16:24 +01:00
exit 1
2022-08-24 21:04:22 +02:00
else
echo "all good! let's setup your system"
2022-03-21 11:16:24 +01:00
fi
2022-08-24 21:04:22 +02:00
function install_apt_dependencies () {
sudo apt-get update > /dev/null && echo "cache updated"
for pgm in $DEPENDENCIES_APT; do
sudo apt-get install -y $pgm > /dev/null && echo "$pgm installed"
done
echo "--- ${FUNCNAME[0]} done"
}
function setup_sources_dir () {
local dst=$SOURCES_DIR
if ! [[ -d $dst ]]; then
mkdir -p $dst && echo "created $dst directory"
else
echo "$dst exists already"
fi
echo "--- ${FUNCNAME[0]} done"
}
function setup_global_git_config () {
content=$(cat << EOF
\n
[user]\n
\tname = $NAME\n
\temail = $EMAIL\n
[filter "lfs"]\n
\tclean = git-lfs clean -- %f\n
\tsmudge = git-lfs smudge -- %f\n
\tprocess = git-lfs filter-process\n
\trequired = true\n
[pull]\n
\trebase = false\n
EOF
)
echo -e $content > ~/.gitconfig
echo "--- ${FUNCNAME[0]} done"
}
function clone_bootstrap_to_sources_dir () {
2022-08-24 23:08:03 +02:00
local dst=$BOOTSTRAP_DIR
2022-08-24 21:04:22 +02:00
if ! [[ -d $dst ]]; then
git clone ssh://gitea@86thumbs.net:3022/waldek/bootstrap.git $dst && echo "cloned bootstrap dir"
2022-08-24 21:05:50 +02:00
else
cd $dst
git pull && echo "updated $dst"
cd -
2022-08-24 21:04:22 +02:00
fi
echo "--- ${FUNCNAME[0]} done"
}
function install_oh_my_zsh () {
local dst=~/.oh-my-zsh
if ! [[ -d $dst ]]; then
2022-08-24 22:26:28 +02:00
git clone https://github.com/robbyrussell/oh-my-zsh.git $dst
2022-08-24 21:04:22 +02:00
cp $dst/templates/zshrc.zsh-template ~/.zshrc
else
cd $dst
2022-08-24 21:05:50 +02:00
git pull && echo "updated $dst"
cd -
2022-08-24 21:04:22 +02:00
fi
echo "--- ${FUNCNAME[0]} done"
}
function customize_oh_my_zsh () {
if [[ -z $(grep $CUSTOM_ZSHRC ~/.zshrc) ]]; then
echo "source $CUSTOM_ZSHRC" >> ~/.zshrc && echo "appended $CUSTOM_ZSHRC to zshrc"
fi
if [[ -z $(grep $CUSTOM_ENV ~/.zshrc) ]]; then
echo "source $CUSTOM_ENV" >> ~/.zshrc && echo "appended $CUSTOM_ENV to zshrc"
fi
echo "--- ${FUNCNAME[0]} done"
}
2022-08-24 21:18:01 +02:00
function clone_and_setup_vimrc () {
2022-08-24 23:08:03 +02:00
local dst=$SOURCES_DIR/vimrc
2022-08-24 21:18:01 +02:00
if ! [[ -d $dst ]]; then
git clone ssh://gitea@86thumbs.net:3022/waldek/vimrc.git $dst && echo "cloned bootstrap dir"
ln -s $dst/main.vimrc ~/.vimrc
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +VundleInstall +qall
else
cd $dst
git pull && echo "updated $dst"
cd -
vim +VundleUpdate +qall
fi
echo "--- ${FUNCNAME[0]} done"
}
function symlink_config_files () {
2022-08-24 22:26:28 +02:00
mkdir -p ~/.config/htop
2022-08-24 21:18:01 +02:00
local dst=~/.config/htop/htoprc
if ! [[ -L $dst ]]; then
rm $dst 2> /dev/null
ln -s $(ls $BOOTSTRAP_DIR/htoprc) $dst
fi
2022-08-24 22:26:28 +02:00
local dst=~/.xonshrc
if ! [[ -L $dst ]]; then
rm $dst 2> /dev/null
ln -s $(ls $BOOTSTRAP_DIR/xonshrc) $dst
fi
2022-08-27 16:35:19 +02:00
local dst=~/.config/kitty
if ! [[ -L $dst ]]; then
rm $dst 2> /dev/null
ln -s $(ls $BOOTSTRAP_DIR/kitty) $dst
fi
2022-08-24 22:26:28 +02:00
echo "--- ${FUNCNAME[0]} done"
}
function install_pip_dependencies () {
2022-09-29 15:29:14 +02:00
mkdir -p ~/virtual_envs
python3 -m venv ~/virtual_envs/base
source ~/virtual_envs/base/bin/activate
2022-08-24 22:26:28 +02:00
for dep in $DEPENDENCIES_PIP; do
pip3 install --upgrade "$dep" > $LOG && echo "installed $dep"
2022-08-24 22:26:28 +02:00
done
2022-08-24 23:24:27 +02:00
echo "--- ${FUNCNAME[0]} done"
}
2022-08-24 22:26:28 +02:00
2022-08-24 23:24:27 +02:00
function change_shell () {
local path=$(which xonsh)
echo $path
2022-09-29 15:29:14 +02:00
path=~/virtual_envs/base/bin/xonsh
2022-08-24 23:24:27 +02:00
if ! [[ -z $path ]]; then
if [[ -z "$(grep xonsh /etc/shells)" ]]; then
echo "$path" | sudo tee -a /etc/shells
fi
sudo chsh -s $path $USER && echo "set $1 as shell for $USER"
fi
echo "--- ${FUNCNAME[0]} done"
2022-08-24 22:26:28 +02:00
}
function main () {
2022-08-24 23:11:54 +02:00
install_apt_dependencies
2022-08-24 22:26:28 +02:00
install_pip_dependencies
setup_sources_dir
setup_global_git_config
clone_bootstrap_to_sources_dir
install_oh_my_zsh
customize_oh_my_zsh
2022-08-24 23:11:54 +02:00
clone_and_setup_vimrc
2022-08-24 22:26:28 +02:00
symlink_config_files
2022-08-24 23:24:27 +02:00
change_shell $DEFAULT_SHELL
2022-08-24 21:18:01 +02:00
}
2022-08-24 22:26:28 +02:00
main