-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
249 lines (226 loc) · 9.23 KB
/
setup.sh
File metadata and controls
249 lines (226 loc) · 9.23 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
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
#!/usr/bin/env bash
if [[ -f /etc/os-release ]]; then
source /etc/os-release
fi
# Variable
USERNAME="lendra"
PASSWORD="lendev"
# Function
function CreateLoginUser {
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
# echo "[LOG]: Creating ssh user..."
# groupadd wheel
# useradd -mG wheel $USERNAME -s $(which bash 2>/dev/null) && echo -e "$PASSWORD\n$PASSWORD" | passwd $USERNAME
# echo "[LOG]: Adding wheel groups to sudoers"
# echo -e "%wheel ALL=(ALL:ALL) ALL" >>/etc/sudoers
}
# Install Docker with distro ID
function InstallDocker() {
# Setup Docker
read -p "Do you want to setup docker? (y/n): " ANSWER
if [[ $ANSWER == "y" || $ANSWER == "Y" || $ANSWER == "yes" ]]; then
if [[ $ID == "fedora" || $ID == "centos" ]]; then
PM="dnf"
if [[ $ID == "centos" ]]; then
PM="yum"
fi
echo "[LOG]: Adding docker to $PM repo..."
$PM config-manager --add-repo https://download.docker.com/linux/$ID/docker-ce.repo
echo "[LOG]: Installing docker with dnf..."
$PM install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
echo "[LOG]: Enabling and starting docker service..."
systemctl enable --now docker.socket
elif [[ $ID == "ubuntu" || $ID == "debian" ]]; then
echo "[LOG]: setup docker..."
echo "[LOG]: Enabling https support for apt..."
apt install ca-certificates curl gnupg lsb-release -y
echo "[LOG]: Adding docker keyring..."
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/$ID/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "[LOG]: Adding docker to apt repo..."
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$ID $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
echo "[LOG]: Updating apt repo..."
apt update
echo "[LOG]: Installing docker with apt..."
apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
echo "[LOG]: Enabling and starting docker service..."
systemctl enable --now docker.sockets
else
echo "[LOG]: Unsupported Distro Linux"
fi
else
echo "[ERR]: invalid or reject answer"
fi
}
# Install methods
function FedoraInstall() {
cd /etc/yum.repos.d/
sed -i 's|baseurl=https://muug.ca|#baseurl=https://muug.ca|g' /etc/yum.repos.d/fedora*
sed -i 's|#metalink=https://mirrors.fedoraproject.org|metalink=https://mirrors.fedoraproject.org|g' /etc/yum.repos.d/fedora*
cd ~
echo "[LOG]: Creating backup for dnf config"
mv /etc/dnf/dnf.conf /etc/dnf/dnf.conf.bck
echo "[LOG]: Generating new dnf config file..."
wget http://gogs.com/lendra/lxc-setup/raw/main/dnf.conf || curl -o dnf.conf http://gogs.com/lendra/lxc-setup/raw/main/dnf.conf
mv dnf.conf /etc/dnf/
echo "[LOG]: Updating and installing missing tools..."
dnf -v update -y && dnf -v install ncurses bash-completion sudo dnf-plugins-core openssh-server -y
CreateLoginUser
echo "[LOG]: Enabling ssh remote && firewall..."
sudo systemctl enable --now sshd
}
function ArchInstall() {
echo "[LOG]: Creating ssh user..."
useradd -mG wheel $USERNAME && echo -e "$PASSWORD\n$PASSWORD" | passwd $USERNAME
echo "[LOG]: Creating temporary mirror..."
echo -e " ## Worldwide\nServer = http://mirror.rackspace.com/archlinux/\$repo/os/\$arch\nServer = https://mirror.rackspace.com/archlinux/\$repo/os/\$arch" >/etc/pacman.d/mirrorlist
echo "[LOG]: Updating keyring..."
rm -rf /etc/pacman.d/gnupg
pacman-key --init
pacman-key --populate archlinux
pacman-key --refresh-keys
pacman -Sy archlinux-keyring --noconfirm
echo -e "\n"
echo "[LOG]: Updating arch linux and installing base-devel"
pacman -Syu --noconfirm && pacman -S base-devel git wget curl bash-completion sudo --needed --noconfirm
echo -e "\n"
echo "[LOG]: Installing ssh if needed..."
echo -e "%wheel ALL=(ALL:ALL) ALL" >>/etc/sudoers
pacman -S openssh --needed && systemctl enable --now sshd
echo "[LOG]: Downloading yay..."
wget https://github.com/Jguer/yay/releases/download/v11.2.0/yay_11.2.0_x86_64.tar.gz
echo "[LOG]: Extracting yay..."
tar -xf ./yay_11.2.0_x86_64.tar.gz && cd yay_11.2.0_x86_64
echo "[LOG]: Installing yay to system..."
./yay -S yay-bin --noconfirm
echo "[LOG]: Installing rate-mirrors..."
yay -S rate-mirrors-bin --noconfirm
echo "[LOG]: Updating mirrors..."
rate-mirrors --allow-root --save /etc/pacman.d/mirrorlist arch
echo "[LOG]: Deleting temp yay"
rm -rf --verbose $HOME/yay_11.2.0_x86_64
rm --verbose $HOME/yay_11.2.0_x86_64.tar.gz
}
function UbuntuInstall() {
echo "[LOG]: Creating backup for local repo..."
echo -e "deb http://kartolo.sby.datautama.net.id/ubuntu/ ${UBUNTU_CODENAME} main restricted universe multiverse\ndeb http://kartolo.sby.datautama.net.id/ubuntu/ ${UBUNTU_CODENAME}-updates main restricted universe multiverse\ndeb http://kartolo.sby.datautama.net.id/ubuntu/ ${UBUNTU_CODENAME}-security main restricted universe multiverse" >/etc/apt/sources.list
CreateLoginUser
echo "[LOG]: Updating system..."
apt update && apt upgrade -y && apt install sudo openssh-server curl -y
echo "[LOG]: Installing ssh if needed..."
echo -e "%wheel ALL=(ALL:ALL) ALL" >>/etc/sudoers
systemctl enable --now ssh
}
function DebianInstall() {
CreateLoginUser
echo "[LOG]: Updating system..."
apt update && apt upgrade -y
echo "[LOG]: Installing ssh if needed..."
apt install sudo openssh-server curl -y
echo -e "%wheel ALL=(ALL:ALL) ALL" >>/etc/sudoers
systemctl enable --now ssh
}
function AlpineInstall() {
echo "[LOG]: Updating system..."
apk upgrade
echo "[LOG]: Installing bash & sudo..."
apk add bash sudo
echo "[LOG]: Creating ssh user..."
adduser $USERNAME -G wheel -s $(which bash 2>/dev/null) -SD && echo -e "$PASSWORD\n$PASSWORD" | passwd $USERNAME
echo -e "%wheel ALL=(ALL:ALL) ALL" >>/etc/sudoers
echo "[LOG]: Installing openssh server..."
apk add openssh-server
echo "[LOG]: Enabling ssh server..."
rc-update add sshd
service sshd start
}
function CentOSInstall() {
if (($VERSION_ID >= 8)); then
if [[ "$PRETTY_NAME" =~ .*"Stream".* ]]; then
echo "[LOG]: Using Distro CentOS Stream..."
else
echo "[LOG]: Fixing AppStream not Found..."
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
cd ~
fi
fi
echo "[LOG]: Updating the system..."
yum update -y
echo "[LOG]: Installing requirements..."
yum install openssh-server sudo yum-utils ncurses -y
echo "[LOG]: Enabling Extra Packages..."
yum install epel-release -y
echo "[LOG]: Updating system again..."
yum update -y
CreateLoginUser
echo "[LOG]: Enabling SSH Server"
systemctl enable --now sshd
}
function SUSELeapInstall() {
echo "[LOG]: Disabling SLE and Backports mirror..."
zypper mr -d repo-sle-update repo-backports-update
echo "[LOG]: Updating and installing missing tools..."
zypper -vn update -y && zypper -vn install bash-completion sudo curl wget
echo "[LOG]: Prefering IPv4 instead of IPv6"
wget http://gogs.com/lendra/lxc-setup/raw/main/gai.conf || curl -o gai.conf http://gogs.com/lendra/lxc-setup/raw/main/gai.conf
mv gai.conf /etc/
CreateLoginUser
echo "[LOG]: Installing SSH Server..."
zypper -vn install openssh-server
echo "[LOG]: Enabling ssh remote..."
systemctl enable --now sshd
}
function AlmaLinuxInstall() {
echo "[LOG]: Prefering IPv4 instead of IPv6"
wget http://gogs.com/lendra/lxc-setup/raw/main/gai.conf || curl -o gai.conf http://gogs.com/lendra/lxc-setup/raw/main/gai.conf
mv gai.conf /etc/
echo "[LOG]: Creating backup for dnf config"
mv /etc/dnf/dnf.conf /etc/dnf/dnf.conf.bck
echo "[LOG]: Generating new dnf config file..."
wget http://gogs.com/lendra/lxc-setup/raw/main/dnf.conf || curl -o dnf.conf http://gogs.com/lendra/lxc-setup/raw/main/dnf.conf
mv dnf.conf /etc/dnf/
echo "[LOG]: Updating and installing missing tools..."
yum update -y && yum install bash-completion ncurses sudo -y
CreateLoginUser
echo "[LOG]: Installing SSH Server..."
yum install openssh-server -y
echo "[LOG]: Enabling ssh remote..."
systemctl enable --now sshd
}
echo "[LOG]: Checking Distro ID..."
echo "[LOG]: Trying install for distro $ID"
case $ID in # Select methods install by distro ID
"fedora")
FedoraInstall
;;
"debian")
DebianInstall
;;
"ubuntu")
UbuntuInstall
;;
"arch")
ArchInstall
;;
"alpine")
AlpineInstall
;;
"centos")
CentOSInstall
;;
"almalinux")
AlmaLinuxInstall
;;
"rocky")
AlmaLinuxInstall
;;
"opensuse-leap")
SUSELeapInstall
;;
*)
echo "[LOG]: We don't support this distro yet"
echo "[LOG]: So please wait for us to create installer for this distro..."
;;
esac