install-script/install-debian.sh

84 lines
3.3 KiB
Bash
Raw Normal View History

2015-10-13 23:42:34 +02:00
#!/usr/bin/env bash
# Install Script for Debian and Ubuntu installations
# This script can be called multiple times
# Copyright (C) 2018 Andreas Fendt - All Rights Reserved
# Permission to copy and modify is granted under the MIT license
# Last revised 28.04.2018
2017-10-27 18:56:57 +02:00
# check if root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
2017-10-27 18:56:57 +02:00
# 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
2017-10-27 18:56:57 +02:00
exit 1
fi
2017-10-27 18:56:57 +02:00
# update system
apt-get update -y
apt-get dist-upgrade -y
apt-get autoclean -y
# get users directory and usernames
root_user=$(grep ':0:' /etc/passwd | awk -F':' '{print $1}')
2017-11-04 14:24:43 +01:00
root_user_path=$(grep ':0:' /etc/passwd | awk -F':' '{print $6}')
default_user_path=$(egrep '\:100[0-9]\:' /etc/passwd | tail -n 1 | awk -F':' '{print $6}')
default_user=$(egrep '\:100[0-9]\:' /etc/passwd | tail -n 1 | awk -F':' '{print $1}')
# install default packages
apt-get install -y sudo mc tree pv vim bash-completion wget git htop iotop iftop nmon apt-file aptitude hexedit tmux \
fonts-powerline
2017-10-27 18:56:57 +02:00
# zsh shell
apt-get install -y zsh && ( [ ! -d $root_user_path/.oh-my-zsh ] || [ ! -d $default_user_path/.oh-my-zsh ] ) && (
# change shell
chsh -s /bin/zsh $root_user
chsh -s /bin/zsh $default_user
# install oh-my-zsh
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
# configure oh-my-zsh
grep 'ZSH_THEME="agnoster"' $root_user_path/.zshrc || sed -i -- 's/ZSH_THEME=".*"/ZSH_THEME="agnoster"/g' $root_user_path/.zshrc
grep "command-not-found" $root_user_path/.zshrc || sed -i -- '/^plugins=(/a \\ command-not-found\n common-aliases\n sudo\n systemd\n tmux\n ubuntu' $root_user_path/.zshrc
# install oh-my-zsh to default user
cp $root_user_path/.zshrc $default_user_path/.zshrc
cp -a $root_user_path/.oh-my-zsh $default_user_path/.oh-my-zsh
chown ${default_user}:${default_user} ${default_user_path}/.oh-my-zsh ${default_user_path}/.zshrc
# configure tmux
grep "ZSH_TMUX_AUTOSTART" $default_user_path/.zshrc || sed -i -- '1s/^/ZSH_TMUX_AUTOSTART="true"\nZSH_TMUX_AUTOQUIT="false"\n\n/' $default_user_path/.zshrc
2017-10-27 18:56:57 +02:00
)
2017-10-27 18:56:57 +02:00
# configure vim
2017-11-04 14:24:43 +01:00
touch ${root_user_path}/.vimrc ${default_user_path}/.vimrc
2017-10-27 18:56:57 +02:00
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
2017-11-04 14:24:43 +01:00
grep "$config" ${root_user_path}/.vimrc || echo "$config" >> ${root_user_path}/.vimrc
grep "$config" ${default_user_path}/.vimrc || echo "$config" >> ${default_user_path}/.vimrc
2014-09-07 21:46:07 +02:00
done
chown ${default_user}:${default_user} ${default_user_path}/.vimrc
2017-11-04 14:24:43 +01:00
2017-10-27 18:56:57 +02:00
# 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
2017-10-27 18:56:57 +02:00
# 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
sensors-detect --auto