Last active
February 14, 2025 03:23
-
-
Save xoste49/b529bd520d1f240a30d267cb97f2cf82 to your computer and use it in GitHub Desktop.
Init Arch linux LXC Proxmox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
clear | |
reflector_country="RU" | |
# Set en_US as the default locale | |
var_locale_default="en_US.UTF-8" | |
echo "==========================================" | |
echo "== Arch Linux LXC initial configuration ==" | |
echo "==========================================" | |
echo | |
echo "This script will perform the inital" | |
echo "configuration of an Arch Linux LXC." | |
echo | |
echo | |
echo | |
echo | |
echo "Setting timezone..." | |
echo "===================" | |
echo | |
echo "Configuring timezone..." | |
timedatectl set-timezone Europe/Moscow | |
date | |
echo | |
echo | |
echo | |
echo | |
echo "Configuring locales..." | |
echo "======================" | |
echo | |
echo "You now have the option to configure a custom locale or use the default ($var_locale_default) as your locale." | |
echo "Note: The locale settings can always be changed again at a later time." | |
echo | |
while true; do | |
read -p "Would you like to configure a custom locale? [no]: " -r | |
# echo | |
# Set default value for REPLY to "no" | |
REPLY=${REPLY:-"no"} | |
if [[ "${REPLY,,}" == "y" || "${REPLY,,}" == "yes" ]]; then | |
# Extract all available locales that end with UTF-8 | |
var_locales_available=($(grep -oP '^[^#]*?\.UTF-8' /usr/share/i18n/SUPPORTED)) | |
# Add all available locales to a selection menu | |
PS3=$'\n'"Please input the number of your desired locale: " | |
select var_locale_selected in "${var_locales_available[@]}"; do | |
if [[ " ${var_locales_available[@]} " =~ " ${var_locale_selected} " ]]; then | |
echo | |
echo "Selected Locale: ${var_locale_selected}" | |
echo | |
echo "LC_ALL=${var_locale_selected}" > /etc/environment | |
echo "${var_locale_selected} UTF-8" > /etc/locale.gen | |
echo "LANG=${var_locale_selected}" > /etc/locale.conf | |
locale-gen | |
break | |
else | |
echo "Invalid selection. Please try again." | |
echo "To display the list of locales again leave the input blank and press ENTER." | |
fi | |
done | |
break | |
elif [[ "${REPLY,,}" == "n" || "${REPLY,,}" == "no" ]]; then | |
echo "The default ($var_locale_default) will be used." | |
var_locale_selected="$var_locale_default" | |
echo | |
echo "LC_ALL=${var_locale_selected}" > /etc/environment | |
echo "${var_locale_selected} UTF-8" > /etc/locale.gen | |
echo "LANG=${var_locale_selected}" > /etc/locale.conf | |
locale-gen | |
break | |
else | |
echo 'Invalid input. Please enter "yes" or "no".' | |
echo | |
fi | |
done | |
echo | |
echo | |
echo | |
echo | |
echo "Configuring Pacman..." | |
echo "=====================" | |
echo | |
echo 'Getting latest mirrors from "https://archlinux.org/mirrorlist/all/https/"...' | |
curl -s 'https://archlinux.org/mirrorlist/all/https/' | sed -n '/^## Worldwide$/,/^$/p' | sed '/^$/d' | sed 's/^#Server/Server/' >| /etc/pacman.d/mirrorlist | |
echo | |
echo 'Disabling extraction of "mirrorlist.pacnew"...' | |
sed -i 's@^#NoExtract =@NoExtract = etc/pacman.conf etc/pacman.d/mirrorlist@' /etc/pacman.conf | |
echo | |
echo "Enabling parallel downloads..." | |
sed -i 's/^#ParallelDownloads = 5/ParallelDownloads = 10/' /etc/pacman.conf | |
echo | |
echo "Initializing, populating and updating keyring..." | |
echo | |
pacman-key --init | |
pacman-key --populate archlinux | |
pacman -Sy --noconfirm archlinux-keyring | |
echo | |
echo | |
echo | |
echo | |
echo "Updating system" | |
echo "===============" | |
echo | |
pacman -Su --noconfirm | |
echo | |
echo | |
echo | |
echo | |
echo "Configuring Pacman Reflector" | |
echo "============================" | |
echo | |
pacman -S --needed --noconfirm reflector | |
echo | |
echo "" > /etc/xdg/reflector/reflector.conf | |
echo "--age 12" >> /etc/xdg/reflector/reflector.conf | |
echo "--country $reflector_country" >> /etc/xdg/reflector/reflector.conf | |
echo "--latest 10" >> /etc/xdg/reflector/reflector.conf | |
echo "--protocol https" >> /etc/xdg/reflector/reflector.conf | |
echo "--save /etc/pacman.d/mirrorlist" >> /etc/xdg/reflector/reflector.conf | |
echo "--sort rate" >> /etc/xdg/reflector/reflector.conf | |
systemctl enable reflector.timer | |
echo "Generating new mirrorlist using Reflector..." | |
systemctl restart reflector.service | |
echo | |
cat /etc/pacman.d/mirrorlist | |
echo | |
echo | |
echo | |
echo | |
echo "Configuring SSH..." | |
echo "==================" | |
echo | |
echo "Generating SSH keys..." | |
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N "" | |
chmod 700 ~/.ssh | |
chmod 600 ~/.ssh/authorized_keys | |
echo | |
echo "Installing OpenSSH..." | |
pacman -S --noconfirm openssh | |
echo | |
echo "Configuring SSH daemon..." | |
sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config | |
sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config | |
echo | |
echo "Restarting and enabling SSH service..." | |
systemctl restart sshd | |
systemctl enable sshd | |
echo | |
echo | |
echo "To connect to this server, use the following command:" | |
echo "ssh root@$(hostname -I | awk '{print $1}')" | |
echo | |
echo | |
echo "Rebooting system..." | |
echo "===================" | |
echo "The initial configuration of your Arch Linux LXC is complete." | |
echo | |
read -p "Press ENTER to reboot" | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment