install-script/install-debian.sh

118 lines
3.6 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) 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
2018-06-17 14:39:15 +02:00
script=/tmp/install-script
cat > $script << 'EOL'
2019-02-20 00:02:55 +01:00
# change behavior of bash
set -e
2018-06-17 14:39:15 +02:00
# 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() {
2019-02-20 00:02:55 +01:00
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
2018-06-17 14:39:15 +02:00
}
# install oh-my-zsh
install-ohmyzsh() {
2019-02-20 00:02:55 +01:00
if [ ! -d ~/.oh-my-zsh ]; then
# install oh-my-zsh
2019-10-05 12:05:41 +02:00
git clone https://github.com/HyP3r-/oh-my-zsh.git ~/.oh-my-zsh
2019-03-06 02:08:19 +01:00
touch ~/.zshrc && cp ~/.zshrc ~/.zshrc.orig
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
2018-06-17 14:39:15 +02:00
# 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
2018-06-17 14:39:15 +02:00
# 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
2019-02-20 00:02:55 +01:00
else
echo "oh-my-zsh is already installed for $(id)"
fi
2018-06-17 14:39:15 +02:00
}
2019-02-19 23:44:13 +01:00
# call target function depending of the arguments
2018-06-17 14:39:15 +02:00
$@
2019-02-19 23:44:13 +01:00
exit 0
2018-06-17 14:39:15 +02:00
EOL
chmod +x $script
2019-02-20 00:02:55 +01:00
# change behavior of bash
set -e
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
# install default packages
2019-10-05 12:14:21 +02:00
apt-get install -y apt-file aptitude bash-completion dialog fonts-powerline git hexedit htop iftop iotop mc nmon pv python3-pip sudo tmux tree vim wget zsh
pip3 install git+https://github.com/jeffkaufman/icdiff.git@release-1.9.5
2018-06-17 14:39:15 +02:00
# 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)
2018-06-17 14:39:15 +02:00
# for each user install packages
for user in $users; do
# install zsh shell
chsh -s /bin/zsh $user
2018-06-17 14:39:15 +02:00
# run install and configuration scripts
for target in install-ohmyzsh install-fzf configure-vim; do
2018-12-28 19:52:10 +01:00
su -l -c "$script $target" -s /bin/bash $user
2018-06-17 14:39:15 +02:00
done
2014-09-07 21:46:07 +02:00
done
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
2018-06-17 14:39:15 +02:00
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
2018-06-17 14:39:15 +02:00
# delete temporary script file
rm -f $script