11#! /bin/bash
22
3- set -euo pipefail
4-
53# Check if this script is run as root
64if [[ $EUID -ne 0 ]]; then
7- echo " Please run as root: sudo $0 "
5+ echo " Please run as root: sudo ./run.sh "
86 exit 1
97fi
108
1715# Display notice message
1816display_notice () {
1917 read -r -d ' ' notice_message << EOF
20- IMPORTANT NOTICE:
21- This script will enable SSH on the host and remove any graphical interface .
22- After the reboot, you will need to access the system using SSH.
23- Please ensure you have the necessary information to connect via SSH .
18+ READ THIS ...
19+ SSH will be enabled on the host, and the console will not show any display during the reboot process .
20+ There is a potential that you will have no display at all available. Be prepared with SSH.
21+ Once the installer finishes, log in with SSH to the new headless machine using the user you created during installation .
2422
25- The installer will now proceed with the automated setup process.
23+ ## Do not try to log in until the system reboots.
24+ ## This is a fully automated installer! Now sit back and relax...
2625
27- Your current IP address is:
26+ As a reminder, your IP address is:
2827$( ip address)
2928
3029EOF
3130 echo " $notice_message "
32- read -p " Press Enter to continue or Ctrl+C to abort..."
33- pacman-mirrors -f 15
34- current_user=$( logname)
31+ sleep 20
32+ pacman-mirrors
33+ pacman-mirrors -f15
34+ u=$( logname)
35+ echo " ${u} " > user.log
36+ echo " Remember current user $u before reboot"
37+ touch notice.log
3538}
3639
3740# Check if Docker installation is requested
38- read -p " Do you want to install Docker? [y/N]: " install_docker_choice
39- install_docker_choice=${install_docker_choice,,}
40-
41- # Execute notice display
42- display_notice
41+ install_docker_choice=" "
42+ while [[ ! " $install_docker_choice " =~ ^(y| n)$ ]]; do
43+ read -r -p " Do you want to install Docker? [y/n]: " install_docker_choice
44+ install_docker_choice=${install_docker_choice,,} # Convert the choice to lowercase
45+ done
46+
47+ # Execute notice display only if Docker installation is chosen
48+ if [[ ! -f ./notice.log ]]; then
49+ display_notice
50+ fi
4351
4452# Function to remove packages safely
4553remove_packages () {
4654 for package in " $@ " ; do
4755 if pacman -Qi " $package " & > /dev/null; then
48- pacman -Rcns --noconfirm " $package "
56+ yes | pacman -Rcns " $package "
57+ else
58+ echo " Package $package does not exist. Skipping."
4959 fi
5060 done
5161}
5262
53- # Remove XFCE4 and GNOME GUI if found
54- gui_packages=(
55- xfce4 wayland gtkhash-thunar libxfce4ui mousepad orage thunar-archive-plugin thunar-media-tags-plugin
56- xfce4-panel xfce4-battery-plugin xfce4-clipman-plugin xfce4-pulseaudio-plugin xfce4-screenshooter
57- xfce4-whiskermenu-plugin xfce4-xkb-plugin parole xfce4-notifyd lightdm light-locker lightdm-gtk-greeter
58- lightdm-gtk-greeter-settings modemmanager gnome gnome-session gnome-shell wayland gnome-terminal
59- gnome-control-center gnome-backgrounds gnome-calculator gnome-disk-utility gnome-keyring gnome-logs
60- gnome-menus gnome-online-accounts gnome-settings-daemon gnome-shell-extensions gnome-software-packagekit-plugin
61- gnome-software packagekit packagekit-qt5 polkit-gnome seahorse vino xdg-user-dirs-gtk
62- )
63- remove_packages " ${gui_packages[@]} "
63+ # Remove XFCE4 GUI if found
64+ if xfce4-panel --version & > /dev/null; then
65+ echo " Removing XFCE4 GUI"
66+ remove_packages xfce4 wayland gtkhash-thunar libxfce4ui mousepad orage thunar-archive-plugin thunar-media-tags-plugin xfce4-panel xfce4-battery-plugin xfce4-clipman-plugin xfce4-pulseaudio-plugin xfce4-screenshooter xfce4-whiskermenu-plugin xfce4-xkb-plugin parole xfce4-notifyd lightdm light-locker lightdm-gtk-greeter lightdm-gtk-greeter-settings modemmanager
67+ else
68+ echo " XFCE4 not found! No GUI removed"
69+ fi
70+
71+ # Remove GNOME GUI if found
72+ if gnome-session --version & > /dev/null; then
73+ echo " Removing GNOME GUI"
74+ remove_packages gnome gnome-session gnome-shell wayland gnome-terminal gnome-control-center gnome-backgrounds gnome-calculator gnome-disk-utility gnome-keyring gnome-logs gnome-menus gnome-online-accounts gnome-settings-daemon gnome-shell-extensions gnome-software-packagekit-plugin gnome-software packagekit packagekit-qt5 polkit-gnome seahorse vino xdg-user-dirs-gtk
75+ else
76+ echo " GNOME not found! No GUI removed"
77+ fi
6478
6579# Install necessary packages
66- packages=(
67- ntp glances htop bmon jq whois yay ufw fail2ban git kubectl lvm2 wireguard-tools openssh
68- autoconf automake binutils bison fakeroot file findutils flex gawk gcc gettext grep groff
69- gzip libtool m4 make pacman patch pkgconf sed sudo systemd texinfo util-linux which
70- )
71- pacman -Sy --noconfirm " ${packages[@]} "
80+ echo " Installing packages: ntp glances htop bmon jq whois yay ufw fail2ban git kubectl lvm2 wireguard-tools openssh"
81+ yes | pacman -Sy ntp glances htop bmon jq whois yay ufw fail2ban git kubectl lvm2 wireguard-tools openssh
7282
7383# Install Docker and related packages if chosen
7484if [[ " $install_docker_choice " =~ ^[yY]$ ]]; then
75- pacman -Sy --noconfirm docker docker-compose
76- groupadd -f docker
77- usermod -aG docker " $current_user "
85+ echo " Installing Docker and Docker Compose"
86+ yes | pacman -Sy docker docker-compose
87+
88+ echo " Setting up Docker user"
89+ groupadd docker
90+ usermod -aG docker " $( cat user.log) "
7891fi
7992
80- # Configure SSH
93+ # Create .ssh directory for keys
94+ echo " Creating .ssh directory for keys"
8195mkdir -p ~ /.ssh
82- chmod 700 ~ /.ssh
83- systemctl enable --now sshd.service
96+
97+ # Enable and start SSH
98+ echo " Enabling SSH"
99+ systemctl enable sshd.service
100+ systemctl start sshd.service
84101
85102# Configure UFW
103+ echo " Configuring UFW"
86104ufw allow ssh
87105ufw limit ssh
88106ufw --force enable
89107
90108# Add wireguard to kernel modules
109+ echo " Adding wireguard to kernel modules"
91110echo " wireguard" >> /etc/modules
92111
93112# Rotate logs at 50M
113+ echo " Rotating logs at 50M"
94114sed -i " /^#SystemMaxUse/s/#SystemMaxUse=/SystemMaxUse=50M/" /etc/systemd/journald.conf
95115
96116# Set time to use NTP
117+ echo " Setting time to use NTP"
97118timedatectl set-ntp true
98119
120+ # Install base-devel and packages for building
121+ echo " Installing base-devel and build packages"
122+ yes | pacman -Sy autoconf automake binutils bison fakeroot file findutils flex gawk gcc gettext grep groff gzip libtool m4 make pacman patch pkgconf sed sudo systemd texinfo util-linux which
123+
99124# Update all packages
100- pacman -Syu --noconfirm
125+ echo " Updating packages"
126+ yes | pacman -Syyu
101127
102128# Configure fail2ban for SSH
129+ echo " Configuring fail2ban for SSH"
103130cat << EOF > /etc/fail2ban/jail.d/sshd.local
104131[sshd]
105132enabled = true
@@ -111,12 +138,21 @@ findtime = 1d
111138bantime = 52w
112139EOF
113140
114- # Enable services
141+ # Enable fail2ban and Docker services
142+ echo " Enabling fail2ban and Docker services"
115143systemctl enable fail2ban.service
116- [[ " $install_docker_choice " =~ ^[yY]$ ]] && systemctl enable docker.service
144+ if [[ " $install_docker_choice " =~ ^[yY]$ ]]; then
145+ systemctl enable docker.service
146+ fi
147+
148+ # Enable time sync
149+ echo " Enabling time sync"
117150systemctl enable ntpd.service
118151
119- # Reload systemd daemon
152+ # Reload systemctl daemon
153+ echo " Reloading systemctl daemon"
120154systemctl daemon-reload
121155
122- echo " Setup complete. Please reboot the system for changes to take effect."
156+ # Reboot the system
157+ echo " Rebooting..."
158+ reboot now
0 commit comments