Class: Warding::Installer
- Inherits:
-
Object
- Object
- Warding::Installer
- Defined in:
- lib/warding.rb
Constant Summary collapse
- @@prompt =
TTY::Prompt.new
Instance Method Summary collapse
Instance Method Details
#banner ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/warding.rb', line 12 def puts <<~'EOF' ( ( ( )\))( ' ) ( )\ ) ( ( ( ((_)()\ ) ( /( )( (()/( )\ ( )\))( _(())\_)() )(_)) (()\ ((_)) ((_) )\ ) ((_))\ \ \((_)/ /((_)_ ((_) _| | (_) _(_/( (()(_) \ \/\/ / / _` | | '_| / _` | | | | ' \)) / _` | \_/\_/ \__,_| |_| \__,_| |_| |_||_| \__, | |___/ EOF end |
#check ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/warding.rb', line 27 def check unless `uname -a`.include?("archiso") @@prompt.error("Exiting...") @@prompt.warn("Warding can only be installed from within the live ISO context!") exit! end unless `[ -d /sys/firmware/efi ] && echo true`.include?("true") @@prompt.error("UEFI/EFI must be enabled to install warding.") exit! end end |
#gather ⇒ Object
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 |
# File 'lib/warding.rb', line 40 def gather locales_list = %w[en_US es_ES pt_BR ru_RU fr_FR it_IT de_DE ja_JP ko_KR zh_CN] keymaps_list = %w[us uk br en fr de zh ru it es] parsed_input = @@prompt.collect do key(:update_mirrors).yes?("Update mirrorlist?") key(:system_language).select("Pick the desired system language:", locales_list) key(:keyboard_keymap).select("Pick your keyboard layout:", keymaps_list) unless @@prompt.yes?("Set timezone automatically?", default: true) key(:update_timezone).ask("Enter timezone:", required: true) end key(:root_password).mask("Insert new root password:", default: "warding") key(:system_settings) do key(:boot_size).("Boot drive partition size (MiB):", min: 512, max: 4096, default: 1024, step: 128) key(:swap_size).("Swap partition size (MiB):", min: 1024, max: 8192, default: 2048, step: 256) if key(:encrypted).yes?("Enable encryption?", default: false) key(:encryption_settings) do key(:encryption_key).mask("Insert the encryption key:", required: true) end end end key(:desktop_environment).select("Select your desktop environment:", %w[plasma gnome i3 none]) end parsed_input end |
#install(data, encrypted = false) ⇒ Object
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/warding.rb', line 72 def install(data, encrypted = false) if @@prompt.yes?("Confirm settings and continue?") @@prompt.say("Installing, please wait...") def setup_mirrors # update mirrorlist `reflector --latest 100 --sort rate --save /etc/pacman.d/mirrorlist` end def setup_timezone(timezone = false) # set clock `timedatectl set-ntp true` # set timezone if timezone `timedatectl set-timezone #{timezone}` else `timedatectl set-timezone "$(curl -s https://ipapi.co/timezone)"` end end def setup_partitions(boot_size) # create partitions `parted -s -a optimal /dev/sda \ mklabel gpt \ mkpart primary fat32 0% #{boot_size}Mib \ set 1 esp on \ mkpart primary ext4 #{boot_size}Mib 100% \ set 2 lvm on ` end def setup_lvm(swap_size, key = false) # setup encryption if key # create an encrypted volume `echo "#{key}" | cryptsetup -q luksFormat --type luks2 --cipher aes-xts-plain64 --key-size 512 /dev/sda2` # open the volume `echo "#{key}" | cryptsetup open /dev/sda2 cryptlvm -` # setup lvm `pvcreate /dev/mapper/cryptlvm` # create virtual group `vgcreate vg0 /dev/mapper/cryptlvm` else # create physical volume `pvcreate /dev/sda2` # create virtual group `vgcreate vg0 /dev/sda2` end # create logical volumes `lvcreate -L #{swap_size}Mib vg0 -n swap` `lvcreate -l 100%FREE vg0 -n root` # make and mount rootfs `mkfs.ext4 -q /dev/vg0/root` `mount /dev/vg0/root /mnt` # make and mount boot partition `mkfs.fat -F32 /dev/sda1` `mkdir /mnt/boot` `mount /dev/sda1 /mnt/boot` # setup swap `mkswap /dev/vg0/swap` `swapon /dev/vg0/swap` end def setup_packages # update packages list `pacman -Syy` # install base system `pacstrap /mnt base base-devel linux linux-firmware linux-headers lvm2 mkinitcpio dmidecode smbclient reflector networkmanager go cronie man-db nano vi fuse wget openbsd-netcat dhcpcd samba openssh openvpn unzip vim git zsh` # generate fstab `genfstab -U /mnt >> /mnt/etc/fstab` end def setup_chroot(lang, keymap, password = "warding", encrypted = false) # set timezone `arch-chroot /mnt ln -sf /usr/share/zoneinfo/"$(curl -s https://ipapi.co/timezone)" /etc/localtime` # update clock `arch-chroot /mnt hwclock --systohc` # set locale `echo "#{lang}.UTF-8 UTF-8" > /mnt/etc/locale.gen` `arch-chroot /mnt locale-gen` `echo "LANG=#{lang}.UTF-8" > /mnt/etc/locale.conf` # set keymap `echo "KEYMAP=#{keymap}" > /mnt/etc/vconsole.conf` # update hostname `echo "warding" > /mnt/etc/hostname` # update hosts `echo "127.0.0.1 localhost\n::1 localhost\n127.0.1.1 warding.localdomain warding" > /mnt/etc/hosts` # update root password `echo -e "#{password}\n#{password}" | arch-chroot /mnt passwd` # update hooks if encrypted `sed -i "/^HOOK/s/modconf/keyboard keymap modconf/" /mnt/etc/mkinitcpio.conf` `sed -i "/^HOOK/s/filesystems/encrypt lvm2 filesystems/" /mnt/etc/mkinitcpio.conf` else `sed -i "/^HOOK/s/filesystems/lvm2 filesystems/" /mnt/etc/mkinitcpio.conf` end # recompile initramfs `arch-chroot /mnt mkinitcpio -P` # add intel microcode `arch-chroot /mnt pacman -S amd-ucode --noconfirm` end def setup_bootloader(encrypted = false) # setup systemd-boot `arch-chroot /mnt bootctl install` `echo "title Warding Linux linux /vmlinuz-linux initrd /amd-ucode.img initrd /initramfs-linux.img" > /mnt/boot/loader/entries/warding.conf` if encrypted `echo "options cryptdevice=UUID=$(blkid -s UUID -o value /dev/sda2):cryptlvm:allow-discards root=/dev/vg0/root quiet rw" >> /mnt/boot/loader/entries/warding.conf` else `echo "options root=/dev/vg0/root rw" >> /mnt/boot/loader/entries/warding.conf` end end def setup_usability # enable internet `arch-chroot /mnt systemctl -q enable NetworkManager` # add cron jobs `echo "#!/bin/bash\nreflector --latest 100 --sort rate --save /etc/pacman.d/mirrorlist" > /mnt/etc/cron.weekly/mirrorlist; chmod +x /mnt/etc/cron.weekly/mirrorlist` `echo "#!/bin/bash\npacman -Sy" > /mnt/etc/cron.weekly/pacman-sync; chmod +x /mnt/etc/cron.weekly/pacman-sync` `echo "#!/bin/bash\npacman -Syu --noconfirm" > /mnt/etc/cron.monthly/system-upgrade; chmod +x /mnt/etc/cron.monthly/system-upgrade` # enable cron jobs `arch-chroot /mnt systemctl -q enable cronie` # change default shell `arch-chroot /mnt chsh -s /usr/bin/zsh` # setup wordlists `arch-chroot /mnt mkdir -p /usr/share/wordlists` `arch-chroot /mnt curl -s https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/raft-large-directories-lowercase.txt -O --output-dir /usr/share/wordlists` `arch-chroot /mnt curl -s https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/common.txt -O --output-dir /usr/share/wordlists` `arch-chroot /mnt curl -s https://github.com/danielmiessler/SecLists/raw/master/Passwords/Leaked-Databases/rockyou.txt.tar.gz -O --output-dir /usr/share/wordlists` # setup drivers `arch-chroot /mnt pacman -S alsa-utils alsa-plugins alsa-lib --noc` # update package list `arch-chroot /mnt pacman -Syy` # user creation --fix `arch-chroot /mnt useradd -m -g wheel -s /bin/zsh ward` `sed -i '85 s/# %wheel ALL=(ALL) NOPASSWD: ALL/%wheel ALL=(ALL) NOPASSWD: ALL/g' /mnt/etc/sudoers` `arch-chroot /mnt sudo -u ward sh -c "cd /home/ward; git clone https://aur.archlinux.org/yay.git; cd yay; makepkg -si --noconfirm"` `arch-chroot /mnt sudo -u ward sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended` # check if on VM if `arch-chroot /mnt dmidecode -s system-manufacturer`.include?("VMware, Inc.") # install and enable VMware utils `arch-chroot /mnt pacman -S open-vm-tools --noconfirm` `arch-chroot /mnt systemctl -q enable vmtoolsd` end end def setup_visuals(theme) case theme when "plasma" # install packages `arch-chroot /mnt pacman -S xorg-server plasma-meta gtkmm konsole sddm kvantum-qt5 --noc -q` # create conf dir `mkdir -p /mnt/etc/sddm.conf.d` # fix theme `echo "[Theme]\nCurrent=breeze" > /mnt/etc/sddm.conf.d/theme.conf` # enable autologin `echo "[Autologin]\nUser=ward\nSession=plasma" > /mnt/etc/sddm.conf.d/autologin.conf` # enable sddm `arch-chroot /mnt systemctl -q enable sddm` when "gnome" # install packages `arch-chroot /mnt pacman -S gtkmm gnome gnome-tweaks --noc` # enable autologin `echo "[daemon]\nAutomaticLogin=ward\nAutomaticLoginEnable=True" > /mnt/etc/gdm/custom.conf` # enable gdm `arch-chroot /mnt systemctl -q enable gdm` when "i3" # install packages `arch-chroot /mnt pacman -S lightdm lightdm-gtk-greeter xorg-server xorg-apps xorg-xinit i3-wm --noc` # enable lightdm `arch-chroot /mnt systemctl -q enable lightdm` else nil end end def finish `umount -R /mnt` `reboot` end setup_mirrors if data[:update_mirrors] data[:update_timezone] ? setup_timezone(data[:update_timezone]) : setup_timezone setup_partitions(data[:system_settings][:boot_size]) data[:system_settings][:encrypted] ? setup_lvm(data[:system_settings][:swap_size], data[:system_settings][:encryption_settings][:encryption_key]) : setup_lvm(data[:system_settings][:swap_size]) setup_packages data[:system_settings][:encrypted] ? setup_chroot(data[:system_language], data[:keyboard_keymap], data[:root_password], true) : setup_chroot(data[:system_language], data[:keyboard_keymap], data[:root_password]) data[:system_settings][:encrypted] ? setup_bootloader(true) : setup_bootloader setup_usability setup_visuals(data[:desktop_environment]) finish end end |