Ver Fonte

interactively ask for missing settings (env variables)

make disk partitioning smarter

fix bootctl behavior to get root partition dynamically

add smart swap size calculation if hibernation is desired

adjust package installation logic and add useful packages
Casey DeLorme há 5 anos atrás
pai
commit
1f7e5e58a9
4 ficheiros alterados com 95 adições e 75 exclusões
  1. 30 24
      arch.sh
  2. 1 0
      packer.json
  3. 58 28
      setup/install.sh
  4. 6 23
      todo.md

+ 30 - 24
arch.sh

@@ -10,10 +10,10 @@
 # and runs as root.  Expects `username`, `password`, and `root_password` to be
 # supplied.
 
-# verify supplied variables
-[ -z "$root_password" ] && echo "missing root password..." && exit 1
-[ -z "$username" ] && echo "missing username..." && exit 1
-[ -z "$password" ] && echo "missing password..." && exit 1
+# verify required variables
+while [ -z "$root_password" ]; do read -p "please enter a root password: " -s root_password && echo ""; done
+while [ -z "$username" ]; do read -p "please enter your username: " username; done
+while [ -z "$password" ]; do read -p "please enter your password: " -s password && echo ""; done
 
 # print all that transpires henceforth
 [ -n "$DEBUG" ] && set -x
@@ -23,7 +23,6 @@ ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
 hwclock -w --utc
 
 # setup locale
-# @todo: determine how to deal with dual-languages
 sed -i "/^en_US.UTF-8/d" /etc/locale.gen
 # sed -i "/^ja_JP.UTF-8/d" /etc/locale.gen
 echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
@@ -44,13 +43,20 @@ echo "FONT=koi8u_8x16" > /etc/vconsole.conf
 # enable multilib
 sed -i "/\[multilib\]/,/Include/"'s/^#//' /etc/pacman.conf
 
-# update and install all packages
-pacman -Syu --noconfirm sudo bash-completion tmux vim linux-firmware linux-headers dkms smartmontools cryptsetup usbutils btrfs-progs gvfs dmidecode parted pkgfile pkgconf bison gcc gcc-libs cmake ccache ncurses xmlstarlet jq at bc cronie iptables rsync net-tools openssh sshfs ntp wget curl wireless_tools bluez bluez-utils lzop unzip p7zip xz unrar unace lrzip arj git mercurial subversion bzr postgresql mesa lib32-mesa dbus polkit xorg-server xorg-server-devel xorg-xinit xorg-xinput xorg-xdpyinfo xdotool xsel pulseaudio vulkan-tools arandr feh hsetroot openbox obmenu archlinux-xdg-menu compton xarchiver pavucontrol pasystray xdg-utils xdg-user-dirs tint2 conky pcmanfm gmrun rxvt-unicode urxvt-perls gnome-themes-extra gnome-icon-theme arc-gtk-theme gtk-engines gtk-engine-murrine lxappearance graphicsmagick imagemagick lame libwebp libid3tag libvorbis vorbis-tools faac x264 x265 libexif ffmpeg ffmpegthumbnailer tumbler joyutils evtest lm_sensors lshw gparted psensor gparted hardinfo fontconfig ttf-bitstream-vera ttf-droid ttf-dejavu ttf-freefont ttf-liberation ttf-hanazono mpv openshot gimp krita transmission-cli evince viewnior virtualbox-host-modules-arch virtualbox vagrant guvcview dia mednafen mame ppsspp lutris steam wine python-pip python-setuptools winetricks
+# rebuild gpg keys
+rm -rf /etc/pacman.d/gnupg
+pacman-key --init
+pacman-key --populate archlinux
 
 # add sublime text source
 curl -O https://download.sublimetext.com/sublimehq-pub.gpg && pacman-key --add sublimehq-pub.gpg && pacman-key --lsign-key 8A8F901A && rm sublimehq-pub.gpg
 [ $(grep -c "sublime-text" /etc/pacman.conf) -eq 0 ] && echo -e "\n[sublime-text]\nServer = https://download.sublimetext.com/arch/stable/x86_64" | tee -a /etc/pacman.conf
