diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/install-debian.sh b/install-debian.sh index 8c9c549..4ecf7b9 100755 --- a/install-debian.sh +++ b/install-debian.sh @@ -6,6 +6,43 @@ # Permission to copy and modify is granted under the MIT license # Last revised 28.04.2018 +script=/tmp/install-script +cat > $script << 'EOL' +# 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() { + [ ! -d ~/.fzf ]&& cd ~ && git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install +} + +# install oh-my-zsh +install-ohmyzsh() { + [ ! -d ~/.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"' ~/.zshrc || sed -i -- 's/ZSH_THEME=".*"/ZSH_THEME="agnoster"/g' ~/.zshrc + grep "command-not-found" ~/.zshrc || sed -i -- '/^plugins=(/a \\ command-not-found\n common-aliases\n sudo\n systemd\n tmux\n 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 + ) +} + +$@ +EOL +chmod +x $script + # check if root if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 @@ -23,61 +60,30 @@ 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}') -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 +apt-get install -y fonts-powerline python-pip zsh sudo mc tree pv vim bash-completion wget git htop iotop iftop nmon apt-file aptitude hexedit tmux pip install git+https://github.com/jeffkaufman/icdiff.git -# install zsh shell -apt-get install -y zsh && ( - chsh -s /bin/zsh ${root_user} - chsh -s /bin/zsh $[default_user] -) +# 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) -# install oh-my-zsh -( [ ! -d ${root_user_path}/.oh-my-zsh ] || [ ! -d ${default_user_path}/.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 -f ${root_user_path}/.zshrc ${default_user_path}/.zshrc - cp -a ${root_user_path}/.oh-my-zsh ${default_user_path}/.oh-my-zsh - chown -R ${default_user}:${default_user} ${default_user_path}/.oh-my-zsh ${default_user_path}/.zshrc - sed -i -- '/Path to your oh-my-zsh installation/!b;n;c\ export ZSH='"${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 -) +# for each user install packages +for user in $users; do + # install zsh shell + chsh -s /bin/zsh $user -# install fzf -install_fzf='cd ~ && git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install' -[ ! -d ${root_user_path}/.fzf ] && su -c ${install_fzf} -s /bin/bash ${root_user} -[ ! -d ${default_user_path}/.fzf ] && su -c ${install_fzf} -s /bin/bash ${default_user} - -# configure vim -touch ${root_user_path}/.vimrc ${default_user_path}/.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}" ${root_user_path}/.vimrc || echo "${config}" >> ${root_user_path}/.vimrc - grep "${config}" ${default_user_path}/.vimrc || echo "${config}" >> ${default_user_path}/.vimrc + # run install and configuration scripts + for target in install-ohmyzsh install-fzf configure-vim; do + su -c "$script $target" -s /bin/bash $user + done done -chown ${default_user}:${default_user} ${default_user_path}/.vimrc # 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 + grep "$config" /etc/tmux.conf || echo "$config" >> /etc/tmux.conf done # configure system @@ -89,3 +95,6 @@ dpkg-reconfigure console-data console-setup locales \ # run programs apt-file update sensors-detect --auto + +# delete temporary script file +rm -f $script