#!/usr/bin/env bash # Install Script for Debian and Ubuntu installations # This script can be called multiple times # Copyright (C) 2019 Andreas Fendt - All Rights Reserved # Permission to copy and modify is granted under the MIT license # Last revised 19.02.2019 # create the temporary script script=/tmp/install-script cat > $script << 'EOL' # change behavior of bash set -e # configure vim configure-vim() { touch ~/.vimrc for config in "filetype plugin indent on" "set tabstop=4" "set shiftwidth=4" \ "set expandtab" "syntax enable" "set softtabstop=4" \ "set number" "set showcmd" "set cursorline"; do grep "$config" ~/.vimrc || echo "$config" >> ~/.vimrc done } # install fzf install-fzf() { if [ ! -d ~/.fzf ]; then cd ~ && git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install else echo "fzf is already installed for $(id)" fi } # install oh-my-zsh install-ohmyzsh() { if [ ! -d ~/.oh-my-zsh ]; then # install oh-my-zsh git clone https://github.com/HyP3r-/oh-my-zsh.git ~/.oh-my-zsh touch ~/.zshrc && cp ~/.zshrc ~/.zshrc.orig cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc # configure oh-my-zsh grep 'ZSH_THEME="agnoster"' ~/.zshrc || sed -i -- 's/ZSH_THEME=".*"/ZSH_THEME="agnoster"/g' ~/.zshrc grep "command-not-found" ~/.zshrc || sed -i -- '/^plugins=(/s/git/command-not-found common-aliases git sudo systemd tmux ubuntu/' ~/.zshrc # configure tmux on normal user if [[ $EUID -ne 0 ]]; then grep "ZSH_TMUX_AUTOSTART" ~/.zshrc || sed -i -- '1s/^/ZSH_TMUX_AUTOSTART="true"\nZSH_TMUX_AUTOQUIT="false"\n\n/' ~/.zshrc fi else echo "oh-my-zsh is already installed for $(id)" fi } # call target function depending of the arguments $@ exit 0 EOL chmod +x $script # change behavior of bash set -e # check if root if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 exit 1 fi # check if debian if [ ! "$(grep -Ei 'debian|buntu' /etc/*release)" ]; then echo "This script must be run on a debian or ubuntu system" 1>&2 exit 1 fi # update system apt-get update -y apt-get dist-upgrade -y apt-get autoclean -y # install default packages apt-get install -y apt-file aptitude bash-completion dialog fonts-powerline git hexedit htop iftop iotop mc nmon pv python-pip sudo tmux tree vim wget zsh pip install git+https://github.com/jeffkaufman/icdiff.git # get users menu=(); while IFS=: read -r name pw uid gid gecos home shell; do if (( uid >= 1000 && uid < 10000 )); then menu+=( "$name" "$uid" on ); fi; done < /etc/passwd users=$(dialog --checklist "Install this on User" 0 0 4 root "0" on "${menu[@]}" 3>&1 1>&2 2>&3) # for each user install packages for user in $users; do # install zsh shell chsh -s /bin/zsh $user # run install and configuration scripts for target in install-ohmyzsh install-fzf configure-vim; do su -l -c "$script $target" -s /bin/bash $user done done # configure tmux for config in "bind '\"' split-window -c \"#{pane_current_path}\"" \ "bind % split-window -h -c \"#{pane_current_path}\"" \ "bind c new-window -c \"#{pane_current_path}\""; do grep "$config" /etc/tmux.conf || echo "$config" >> /etc/tmux.conf done # configure system apt-get install -y console-data console-setup locales \ keyboard-configuration tzdata dpkg-reconfigure console-data console-setup locales \ keyboard-configuration tzdata # run programs apt-file update # delete temporary script file rm -f $script