-pacman -Syu --noconfirm sublime-text
+
+# update and install all packages
+pacman -Syu --noconfirm sudo bash-completion tmux vim linux-firmware linux-headers dkms smartmontools cryptsetup usbutils btrfs-progs gvfs dmidecode parted pkgfile pkgconf bison gcc gcc-libs cmake ccache ncurses xmlstarlet jq at bc cronie iptables rsync net-tools openssh sshfs ntp wget curl wireless_tools bluez bluez-utils lzop unzip p7zip xz unrar unace lrzip arj git mercurial subversion bzr postgresql mesa lib32-mesa dbus polkit xorg-server xorg-server-devel xorg-xinit xorg-xinput xorg-xdpyinfo xdotool xsel pulseaudio vulkan-tools arandr feh hsetroot openbox obmenu archlinux-xdg-menu compton xarchiver pavucontrol pasystray xdg-utils xdg-user-dirs tint2 conky pcmanfm gmrun rxvt-unicode urxvt-perls gnome-themes-extra gnome-icon-theme arc-gtk-theme gtk-engines gtk-engine-murrine lxappearance graphicsmagick imagemagick lame libwebp libid3tag libvorbis vorbis-tools faac x264 x265 libexif ffmpeg ffmpegthumbnailer tumbler joyutils evtest lm_sensors lshw gparted psensor gparted hardinfo fontconfig ttf-bitstream-vera ttf-droid ttf-dejavu ttf-freefont ttf-liberation ttf-hanazono mpv openshot gimp krita transmission-cli evince viewnior virtualbox-host-modules-arch virtualbox vagrant guvcview dia mednafen mame ppsspp lutris steam wine python-pip python-setuptools winetricks sublime-text
+
+# if the active network device is wireless install connman
+[ -d "/sys/class/net/${active_network_device}/wireless" ] && pacman -Syu connman wpa_supplicant openvpn ethtool iwd pptpclient && systemctl enable connman
 
 # install protontricks
 python3 -m pip install protontricks
@@ -76,17 +82,29 @@ fi
 
 # install AMD/Radeon related packages
 if [ $(lspci | grep -i "vga" | grep -ci "amd") -gt 0 ]; then
-	pacman -Syu --noconfirm xf86-video-amdgpu vulkan-radeon lib32-vulkan-radeon libva-mesa-driver lib32-libva-mesa-driver
+	pacman -Syu --noconfirm xf86-video-amdgpu vulkan-radeon lib32-vulkan-radeon libva-mesa-driver lib32-libva-mesa-driver mesa-vdpau lib32-mesa-vdpau
 
 	# update modules to load
 	[ $(grep -c "amd" /etc/mkinitcpio.conf) -eq 0 ] && sed -i 's/MODULES=(\(.*\))/MODULES=(\1 amdgpu radeon)/' /etc/mkinitcpio.conf
 fi
 
-# temporarily create a user to install aur packages
+# create a user to install aur packages
 export aur_username=$(head /dev/urandom | tr -dc a-z | head -c 13 ; echo '')
 useradd -r -m -s /bin/bash $aur_username
 echo "${aur_username} ALL= NOPASSWD: /usr/bin/pacman" > /etc/sudoers.d/${aur_username}
 
