From 956f923f3f271f9342d9fc0e86087a5efa543ab8 Mon Sep 17 00:00:00 2001 From: AngeD Date: Thu, 9 Nov 2023 12:32:30 +0100 Subject: [PATCH] feat: run scripts directly from iso --- base.sh | 64 ----------------------------------------- dotfiles.sh | 21 +++++++------- gui/dwm/install.sh | 9 ++---- gui/install.sh | 8 ++---- install.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 86 insertions(+), 88 deletions(-) delete mode 100644 base.sh diff --git a/base.sh b/base.sh deleted file mode 100644 index 7bb516b..0000000 --- a/base.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -e - -# 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/dotfiles.sh b/dotfiles.sh index cff5341..447a363 100755 --- a/dotfiles.sh +++ b/dotfiles.sh @@ -1,13 +1,12 @@ -#!/bin/bash -e -cd +#!/bin/bash -ex +cd "$(dirname "$0")" +. ./config +. ./lib.sh -if [ -t 1 ]; then - NORMAL='\e[0m' - BOLD='\e[1m' - GREEN='\e[32m' -fi +awk 'p; /pattern/{p=1}' "$0" | arch-chroot /mnt/ su "$username" -c bash -ex; exit -config="git --git-dir $HOME/.dotfiles --work-tree $HOME" + +config=(git --git-dir "$HOME/.dotfiles" --work-tree "$HOME") repo='https://git.maby.dev/ange/.dotfiles.git' if [ "$EUID" = 0 ]; then @@ -17,8 +16,8 @@ fi git clone --bare "$repo" "$HOME/.dotfiles" -$config checkout -f -$config submodule update --init --recursive --remote -$config config status.showUntrackedFiles no +"${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/gui/dwm/install.sh b/gui/dwm/install.sh index 34b038a..6fa39d4 100755 --- a/gui/dwm/install.sh +++ b/gui/dwm/install.sh @@ -3,10 +3,8 @@ cd "$(dirname "$0")" . ./config . ../../lib.sh -if [ "$EUID" != 0 ]; then - echo 'This script needs root privileges.' - exit 1 -fi +awk 'p; /pattern/{p=1}' "$(basename "$0")" | arch-chroot /mnt/ bash -ex; exit + # drivers case "$(lspci -k | grep -A3 -E '(VGA|3D)')" in @@ -28,5 +26,4 @@ git clone https://git.maby.dev/ange/suckless.git /tmp/suckless/ cd /tmp/suckless ./update.sh -echo -e "${BOLD}${GREEN}DONE. I recommend you run \`su ${username-\$username} \ --c ./dotfiles\` to get a fully functioning config.${NORMAL}" +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 2fa1699..a80b725 100755 --- a/gui/install.sh +++ b/gui/install.sh @@ -1,12 +1,10 @@ -#!/bin/bash -e +#!/bin/bash -ex cd "$(dirname "$0")" . ./config . ../lib.sh -if [ "$EUID" != 0 ]; then - echo 'This script needs root privileges.' - exit 1 -fi +awk 'p; /pattern/{p=1}' "$(basename "$0")" | arch-chroot /mnt/ bash -ex; exit + pac "${pkg[@]}" flatpak flatpak install -y "${flatpakpkg[@]}" diff --git a/install.sh b/install.sh index e2f65f0..b3055a7 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -ex cd "$(dirname "$0")" . ./config . ./lib.sh @@ -28,4 +28,72 @@ pacman -Sy pacstrap -K /mnt/ "${pkg[@]}" cp -rfT rootfs/ /mnt/ genfstab -U /mnt >> /mnt/etc/fstab -cat base.sh | arch-chroot /mnt/ bash + + + +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}"