-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdebian-based.sh
More file actions
172 lines (147 loc) · 4.86 KB
/
debian-based.sh
File metadata and controls
172 lines (147 loc) · 4.86 KB
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
#!/bin/bash
set -e
#############################################################
# Configuration Variables
#############################################################
TIMEZONE="Europe/Istanbul"
LOCALE="en_US.UTF-8"
SYSCTL_CUSTOM_FILE="/etc/sysctl.d/99-champion.conf"
JAIL_FILE="/etc/fail2ban/jail.local"
ULIMIT_CONFIG="/etc/security/limits.d/99-champion.conf"
DNS1="1.1.1.3"
DNS2="1.0.0.3"
#############################################################
# Color Codes
#############################################################
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
#############################################################
# Root Check
#############################################################
if [ "$(id -u)" -ne 0 ]; then
echo -e "${RED}Run as root.${NC}"
exit 1
fi
clear
echo -e "${GREEN}==================================================${NC}"
echo -e "${GREEN} CHAMPION EDITION – DEBIAN 13 (TRIXIE) ${NC}"
echo -e "${GREEN}==================================================${NC}"
sleep 2
#############################################################
# Update System
#############################################################
echo -e "${BLUE}System update...${NC}"
apt update
apt full-upgrade -y
apt autoremove --purge -y
#############################################################
# Base Packages
#############################################################
echo -e "${BLUE}Installing base packages...${NC}"
DEBIAN_FRONTEND=noninteractive apt install -y \
vim nano curl wget jq ca-certificates \
locales tzdata net-tools iproute2 ethtool \
htop iotop iftop conntrack \
ufw fail2ban \
build-essential \
docker.io
systemctl enable --now docker
#############################################################
# Locale & Timezone
#############################################################
echo -e "${BLUE}Configuring locale & timezone...${NC}"
sed -i "s/^# $LOCALE/$LOCALE/" /etc/locale.gen
locale-gen
update-locale LANG=$LOCALE
timedatectl set-timezone $TIMEZONE
timedatectl set-ntp true
#############################################################
# DNS (Debian Safe)
#############################################################
echo -e "${BLUE}Configuring DNS...${NC}"
cat > /etc/resolv.conf <<EOF
nameserver $DNS1
nameserver $DNS2
EOF
#############################################################
# Disable Swap
#############################################################
echo -e "${BLUE}Disabling swap...${NC}"
swapoff -a
sed -i '/swap/d' /etc/fstab
#############################################################
# Limits (SAFE VALUES)
#############################################################
echo -e "${BLUE}Configuring limits...${NC}"
cat > $ULIMIT_CONFIG <<EOF
* soft nofile 1048576
* hard nofile 1048576
EOF
mkdir -p /etc/systemd/system.conf.d
cat > /etc/systemd/system.conf.d/limits.conf <<EOF
[Manager]
DefaultLimitNOFILE=1048576
DefaultLimitNPROC=infinity
EOF
systemctl daemon-reexec
#############################################################
# Sysctl (BBR + Low Latency)
#############################################################
echo -e "${BLUE}Applying sysctl tuning...${NC}"
cat > $SYSCTL_CUSTOM_FILE <<EOF
net.ipv4.ip_forward=1
vm.swappiness=0
fs.file-max=2097152
net.core.somaxconn=65535
net.core.netdev_max_backlog=250000
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
net.ipv4.tcp_fastopen=3
net.ipv4.tcp_mtu_probing=1
net.netfilter.nf_conntrack_max=1048576
EOF
sysctl --system
#############################################################
# GRUB – Debian Friendly
#############################################################
echo -e "${BLUE}Configuring GRUB...${NC}"
cp /etc/default/grub /etc/default/grub.bak
sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="quiet mitigations=off"/' \
/etc/default/grub
update-grub
#############################################################
# Network Tuning
#############################################################
echo -e "${BLUE}Network tuning...${NC}"
IFACE=$(ip route | awk '/default/ {print $5}' | head -n1)
if [ -n "$IFACE" ]; then
ip link set "$IFACE" txqueuelen 10000
fi
#############################################################
# Fail2Ban
#############################################################
echo -e "${BLUE}Configuring Fail2Ban...${NC}"
cat > $JAIL_FILE <<EOF
[sshd]
enabled = true
maxretry = 3
bantime = 1d
findtime = 10m
EOF
systemctl enable --now fail2ban
#############################################################
# Cleanup
#############################################################
echo -e "${BLUE}Cleaning system...${NC}"
apt clean
history -c || true
#############################################################
# Finish
#############################################################
echo -e "${GREEN}DONE. Reboot required.${NC}"
echo -e "${YELLOW}Rebooting in 10 seconds...${NC}"
sleep 10
reboot