-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-install.sh
executable file
·79 lines (67 loc) · 2.24 KB
/
server-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
# Debian Server installation
#
# Run installation:
#
# - Run: `# bash <(curl -sL https://github.com/rarescosma/env.dotfiles/server-install.sh)`
set -uo pipefail
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
exec 1> >(tee -a "/tmp/server-install.out")
exec 2> >(tee -a "/tmp/server-install.err" >&2)
BACKTITLE="Debian Server installation"
get_input() {
title="$1"
description="$2"
input=$(dialog --clear --stdout --backtitle "$BACKTITLE" --title "$title" --inputbox "$description" 0 0)
echo "$input"
}
main() {
echo -e "\n### Setting up clock"
timedatectl set-ntp true
timedatectl set-timezone CET
echo -e "\n### Installing essential packages"
apt update
apt install --yes \
sudo zsh stow curl wget git rsync neovim mc ncdu htop screen tig \
dnsutils net-tools make fzf ripgrep fd-find
# god mode
grep -q $user /etc/sudoers || {
echo "$user ALL=(ALL) NOPASSWD:ALL" | EDITOR='tee -a' visudo
}
setup_dotfiles
}
setup_dotfiles() {
# very important
vim_colors="/usr/share/nvim/runtime/colors/gruvbox.vim"
test -f $vim_colors || wget https://raw.githubusercontent.com/morhetz/gruvbox/master/colors/gruvbox.vim -O $vim_colors
# set up dotfiles
dotfiles_dir="/home/$user/src/env/dotfiles"
dotfiles_setup=(
"mkdir -p $dotfiles_dir;"
"test -f $dotfiles_dir/setup-user.sh || git clone --recursive https://github.com/rarescosma/env.dotfiles.git $dotfiles_dir || true;"
"pushd $dotfiles_dir;"
"./setup-user.sh stow::bin 'stow devel' 'stow shell' 'stow misc';"
"echo -e \"enable_devel=(kubectl python)\nenable_ssh_agent=0\n\" > /home/$user/.local/env;"
"mkdir -p /home/$user/.ssh;"
"test -f /home/$user/.ssh/authorized_keys || wget https://static.getbetter.ro/$user.pub -O /home/$user/.ssh/authorized_keys;"
"mkdir -p /home/$user/.local/share/vim/files/backup"
)
sudo -u $user bash -c "${dotfiles_setup[*]}"
chsh -s /bin/zsh $user
ln -sf /bin/fdfind /home/$user/bin/fd
}
# ask for username
if test -z "$DEBBIE_USER"; then
apt update
apt install --yes dialog
user=$(get_input "User" "Enter username") || exit 1
clear
: ${user:?"user cannot be empty"}
else
user="$DEBBIE_USER"
fi
if [[ "$@" == "" ]]; then
main
else
"$@"
fi