diff --git a/config b/config index 23ba47f..26ea0a9 100644 --- a/config +++ b/config @@ -3,7 +3,7 @@ set -a -swapfile=auto # true|MB +swapfile=auto # auto|MB username=ange user_passwd=ange diff --git a/dotfiles.sh b/dotfiles.sh index 447a363..485e5d5 100755 --- a/dotfiles.sh +++ b/dotfiles.sh @@ -1,23 +1,6 @@ #!/bin/bash -ex cd "$(dirname "$0")" . ./config -. ./lib.sh -awk 'p; /pattern/{p=1}' "$0" | arch-chroot /mnt/ su "$username" -c bash -ex; exit - - -config=(git --git-dir "$HOME/.dotfiles" --work-tree "$HOME") -repo='https://git.maby.dev/ange/.dotfiles.git' - -if [ "$EUID" = 0 ]; then - echo 'You are currently logged in as root. Continue?' - read -r -fi - -git clone --bare "$repo" "$HOME/.dotfiles" - -"${config[@]}" checkout -f -"${config[@]}" submodule update --init --recursive --remote -"${config[@]}" config status.showUntrackedFiles no - -echo -e "${BOLD}${GREEN}DONE. You need to reboot to apply the changes.${NORMAL}" +arch-chroot /mnt/ su "$username" -c bash -ex \ + < src/dotfiles.sh diff --git a/gui/dwm/install.sh b/gui/dwm/install.sh index 6fa39d4..0d102fb 100755 --- a/gui/dwm/install.sh +++ b/gui/dwm/install.sh @@ -1,29 +1,7 @@ #!/bin/bash -e cd "$(dirname "$0")" -. ./config -. ../../lib.sh -awk 'p; /pattern/{p=1}' "$(basename "$0")" | arch-chroot /mnt/ bash -ex; exit - - -# drivers -case "$(lspci -k | grep -A3 -E '(VGA|3D)')" in - *amdgpu*) - pkg=("${pkg[@]}" xf86-video-amdgpu) - ;; - *i915*) - pkg=("${pkg[@]}" xf86-video-intel) - ;; - *nouveau*) - pkg=("${pkg[@]}" xf86-video-nouveau) - ;; -esac -pac "${pkg[@]}" - -cp -rfT rootfs / - -git clone https://git.maby.dev/ange/suckless.git /tmp/suckless/ -cd /tmp/suckless -./update.sh - -echo -e "${BOLD}${GREEN}DONE. I recommend you to install dotfiles.sh to get a fully functioning config.${NORMAL}" +arch-chroot /mnt/ bash -ex \ + < ../../src/lib.sh \ + < config \ + < src/install.sh diff --git a/gui/dwm/src/install b/gui/dwm/src/install new file mode 100644 index 0000000..ff1f8ec --- /dev/null +++ b/gui/dwm/src/install @@ -0,0 +1,23 @@ +#!/bin/bash -ex + +# drivers +case "$(lspci -k | grep -A3 -E '(VGA|3D)')" in + *amdgpu*) + pkg=("${pkg[@]}" xf86-video-amdgpu) + ;; + *i915*) + pkg=("${pkg[@]}" xf86-video-intel) + ;; + *nouveau*) + pkg=("${pkg[@]}" xf86-video-nouveau) + ;; +esac +pac "${pkg[@]}" + +cp -rfT rootfs / + +git clone https://git.maby.dev/ange/suckless.git /tmp/suckless/ +cd /tmp/suckless +./update.sh + +echo -e "${BOLD}${GREEN}DONE. I recommend you to install dotfiles.sh to get a fully functioning config.${NORMAL}" diff --git a/gui/install.sh b/gui/install.sh index a80b725..7f99e5d 100755 --- a/gui/install.sh +++ b/gui/install.sh @@ -1,32 +1,7 @@ #!/bin/bash -ex cd "$(dirname "$0")" -. ./config -. ../lib.sh -awk 'p; /pattern/{p=1}' "$(basename "$0")" | arch-chroot /mnt/ bash -ex; exit - - -pac "${pkg[@]}" flatpak -flatpak install -y "${flatpakpkg[@]}" - -case "$(lspci -k | grep -E '(VGA|3D)')" in - *AMD*) - pac mesa vulkan-radeon - modules=amdgpu - ;; - *Intel*) - pac mesa vulkan-intel - modules=i915 - ;; - *NVIDIA*) - pac nvidia{,-utils,-settings} - modules='nvidia nvidia_modeset nvidia_uvm nvidia_drm' - ;; -esac - -sed -i "s/^MODULES=(/MODULES=($modules/" /etc/mkinitcpio.conf -mkinitcpio -P - -xdg-user-dirs-update - -echo -e "${BOLD}${GREEN}GPU drivers install finished.${NORMAL}" +arch-chroot /mnt/ bash -ex \ + < config \ + < ../src/lib.sh \ + < src/install.sh diff --git a/gui/src/install.sh b/gui/src/install.sh new file mode 100644 index 0000000..edb8255 --- /dev/null +++ b/gui/src/install.sh @@ -0,0 +1,26 @@ +#!/bin/bash -ex + +pac "${pkg[@]}" flatpak +flatpak install -y "${flatpakpkg[@]}" + +case "$(lspci -k | grep -E '(VGA|3D)')" in + *AMD*) + pac mesa vulkan-radeon + modules=amdgpu + ;; + *Intel*) + pac mesa vulkan-intel + modules=i915 + ;; + *NVIDIA*) + pac nvidia{,-utils,-settings} + modules='nvidia nvidia_modeset nvidia_uvm nvidia_drm' + ;; +esac + +sed -i "s/^MODULES=(/MODULES=($modules/" /etc/mkinitcpio.conf +mkinitcpio -P + +xdg-user-dirs-update + +echo -e "${BOLD}${GREEN}GPU drivers install finished.${NORMAL}" diff --git a/install.sh b/install.sh index b3055a7..efa4aa0 100755 --- a/install.sh +++ b/install.sh @@ -6,17 +6,18 @@ cd "$(dirname "$0")" ( case "$swapfile" in [0-9]*) - size=$swapfile + size="$swapfile" ;; true) - size="$(python -c "from math import ceil,log; print(2**ceil((log($swapfile)/log(2))))")" + ram="$(free -h | awk '$1 == "Mem:" {print $2}')" + size="$(python -c "from math import ceil,log; print(2**ceil((log($ram)/log(2))))")" ;; *) exit ;; esac - dd if=/dev/zero of=/mnt/swapfile bs=1M count="$swapfile" status=progress + dd if=/dev/zero of=/mnt/swapfile bs=1M count="$size" status=progress chmod 600 /mnt/swapfile mkswap /mnt/swapfile swapon /mnt/swapfile @@ -25,75 +26,11 @@ cd "$(dirname "$0")" cp -f rootfs/etc/pacman.conf /etc/pacman.conf systemctl restart reflector pacman -Sy -pacstrap -K /mnt/ "${pkg[@]}" +pacstrap -K --needed /mnt/ "${pkg[@]}" cp -rfT rootfs/ /mnt/ -genfstab -U /mnt >> /mnt/etc/fstab +genfstab -U /mnt/ >> /mnt/etc/fstab - - -awk 'p; /pattern/{p=1}' "$0" | arch-chroot /mnt/ bash -ex; exit - - - -# System config -ln -sf "/usr/share/zoneinfo/$tz" /etc/localtime -hwclock --systohc -for l in "${locales[@]}"; do - sed -i "/^#\s*$l.UTF-8/s/^#\s*//" /etc/locale.gen -done -locale-gen -echo "LANG=$lang.UTF-8" > /etc/locale.conf -echo "$hostname" > /etc/hostname - -# Drivers -case "$(lscpu | grep Vendor)" in - *AuthenticAMD*) cpu=amd ;; - *GenuineIntel*) cpu=intel ;; -esac -sed -i '/^HOOKS=(/s/filesystems/encrypt filesystems/' /etc/mkinitcpio.conf - -# Services -pac "$cpu-ucode" -systemctl enable \ - NetworkManager \ - ip6tables \ - iptables \ - podman.socket \ - reflector.timer \ - systemd-resolved \ - systemd-timesyncd - -if ls -d /sys/class/power_supply/BAT*/ > /dev/null 2>&1; then - pac "${laptop_pkg[@]}" - systemctl enable tlp -fi - -# Users -echo "root:$root_passwd" | chpasswd -useradd -mG wheel,video "$username" -s "${default_shell-/bin/bash}" -echo "$username:$user_passwd" | chpasswd -su "$username" -c 'xdg-user-dirs-update' 2> /dev/null || true - -sed -i '/^#\s*%wheel\s\+ALL=(ALL:ALL)\s\+ALL/s/^#\s*//' /etc/sudoers - -# Bootloader -bootctl install - -root="$(findmnt -nr -o source /)" -cryptdev="$(cryptsetup status "$root" | grep device | awk '{print $2}' || true)" -if [ -n "$cryptdev" ]; then - uuid="$(blkid | grep "$cryptdev" | awk '{print $2}')" - options="cryptdevice=$uuid:$(basename "$root") " -fi - -options="${options}root=$root" - -for f in /boot/loader/entries/*.conf; do - cat << EOF >> "$f" -initrd /$cpu-ucode.img -options $options rw -EOF -done - -echo -e "${BOLD}${GREEN}DONE. You can install a desktop environment \ -(see README.md). Then, you can Ctrl+D, umount -R /mnt/ and reboot${NORMAL}" +arch-chroot /mnt/ bash -ex \ + < config \ + < src/lib.sh \ + < src/install.sh diff --git a/src/dotfiles.sh b/src/dotfiles.sh new file mode 100644 index 0000000..a1c178c --- /dev/null +++ b/src/dotfiles.sh @@ -0,0 +1,17 @@ +#!/bin/bash -ex + +config=(git --git-dir "$HOME/.dotfiles" --work-tree "$HOME") +repo='https://git.maby.dev/ange/.dotfiles.git' + +if [ "$EUID" = 0 ]; then + echo 'You are currently logged in as root. Continue?' + read -r +fi + +git clone --bare "$repo" "$HOME/.dotfiles" + +"${config[@]}" checkout -f +"${config[@]}" submodule update --init --recursive --remote +"${config[@]}" config status.showUntrackedFiles no + +echo -e "${BOLD}${GREEN}DONE. You need to reboot to apply the changes.${NORMAL}" diff --git a/src/install.sh b/src/install.sh new file mode 100644 index 0000000..4c3709a --- /dev/null +++ b/src/install.sh @@ -0,0 +1,64 @@ +#!/bin/bash -ex + +# System config +ln -sf "/usr/share/zoneinfo/$tz" /etc/localtime +hwclock --systohc +for l in "${locales[@]}"; do + sed -i "/^#\s*$l.UTF-8/s/^#\s*//" /etc/locale.gen +done +locale-gen +echo "LANG=$lang.UTF-8" > /etc/locale.conf +echo "$hostname" > /etc/hostname + +# Drivers +case "$(lscpu | grep Vendor)" in + *AuthenticAMD*) cpu=amd ;; + *GenuineIntel*) cpu=intel ;; +esac +sed -i '/^HOOKS=(/s/filesystems/encrypt filesystems/' /etc/mkinitcpio.conf + +# Services +pac "$cpu-ucode" +systemctl enable \ + NetworkManager \ + ip6tables \ + iptables \ + podman.socket \ + reflector.timer \ + systemd-resolved \ + systemd-timesyncd + +if ls -d /sys/class/power_supply/BAT*/ > /dev/null 2>&1; then + pac "${laptop_pkg[@]}" + systemctl enable tlp +fi + +# Users +echo "root:$root_passwd" | chpasswd +useradd -mG wheel,video "$username" -s "${default_shell-/bin/bash}" +echo "$username:$user_passwd" | chpasswd +su "$username" -c 'xdg-user-dirs-update' 2> /dev/null || true + +sed -i '/^#\s*%wheel\s\+ALL=(ALL:ALL)\s\+ALL/s/^#\s*//' /etc/sudoers + +# Bootloader +bootctl install + +root="$(findmnt -nr -o source /)" +cryptdev="$(cryptsetup status "$root" | grep device | awk '{print $2}' || true)" +if [ -n "$cryptdev" ]; then + uuid="$(blkid | grep "$cryptdev" | awk '{print $2}')" + options="cryptdevice=$uuid:$(basename "$root") " +fi + +options="${options}root=$root" + +for f in /boot/loader/entries/*.conf; do + cat << EOF >> "$f" +initrd /$cpu-ucode.img +options $options rw +EOF +done + +echo -e "${BOLD}${GREEN}DONE. You can install a desktop environment \ +(see README.md). Then, you can Ctrl+D, umount -R /mnt/ and reboot${NORMAL}" diff --git a/lib.sh b/src/lib.sh similarity index 100% rename from lib.sh rename to src/lib.sh