+# install laptop packages and optimize system configuration
+export chassistype=$(dmidecode --string chassis-type)
+if [[ "$chassistype" = "Laptop" || "$chassistype" = "Portable" || "$chassistype" = "Notebook" || "$chassistype" = "Sub Notebook" ]]; then
+	pacman -Syu --noconfirm xf86-input-synaptics acpid hdparm sdparm acpilight connman wpa_supplicant openvpn ethtool iwd pptpclient
+	systemctl enable connman
+	systemctl enable acpid
+
+	sudo -u $aur_username git clone https://aur.archlinux.org/laptop-mode-tools.git /home/${aur_username}/laptop-mode-tools
+	(cd /home/${aur_username}/laptop-mode-tools && sudo -u ${aur_username} makepkg -rcsi --noconfirm)
+	systemctl enable laptop-mode
+fi
+
 # install xcursor-chameleon-skyblue
 sudo -u $aur_username git clone https://aur.archlinux.org/xcursor-chameleon-skyblue.git /home/${aur_username}/xcursor-chameleon-skyblue
 (cd /home/${aur_username}/xcursor-chameleon-skyblue && sudo -u ${aur_username} makepkg -rcsi --noconfirm)
@@ -111,19 +129,7 @@ sudo -u $aur_username git clone https://aur.archlinux.org/libc++.git /home/${aur
 sudo -u $aur_username git clone https://aur.archlinux.org/discord.git /home/${aur_username}/discord
 (cd /home/${aur_username}/discord && sudo -u ${aur_username} makepkg --nocheck -rcsi --noconfirm)
 
-# install laptop packages and optimize system configuration
-export chassistype=$(dmidecode --string chassis-type)
-if [[ "$chassistype" = "Laptop" || "$chassistype" = "Portable" || "$chassistype" = "Notebook" || "$chassistype" = "Sub Notebook" ]]; then
-	pacman -Syu --noconfirm xf86-input-synaptics connman wpa_supplicant openvpn acpid ethtool hdparm sdparm acpilight
-	systemctl enable connman
-	systemctl enable acpid
-
-	sudo -u $aur_username git clone https://aur.archlinux.org/laptop-mode-tools.git /home/${aur_username}/laptop-mode-tools
-	(cd /home/${aur_username}/laptop-mode-tools && sudo -u ${aur_username} makepkg -rcsi --noconfirm)
-	systemctl enable laptop-mode
-fi
-
-# cleanup temporary aur user
+# cleanup aur user
 rm -rf /etc/sudoers.d/${aur_username}
 userdel -fr $aur_username
 unset $aur_username
@@ -285,7 +291,7 @@ echo "linux vmlinuz-linux" >> /boot/loader/entries/arch.conf
 [ -f /boot/intel-ucode.img ] && echo "initrd /intel-ucode.img" >> /boot/loader/entries/arch.conf
 [ -f /boot/amd-ucode.img ] && echo "initrd /amd-ucode.img" >> /boot/loader/entries/arch.conf
 echo "initrd /initramfs-linux.img" >> /boot/loader/entries/arch.conf
-echo "options root=PARTUUID=$(blkid -s PARTUUID -o value /dev/sda3) rw" >> /boot/loader/entries/arch.conf
+echo "options root=PARTUUID=$(blkid -s PARTUUID -o value $(mount | grep ' / '|cut -d' ' -f 1)) rw" >> /boot/loader/entries/arch.conf
 [[ $(lspci | grep -i " vga" | grep -ci " nvidia") -gt 0 && $(grep -c "nvidia" /boot/loader/entires/arch.conf) -eq 0 ]] && sed -i 's/rw/rw nvidia-dkm.modeset=1/' /boot/loader/entires/arch.conf
 
 # set boot loader entry as default

+ 1 - 0
packer.json

