#!/bin/bash
set -e
ARCH_USERNAME=${ARCH_USERNAME:-tux}
ARCH_PASSWORD=${ARCH_PASSWORD:-1}
ARCH_HOSTNAME=${ARCH_HOSTNAME:-${ARCH_USERNAME}-pc}
ARCH_MOUNT=${ARCH_MOUNT:-/mnt}
ARCH_TIMEZONE=${ARCH_TIMEZONE:-Europe/Moscow}
ARCH_LOCALE=${ARCH_LOCALE:-en_US}
ARCH_EFI_DIRECTORY=${ARCH_EFI_DIRECTORY:-/boot/efi}
ARCH_BOOTLOADER_ID=${ARCH_BOOTLOADER_ID:-Arch}
echo "pacstrap"
# Баг: если поставить deepin и deepin-extra вместе, то после логина мы будем созерцать белый экран
pacstrap $ARCH_MOUNT base base-devel linux linux-firmware linux-headers efibootmgr grub os-prober ntfs-3g exfat-utils btrfs-progs git vim nano wget zsh xorg lightdm deepin firefox networkmanager
echo "generate fstab"
genfstab -U "$ARCH_MOUNT" >> "$ARCH_MOUNT/etc/fstab"
echo "change root"
arch-chroot "$ARCH_MOUNT" /bin/bash <<CHROOTEOF
echo "set timezone and locale"
ln -sf "/usr/share/zoneinfo/$ARCH_TIMEZONE" /etc/localtime
hwclock --systohc
mv /etc/locale.gen /etc/locale.gen.bak
echo "$ARCH_LOCALE.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
echo "LANG=$ARCH_LOCALE.UTF-8" > /etc/locale.conf
echo "configure hostname"
echo $ARCH_HOSTNAME > /etc/hostname
cat > /etc/hosts <<EOF
127.0.0.1 $ARCH_HOSTNAME
::1 $ARCH_HOSTNAME
127.0.1.1 $ARCH_HOSTNAME.localdomain $ARCH_HOSTNAME
EOF
echo "lock root account"
passwd -l root
# expired
chage -E0 root
# change shell
usermod -s /sbin/nologin root
echo "create user $ARCH_USERNAME"
useradd -m -g users -G wheel -s /bin/zsh $ARCH_USERNAME
echo "$ARCH_USERNAME:$ARCH_PASSWORD" | chpasswd
sed -i 's/^# \(%wheel ALL=(ALL) ALL\)$/\1/' /etc/sudoers
echo "install grub"
grub-install --target=x86_64-efi --efi-directory="$ARCH_EFI_DIRECTORY" --bootloader-id="$ARCH_BOOTLOADER_ID"
grub-mkconfig -o /boot/grub/grub.cfg
echo "configure lightdm"
sed -i 's/^#greeter-session=.*/greeter-session=lightdm-deepin-greeter/' /etc/lightdm/lightdm.conf
# lightdm --test-mode --debug
echo "enable services"
systemctl enable lightdm
systemctl enable NetworkManager
CHROOTEOF
echo "installation completed!"
echo "do not forget remove disk from virtual drive"