Home Post Installation Script - Debian & Ubuntu
Post
Cancel

Post Installation Script - Debian & Ubuntu

Post Installation Script - Debian & Ubuntu

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash

# ===================
# Author: @impulsado
# Web: impulsado.org
# Date:   18/10/2022
# ===================

# === FUNCTIONS ===
function startCheck() {
    if [[ "$EUID" -ne 0 ]]; then
        echo ""
        echo "Must be root!"
        echo ""
        exit 1
    fi

    ping -c 1 -q google.com >&/dev/null
    if [[ $? != 0 ]]; then
        echo ""
        echo "Must have internet connection!"
        echo ""
        exit 1
    fi

    echo ""
    echo "=============================="
    echo "   Welcome to your new O.S! "
    echo "=============================="
    echo ""
    echo ""
    read -p "Enter your username: " username

    if [[ $username == "root" ]]; then
        echo ""
        echo "Please, enter another username!"
        echo ""
    fi

    read -p "Which SHELL do you prefere BASH [B] or ZSH [Z]? " -e -i "Y" usr_op_shell
    read -p "Do you want to install/configure SSH? [Y/n] " -e -i "Y" usr_op_ssh
    read -p "Do you want to install/configure TMUX? [Y/n] " -e -i "Y" usr_op_tmux
    read -p "Do you want to install/configure NEOVIM? [Y/n] " -e -i "Y" usr_op_neovim
    read -p "Select other apps you want install: " -e -i "wget bat nmap tcpdump curl xclip" usr_apps
    echo ""
    read -p "Do you want to proceed? [Y/n] " -e -i "Y" usr_op

    if [[ $usr_op != "Y" ]]; then
        echo ""
        echo "See you soon!"
        echo ""
        exit 2
    fi
}

function initial() {
    apt update -y && apt upgrade -y
    apt install -y $usr_apps
    echo "$username ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
    rm -d /home/$username/{Documents,Music,Pictures,Public,Templates,Videos}
    mkdir /home/$username/{Scripts,Programs}
    chown $username:$username /home/$username/Scripts
    chown $username:$username /home/$username/Programs
    timedatectl set-timezone Europe/Madrid
    clear
}

function zshrc() {
    # Download & Install Oh-My-ZSH
    sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

    # Download & Install Starship
    curl -sS https://starship.rs/install.sh | sh 
    
    # Download plugins
    git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-/home/$username/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

    # Change .zshrc
    sed -i 's/(git)/(git sudo zsh-autosuggestions zsh-syntax-highlighting)/g' /home/$username/.zshrc
    cat <<EOF >> /home/$username/.zshrc
# === ALIAS ===
alias ls='ls --color=auto'
alias ll='ls -la --color=auto'
alias cat='batcat'
alias update='sudo apt update -y && sudo apt upgrade -y'
alias poweroff='sudo systemctl poweroff'
alias reboot='sudo systemctl reboot'
alias apt='sudo apt'
alias mkt='mkdir'
alias tmux='tmux -u'
alias vim='nvim'
alias myip='curl ifconfig.co/'
alias copy='xcopy -sel c <'

# === OTHERS ===
export PATH=$PATH:/home/$username/Scripts/
eval "$(starship init zsh)"
EOF
}

function sshInstall() {
    if [[ $usr_op_ssh != "Y" ]]; then
        return 2
    fi
    apt install -y openssh-server
    systemctl enable ssh
    systemctl stop ssh
    cat <<EOF > /etc/ssh/sshd_config
# === NEW SSH CONFIGURATION ===
# Protocolo 1 is older and less secure
Protocol 2

# Limit passwords attempts
MaxAuthTries 3

# Disable root login
PermitRootLogin no

# Disable empty passwords to login
PermitEmptyPasswords no

# Disable X11 Forwarding
X11Forwarding no

# Period of time before client gets disconnected (Seconds)
ClientAliveInterval 15

# Server waiting time after a connection request is made (Seconds)
LoginGraceTime 20
EOF
    systemctl start ssh
    clear
}

function tmuxInstall() {
    if [[ $usr_op_tmux != "Y" ]]; then
        return 2
    fi
    apt install -y tmux git
    git clone https://github.com/tmux-plugins/tpm /home/$username/.tmux/plugins/tpm
    touch /home/$username/.tmux.conf
    cat <<EOF > /home/$username/.tmux.conf
# === MAIN ===
# Reload config file
unbind r
bind r source-file /home/$username/.tmux.conf

# Double prefix to change pane
unbind C-b
bind C-b select-pane -t :.+

# Split pane
bind h split-window -v
bind v split-window -h

# Mouse friendly
set -g mouse on

# Start index at number 1
set -g base-index 1

# Modern colors
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",alacritty:Tc"

# Set scroll history to 100,000 lines
set-option -g history-limit 100000

# Window automatically rename 
set-option -g automatic-rename on

# Quiet
set -g visual-activity off
set -g visual-bell off
set -g visual-silence off
set -g monitor-activity off
set -g bell-action none

# === DESIGN ===
# Remove extra information
set-option -g status-right ''

# Centre window names
set-option -g status-justify centre

# Default window title colors
set-window-option -g window-status-style "fg=white,bg=default"

# Active window title colors
set-window-option -g window-status-current-style "fg=red,bg=default"

# Status bar colors
set-option -g status-style "fg=green,bg=#292929"

# Pane border
set-option -g pane-border-style "fg=#292929"
set-option -g pane-active-border-style "fg=white"
EOF
    chown $username:$username /home/$username/.tmux.conf
    tmux source-file /home/$username/.tmux.conf
    clear
}

function bashrc() {
cat <<EOF >> /home/$username/.bashrc
# === ALIAS ===
alias ls='ls --color=auto'
alias ll='ls -la --color=auto'
alias cat='batcat'
alias update='sudo apt update -y && sudo apt upgrade -y'
alias poweroff='sudo systemctl poweroff'
alias reboot='sudo systemctl reboot'
alias apt='sudo apt'
alias mkt='mkdir'
alias tmux='tmux -u'
alias vim='nvim'
alias myip='curl ifconfig.co/'
alias copy='xcopy -sel c <'

# === OTHERS ===
export PATH=$PATH:/home/$username/Scripts/
PS1='\[\e[0;38;5;46m\]\u\[\e[0;38;5;46m\]@\[\e[0;38;5;46m\]\H \[\e[0m\][\[\e[0m\]\w\[\e[0m\]] \[\e[0;93m\]\$ \[\e[0m\]'
EOF
}

function secureOS() {
    # Enable broadcast echo Protection
    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

    # Disable Source Routed Packets
    for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
        echo 0 > $i
    done

    # Enable TCP SYN Cookie Protection
    echo 1 > /proc/sys/net/ipv4/tcp_syncookies

    # Disable ICMP Redirect Acceptance
    for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do
        echo 0 > $i
    done

    # Don't send Redirect Messages
    for i in /proc/sys/net/ipv4/conf/*/send_redirects; do
        echo 0 > $i
    done

    # Drop Spoofed Packets coming in on an interface, which, if replied to,
    # would result in the reply going out a different interface.
    for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
        echo 1 > $i
    done
}

function nvimInstall() {
    if [[ $usr_op_neovim != "Y" ]]; then
        return 2
    fi
    apt install -y neovim > /dev/null
    if [ ! -d /home/$username/.config/nvim ]; then
    mkdir -p /home/$username/.config/nvim
    cat <<EOF >> /home/$username/.config/nvim/init.vim
syntax on                   " syntax highlighting
syntax on                   " syntax highlighting
set hidden                  " Required to keep multiple buffers open
set nocompatible            " disable compatibility to old-time vi
set encoding=utf-8          " The encoding displayed
set showmatch               " show matching
set ignorecase              " case insensitive
set mouse=v                 " middle-click paste with
set hlsearch                " highlight search
set smartcase               " Enable smart-case search
set incsearch               " incremental search
set tabstop=4               " number of columns occupied by a tab
set softtabstop=4           " see multiple spaces as tabstops so <BS> does the right thing
set expandtab               " converts tabs to white space
set shiftwidth=4            " width for autoindents
set autoindent              " indent a new line the same amount as the line just typed
set number                  " add line numbers
set wildmode=longest,list   " get bash-like tab completions
filetype plugin indent on   " allow auto-indenting depending on file type
set mouse=a                 " enable mouse click
set clipboard=unnamedplus   " using system clipboard
filetype plugin on
set cursorline              " highlight current cursorline
set ttyfast                 " Speed up scrolling in Vim
set t_Co=256                " Support 256 colors
set conceallevel=0          " Can see `` in Markdown files
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
EOF
fi
}

function printEnd() {
    clear
    echo ""
    echo ""
    echo " BASH:  source ~/.bashrc"
    echo ""
    echo " ZSH:   source ~/.zshrc"
    echo ""
    echo ""
    echo "> Author: impulsado"
}

# === MAIN ===
startCheck

if [[ $usr_op == "Y" ]]; then
    initial
    if [[ $usr_op_shell == "B" ]]; then
        bashrc
    else
        zshrc
    fi
    sshInstall
    tmuxInstall
    nvimInstall
    secureOS
    sleep 1
    printEnd
fi
This post is licensed under CC BY 4.0 by the author.