Files
scripts/bash/install_arch.sh
2019-04-14 03:41:58 +03:00

243 lines
4.7 KiB
Bash
Executable File

#!/bin/bash
KEYMAP="dvorak-programmer"
DEVICE="/dev/sda"
USE_UEFI=true
HOSTNAME=""
USER="olari"
USER_PASS=""
ROOT_PASS=""
REGION="Europe/Tallinn"
MIRROR="http://mirrors.dotsrc.org/archlinux/\$repo/os/\$arch"
PACKAGES=(
# base groups
base
base-devel
# bootloader
grub
intel-ucode
efibootmgr
# drivers
xf86-video-intel
# network & audio
networkmanager
pulseaudio
# desktop environment
gdm # display manager
gnome-shell # session
gvfs # automount system
gvfs-smb # samba support
sushi # file preview
file-roller # archive tool
nautilus # file browser
xdg-user-dirs-gtk # filesystem manager
# fonts
ttf-dejavu
ttf-liberation
noto-fonts-cjk
noto-fonts-emoji
# media players
mpv
feh
zathura
zathura-pdf-mupdf
zathura-cb
audacious
# terminal apps
termite
tmux
vim
git
ranger
htop
openssh
youtube-dl
wget
neofetch
# other
firefox # web browser
fish # better shell
ntfs-3g # support for ntfs partitons
tlp # power manager
)
prepare_disk_uefi() {
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${DEVICE}
g # Create gpt partition table.
## Create partitions
n # Create efi partition...
1 # ... at index 1...
# ... at default start pos...
+512M # ... with 512MB size.
n # Create swap partition...
2 # ... at index 2...
# ... at default start pos...
+4G # ... with 4G size.
n # Create root partition...
3 # ... at index 3...
# ... at default start pos...
# ... with max size.
## Set partition types
t # Change parition type...
1 # ... of the efi partition...
1 # ... to "1 EFI System".
t # Change partition type...
2 # ... of the swap partition...
19 # ... to "19 Linux swap".
t # Change partition type...
3 # ... of the root partition...
20 # ... to "20 Linux filesystem"
w # Write changes
q # Quit
EOF
mkfs.fat -F32 ${DEVICE}1
mkswap ${DEVICE}2
swapon ${DEVICE}2
mkfs.ext4 ${DEVICE}3
mount ${DEVICE}3 /mnt
mkdir /mnt/boot
mount ${DEVICE}1 /mnt/boot
cat <<EOT > /mnt/etc/fstab
/dev/sda3 / ext4 noatime,discard 0 1
/dev/sda1 /boot vfat defaults 0 2
/dev/sda2 none swap sw 0 0
EOT
}
partition_disk_dos() {
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${DEVICE}
o # Create dos partition table.
## Create partitions
n # Create swap partition...
# ... with default type...
1 # ... at index 1...
# ... at default start pos...
+8G # ... with 8G size.
n # Create root partition...
# ... with default type...
2 # ... at index 2...
# ... at default start pos...
# ... with default size.
## Set partition types
t # Change parition type...
1 # ... of the swap partuition...
82 # ... to "82 Linux swap".
t # Change partition type...
2 # ... of the root partition...
83 # ... to "83 Linux".
a # Set bootable flag...
2 # ... on the root partition.
w # Write changes
q # Quit
EOF
mkswap ${DEVICE}1
swapon ${DEVICE}1
mkfs.ext4 ${DEVICE}2
mount ${DEVICE}2 /mnt
cat <<EOT > /mnt/etc/fstab
/dev/sda2 / ext4 noatime,discard 0 1
/dev/sda1 none swap sw 0 0
EOT
}
create_chroot_script() {
cat <<EOT > /mnt/chroot_script.sh
#!/bin/sh
# Discard on use
rm chroot_script.sh
# Sync clock
ln -sf /usr/share/zoneinfo/${REGION} /etc/localtime
hwclock --systohc
# Generate locale
sed -i '1ien_US.UTF-8 UTF-8' /etc/locale.gen
locale-gen
# Set locale options
echo "LANG=en_US.UTF-8" > /etc/locale.conf
echo "KEYMAP=${KEYMAP}" > /etc/vconsole.conf
# Set hostname
echo "${HOSTNAME}" > /etc/hostname
# Set up hosts file
echo -e "127.0.0.1 localhost\n::1 localhost\n127.0.1.1 ${HOSTNAME}.localdomain ${HOSTNAME}" > /etc/hosts
# Set up bootloader
if [[ ${USE_UEFI} == true ]]; then
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
grub-mkconfig -o /boot/grub/grub.cfg
else
grub-install ${DEVICE}
grub-mkconfig -o /boot/grub/grub.cfg
fi
# Set root password
echo "root:${ROOT_PASS}" | chpasswd
# Create user and set password
useradd -m -G wheel -s /bin/bash ${USER}
echo "${USER}:${USER_PASS}" | chpasswd
# Enable sudo for wheel group
sed -i '1i%wheel ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
# Enable services
systemctl enable gdm
systemctl enable NetworkManager
systemctl enable tlp
systemctl enable tlp-sleep
exit
EOT
chmod +x /mnt/chroot_script.sh
}
timedatectl set-ntp true
if [[ $USE_UEFI == true ]]; then
prepare_disk_uefi
else
prepare_disk_dos
fi
sed -i "1iServer = $MIRROR" /etc/pacman.d/mirrorlist
pacstrap /mnt ${PACKAGES[*]}
create_chroot_script
arch-chroot /mnt /bin/sh chroot_script.sh
reboot