@@ -55,6 +55,7 @@
 			"expect_disconnect": true,
 			"environment_vars": [
 				"DEBUG=true",
+				"enable_hibernation=y",
 				"root_password={{user `root_password`}}",
 				"username={{user `username`}}",
 				"password={{user `password`}}"

+ 58 - 28
setup/install.sh

@@ -1,22 +1,26 @@
-#!/usr/bin/bash -eu
+#!/usr/bin/bash -e
 #
 # Author: Casey DeLorme
 #
-# This is used by my packer build, but is wired to work for a complete install.
+# Description: A fully automated installation script wired for testing with
+# packer, but fully functional for a standard installation.
 #
-# Description: Thse are the pre-installation steps for Arch, where you may have
-# launched the iso and have a terminal, but you're working off a live system
-# and still need to partition the disk.
+# Make sure you have a network connection, install git, clone this repository,
+# and finally run this script to automate the entire installation.
 #
-# Warning: This installation is wired for efi mode installations.  While it
-# may print a warning it won't stop the installation and may leave you with
-# a derelict system.
-#
-# Warning: This currently uses /dev/sda explicitly and may delete data or fail
-# if there are multiple disks connected or you are using alternative storage
-# such as M.2/NVME.
+#	pacman -Sy git
+#	git clone https://git.caseydelorme.com/cdelorme/arch-desktop.git
+#	cd arch-desktop
+#	./setup/install.sh
+
+# check that efivars is mounted or notify the user that it could create a problem
+[ ! -f /sys/firmware/efi/efivars ] && echo "efivars not mounted; this install may leave you with a derelict system..." && sleep 30s
 
-[ ! -f /sys/firmware/efi/efivars ] && echo "efivars not mounted and this install may leave you with a derelict system..."
+# verify required variables
+while [[ ! "$enable_hibernation" =~ ^[yn]$ ]]; do read -p "would you like to enable hibernation (yn)? " -n1 enable_hibernation && echo ""; done
+while [ -z "$root_password" ]; do read -p "please enter a root password: " -s root_password && echo ""; done
+while [ -z "$username" ]; do read -p "please enter your username: " username; done
+while [ -z "$password" ]; do read -p "please enter your password: " -s password && echo ""; done
 
 # optionally print all commands
 [ -n "$DEBUG" ] && set -x
@@ -28,28 +32,54 @@ ping -c 3 archlinux.org
 timedatectl set-ntp true
 timedatectl status
 
-# @todo: future editions will intelligently check available disks,
-# may ask which disk to use, may detect if running on a laptop,
-# may automatically choose or ask if swap should be sized for
-# hibernation, and appropriately modify partition logic.
+# detect disks (if only one exists we can use it)
+# @todo: make sure this ignores optical drives (???)
+export disk=$(lsblk -l | grep disk | awk '{print $1}')
+
+# if more than one disk exists ask which to use:
+if [ $(echo "$disk" | wc -l) -gt 1 ]; then
+	echo -e "multiple disks found:\n$disk"
+	read -p "please enter the name of the disk you want to use: " disk
+
+	# make sure the disk exists or terminate
+	if [ ! -b "/dev/${disk}" ]; then
+		echo "unable to locate disk: /dev/${disk}"
+		exit 1
+	fi
+fi
+
+# either use sane default or intelligently size swap for hibernation
+export swap_size=2048
+if [ "$enable_hibernation" = "y" ]; then
+	export ram_size=$(numfmt --from-unit=K --from=iec --to-unit=M --to=iec $(cat /proc/meminfo | grep MemTotal | awk '{print $2}'))
+	if [ $ram_size -le $(numfmt --from-unit=1024 --from=iec 4G) ]; then
+		export swap_size=$(printf %.0f $(echo "$ram_size * 1.5" | bc))
+	else
+		export ram_sqrt=$(echo "sqrt($(numfmt --from-unit=M --to-unit=Gi $ram_size))" | bc)
+ 		export swap_size=$(printf %.0f $(echo "$ram_size + $(numfmt --from-unit=Gi --to-unit=Mi $ram_sqrt)" | bc))
+	fi
+fi
 
 # partition the hard drive
-parted /dev/sda -s 'mklabel gpt'
-parted /dev/sda -s 'mkpart primary fat32 1MiB 1024MiB'
-parted /dev/sda -s 'set 1 esp on'
-parted /dev/sda -s 'mkpart primary linux-swap 1024MiB 3072MiB'
-parted /dev/sda -s 'mkpart primary btrfs 3072MiB 100%'
+parted "/dev/${disk}" -s 'mklabel gpt'
+parted "/dev/${disk}" -s 'mkpart primary fat32 1MiB 1024MiB'
+parted "/dev/${disk}" -s 'set 1 esp on'
+parted "/dev/${disk}" -s "mkpart primary linux-swap 1024MiB ${swap_size}MiB"
+parted "/dev/${disk}" -s "mkpart primary btrfs ${swap_size}MiB 100%"
+
+# acquire partitions as an array
+export partitions=( $(lsblk -l "/dev/${disk}" | grep part | awk '{print $1}') )
 
 # format the partitions
-mkfs.fat -F32 -nEFI /dev/sda1
-mkswap -Larch /dev/sda2
-mkfs.btrfs -fLarch /dev/sda3
+mkfs.fat -F32 -nEFI "/dev/${partitions[0]}"
+mkswap -Larch "/dev/${partitions[1]}"
+mkfs.btrfs -fLarch "/dev/${partitions[2]}"
 
 # enable and mount partitions with appropriate settings
-swapon /dev/sda2
-mount -o "noatime,compress=lzo,space_cache,autodefrag,ssd" /dev/sda3 /mnt
+swapon "/dev/${partitions[1]}"
+mount -o "noatime,compress=lzo,space_cache,autodefrag,ssd" "/dev/${partitions[2]}" /mnt
 mkdir /mnt/boot
-mount /dev/sda1 /mnt/boot
+mount "/dev/${partitions[0]}" /mnt/boot
 
 # install base and base-devel package sets, and generate the fstab
 pacstrap /mnt base base-devel

+ 6 - 23
todo.md

@@ -1,31 +1,16 @@
 
 # todo
 
-- investigate using `Ignorepkg` to lock the kernel and prevent disruption during daily updates
-
-- investigate a method of detecting "hidpi" displays without relying on xserver so we can automate configuration changes
+- consider adding `https://aur.archlinux.org/packages/yay/` to the installed AUR packages
 
-- replace hard-coded `/dev/sda`
-	- parameterize `setup/install.sh` to detect disks and interactively ask for primary
-	- parameterize disk so that `bootctl` in `arch.sh` determines the root partition
+- try and figure out how to add `ctrl+c` support to the getty login (_like debian_)
 
-- enhance `setup/install.sh` such that it can intelligently size swap
-	- detect if laptop (`pacman -S dmidecode`) or ask if user wishes to enable hibernation
-	- detect memory total (`cat /proc/meminfo | grep "MemTotal" | awk '{print $2}'`)
-		- if no hibernation
-			- total > 4GB use 20% for SWAP
-			- else use 200% total
-		- if yes hibernation
-			- if total < 6G use 200%
-			- else use 100% + 2G
+- determine whether we can detect "hidpi" without xserver to automate configuration
 
-- verify `locale-gen` with `ja_JP.UTF-8` works without any problems
-	- test `fcitx-mozc` or alternatives for GUI selection and IME support
+- determine whether we can fully automate laptop configuration
+	- _for example setting `panel_items = LTSCB` in `~/.config/tint2/tint2rc` to display battery power_
 
-- investigate `laptop-mode-tools` configuration (_on an actual laptop_)
-	- modify `panel_items = LTSCB` in `~/.config/tint2/tint2rc` for displaying battery
-
-- consider adding `https://aur.archlinux.org/packages/yay/` to the installed AUR packages
+- experiment with `fcitx-mozc` and document enabling `ja_JP` language (_instead of making it a default configuration_)
 
 - investigate `libfm` and `pcmanfm` enhancements
 	- a patch to enable directory thumbnail generation
@@ -55,5 +40,3 @@
 	- albert
 	- dmenu
 	- kupfer
-
-- try and figure out how to add `ctrl+c` support to the getty login (_like debian_)