-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebianDocker.sh
196 lines (147 loc) · 11.1 KB
/
DebianDocker.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
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
#!/bin/bash
# Script for Debian VM installed in ProxMox
# Script does the following:
# 1. Installs packages: qemu-guset-agent, parted, ssh, sudo, openssl.
# 2. Resizes the root partition to the full size of the disk (parted /dev/sda resizepart 1 -1)
# 3. Setup the sshd daemon (Create in /etc/ssh/sshd_config.d/proxmox.conf and set port, setup security)
# 4. Setup the sudoers file (Create group, add to file group)
# 5. Creates a user with sudo group
# 6. Add to new user ssh authorized keys
# 7. Install docker and lazydocker with script by uuuuuno(github.com/uuuuuno)
#
# Docker script author: uuuuuno (github.com/uuuuuno)
# Script locate (github.com/uuuuuno-devops/homelab)
#
# Author: alozo (github.com/alozoBack)
# Port for ssh
port=7346
# Update
echo "";
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " /\_/\ /\_/\ ";
echo "( o.o ) ____ ___ .___ __ __ ( o.o )";
echo " > ^ < | | \_____ __| _/____ _/ |_ ____ _________.__. ______/ |_ ____ _____ > ^ < ";
echo " /\_/\ | | |____ \ / __ |\__ \\ __\/ __ \ / ___< | |/ ___| __\/ __ \ / \ /\_/\ ";
echo "( o.o ) | | /| |_> > /_/ | / __ \| | \ ___/ \___ \ \___ |\___ \ | | \ ___/| Y Y \ ( o.o )";
echo " > ^ < |______/ | __/\____ |(____ /__| \___ > /____ >/ ____/____ >|__| \___ >__|_| / > ^ < ";
echo " /\_/\ |__| \/ \/ \/ \/ \/ \/ \/ \/ /\_/\ ";
echo "( o.o ) ( o.o )";
echo " > ^ < > ^ < ";
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo "";
apt-get update && apt-get upgrade -y
# Install packages
echo " "
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " /\_/\ /\_/\ ";
echo "( o.o ) .___ __ .__ .__ __ ( o.o )";
echo " > ^ < | | ____ ______/ |______ | | | | ___________ ____ | | ______ ____ ____ ______ > ^ < ";
echo " /\_/\ | |/ \ / ___| __\__ \ | | | | \____ \__ \ _/ ___\| |/ |__ \ / ___\_/ __ \ / ___/ /\_/\ ";
echo "( o.o ) | | | \\___ \ | | / __ \| |_| |__ | |_> > __ \\ \___| < / __ \/ /_/ > ___/ \___ \ ( o.o )";
echo " > ^ < |___|___| /____ >|__| (____ /____/____/ | __(____ /\___ >__|_ (____ |___ / \___ >____ > > ^ < ";
echo " /\_/\ \/ \/ \/ |__| \/ \/ \/ \/_____/ \/ \/ /\_/\ ";
echo "( o.o ) ᑫᵉᵐᵘ⁻ᵍᵘˢᵉᵗ⁻ᵃᵍᵉⁿᵗ ᵖᵃʳᵗᵉᵈ ˢˢʰ ˢᵘᵈᵒ ᵒᵖᵉⁿˢˢˡ ( o.o )";
echo " > ^ < > ^ < ";
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " "
echo "Packages to install: qumu-guest-agent, parted, ssh, sudo, openssl, docker"
echo "Enter to continue"
read
echo " "
apt-get install -y qemu-guest-agent parted ssh sudo openssl curl
# Resize root partition
echo " "
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " /\_/\ /\_/\ ";
echo "( o.o ) __________ .__ __ .__ ( o.o )";
echo " > ^ < \______ \ ____ _____|__|_______ ____ ___________ ________/ |_|__| ____ ____ > ^ < ";
echo " /\_/\ | _// __ \ / ___/ \___ // __ \ \____ \__ \\_ __ \ __\ |/ _ \ / \ /\_/\ ";
echo "( o.o ) | | \ ___/ \___ \| |/ /\ ___/ | |_> > __ \| | \/| | | ( <_> ) | \ ( o.o )";
echo " > ^ < |____|_ /\___ >____ >__/_____ \\___ > | __(____ /__| |__| |__|\____/|___| / > ^ < ";
echo " /\_/\ \/ \/ \/ \/ \/ |__| \/ \/ /\_/\ ";
echo "( o.o ) /ᵈᵉᵛ/ˢᵈᵃ¹ ( o.o )";
echo " > ^ < > ^ < ";
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " "
echo -e "Fix\n1\nYes" | parted /dev/sda resizepart 1 100% ---pretend-input-tty
resize2fs /dev/sda1
# Setup sshd daemon
echo " "
#install docker
sh -c "$(curl -fsSL https://raw.githubusercontent.com/uuuuuno-devops/home-lab/refs/heads/main/install-docker.sh)"
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " /\_/\ /\_/\ ";
echo "( o.o ) _________ __ .__ .___ ( o.o )";
echo " > ^ < / _____/ _____/ |_ __ ________ ______ _____| |__ __| _/ > ^ < ";
echo " /\_/\ \_____ \_/ __ \ __\ | \____ \ / ___// ___/ | \ / __ | /\_/\ ";
echo "( o.o ) / \ ___/| | | | / |_> > \___ \ \___ \| Y \/ /_/ | ( o.o )";
echo " > ^ < /_______ /\___ >__| |____/| __/ /____ >____ >___| /\____ | > ^ < ";
echo " /\_/\ \/ \/ |__| \/ \/ \/ \/ /\_/\ ";
echo "( o.o ) ( o.o )";
echo " > ^ < > ^ < ";
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " "
echo "
Port $port
PermitRootLogin yes
PasswordAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
MaxAuthTries 3
MaxSessions 2
" > /etc/ssh/sshd_config.d/proxmox.conf
systemctl restart sshd
# Setup sudoers file
echo " "
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " /\_/\ /\_/\ ";
echo "( o.o ) _________ __ .___ .___ ( o.o )";
echo " > ^ < / _____/ _____/ |_ __ ________ __ __ ______ ___________ _____ ____ __| _/ ________ __ __| _/____ > ^ < ";
echo " /\_/\ \_____ \_/ __ \ __\ | \____ \ | | \/ ___// __ \_ __ \ \__ \ / \ / __ | / ___/ | \/ __ |/ _ \ /\_/\ ";
echo "( o.o ) / \ ___/| | | | / |_> > | | /\___ \\ ___/| | \/ / __ \| | \/ /_/ | \___ \| | / /_/ ( <_> ) ( o.o )";
echo " > ^ < /_______ /\___ >__| |____/| __/ |____//____ >\___ >__| (____ /___| /\____ | /____ >____/\____ |\____/ > ^ < ";
echo " /\_/\ \/ \/ |__| \/ \/ \/ \/ \/ \/ \/ /\_/\ ";
echo "( o.o ) ( o.o )";
echo " > ^ < > ^ < ";
echo " /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ /\_/\ ";
echo "( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )( o.o )";
echo " > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < > ^ < ";
echo " "
groupadd sdwhl
echo "%sdwhl ALL=(ALL:ALL) ALL" > /etc/sudoers.d/sdwhl
chmod 440 /etc/sudoers.d/sdwhl
# Create user
echo ""
read -p "Enter username: " username
useradd -m -s /bin/bash -G sdwhl,docker $username
#Set password
password=$(openssl rand -hex 6)
echo "$username:$password" | chpasswd
echo "Password for $username is: $password"
# Add to user ssh authorized keys
mkdir -p /home/$username/.ssh
chmod 700 /home/$username/.ssh
read -p "Enter SSH public key: " sshkey
echo "$sshkey" > /home/$username/.ssh/authorized_keys
chown -R $username:$username /home/$username/.ssh
chmod 600 /home/$username/.ssh/authorized_keys
# Print new password
echo "Setup complete. The password for $username is: $password"