202 lines
6.1 KiB
Bash
Executable file
202 lines
6.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
scrDir=$(dirname "$(realpath "$0")")
|
|
source "${scrDir}/global_fn.sh"
|
|
|
|
REFINDCONF="/boot/EFI/refind/refind.conf"
|
|
|
|
install_secureboot(){
|
|
sudo pacman -S sbsigntools efitools refind
|
|
echo "[sbsigntools, efitools, refind] installed, press any key to continue ..."
|
|
sudo refind-install --shim /usr/share/shim-signed/shimx64.efi --localkeys
|
|
echo "[refind-install] executed, press any key to continue ..."
|
|
|
|
echo signing [/boot/EFI/BOOT/BOOTX64.EFI]
|
|
sudo sbsign --key /etc/refind.d/keys/refind_local.key --cert /etc/refind.d/keys/refind_local.crt --output /boot/EFI/BOOT/BOOTX64.EFI /boot/EFI/BOOT/BOOTX64.EFI
|
|
echo signing [/boot/vmlinuz-linux]
|
|
sudo sbsign --key /etc/refind.d/keys/refind_local.key --cert /etc/refind.d/keys/refind_local.crt --output /boot/vmlinuz-linux /boot/vmlinuz-linux
|
|
|
|
echo -e "\033[0;32m[SECUREBOOT]\033[0m installing update-secureboot script to /usr/bin/update-secureboot"
|
|
sudo cp .refind/update-secureboot /usr/bin/update-secureboot
|
|
|
|
|
|
echo -e "\033[0;32m[SECUREBOOT]\033[0m installing pacman hook for automatic secureboot updates"
|
|
sudo mkdir -p /etc/pacman.d/hooks/
|
|
sudo cp .refind/update-secureboot.hook /etc/pacman.d/hooks/update-secureboot.hook
|
|
|
|
}
|
|
|
|
install_theme(){
|
|
sudo mkdir -p /boot/EFI/refind/themes
|
|
git clone https://github.com/catppuccin/refind.git catppuccin
|
|
cp catppuccin/assets/mocha/icons/os_arch.png catppuccin/assets/mocha/icons/os_endeavouros.png
|
|
sudo cp -rf catppuccin /boot/EFI/refind/themes/
|
|
sudo rm $REFINDCONF
|
|
sudo cp .refind/refind.conf $REFINDCONF
|
|
rm -rf catppuccin
|
|
}
|
|
|
|
|
|
# Function to auto-detect the partition where the OS is installed
|
|
detect_partition() {
|
|
# Replace this logic with a specific method to detect your desired partition
|
|
# Example: using `lsblk` and assuming the root filesystem is mounted
|
|
ROOT_PART=$(findmnt -n -o SOURCE /)
|
|
echo "$ROOT_PART"
|
|
}
|
|
|
|
# Function to create the rEFInd menuentry
|
|
create_menuentry() {
|
|
read -p "Enter the name of the OS (e.g., EndeavourOS): " OS_NAME
|
|
PARTITION=$(detect_partition)
|
|
|
|
# Ask the user if they want to include the i915.enable_dpcd_backlight=3 option
|
|
read -p "Do you want to include i915.enable_dpcd_backlight=3 (needed for screen brightness on some OLED screens) in boot options? (Y/n): " BACKLIGHT_RESPONSE
|
|
BACKLIGHT_RESPONSE=${BACKLIGHT_RESPONSE,,} # Convert to lowercase
|
|
BACKLIGHT_OPTION=""
|
|
if [[ "$BACKLIGHT_RESPONSE" == "y" || -z "$BACKLIGHT_RESPONSE" ]]; then
|
|
BACKLIGHT_OPTION="i915.enable_dpcd_backlight=3"
|
|
fi
|
|
|
|
MENUENTRY="menuentry \"$OS_NAME\" {\n"
|
|
MENUENTRY+="\ticon\t/EFI/refind/themes/catppuccin/assets/mocha/icons/os_arch.png\n"
|
|
MENUENTRY+="\tvolume\t$(basename $PARTITION)\n"
|
|
MENUENTRY+="\tloader\t/boot/vmlinuz-linux\n"
|
|
MENUENTRY+="\tinitrd\t/boot/initramfs-linux.img\n"
|
|
MENUENTRY+="\toptions\t\"root=$PARTITION rw quiet splash nowatchdog nvme_load=YES loglevel=3 intel_iommu=on iommu=pt $BACKLIGHT_OPTION ibt=off\"\n"
|
|
MENUENTRY+="}"
|
|
|
|
echo -e "$MENUENTRY"
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
install_snapd(){
|
|
|
|
echo "Cloning Snapd AUR package..."
|
|
git clone https://aur.archlinux.org/snapd.git
|
|
cd snapd
|
|
echo "Building and installing Snapd..."
|
|
makepkg -si --noconfirm
|
|
echo "Enabling snapd.socket service..."
|
|
sudo systemctl enable --now snapd.socket
|
|
echo "Enabling AppArmor for Snap confinement..."
|
|
sudo systemctl enable --now snapd.apparmor.service
|
|
echo "Creating symbolic link for classic Snap support..."
|
|
sudo ln -s /var/lib/snapd/snap /snap
|
|
|
|
|
|
echo "Waiting for Snapd to complete device seeding..."
|
|
max_retries=10
|
|
retry_count=0
|
|
while ! sudo snap wait system seed.loaded && [ $retry_count -lt $max_retries ]; do
|
|
echo "Snapd is not seeded yet, retrying... ($retry_count/$max_retries)"
|
|
sleep 2
|
|
((retry_count++))
|
|
done
|
|
|
|
# Check if seeding failed after max retries
|
|
if [ $retry_count -ge $max_retries ]; then
|
|
echo "Snapd seeding failed after $max_retries retries. Exiting."
|
|
exit 1
|
|
fi
|
|
|
|
# Now you can install your Snap package
|
|
echo "Snapd is seeded and ready, installing the Snap package..."
|
|
sudo snap install hello-world
|
|
|
|
echo "Snap installation complete!"
|
|
|
|
}
|
|
|
|
install_snap_apps(){
|
|
# Set the path to the snap_apps.lst file
|
|
SNAP_APPS_FILE="${scrDir}/.extra/snap_apps.lst"
|
|
|
|
# Check if the file exists
|
|
if [ ! -f "$SNAP_APPS_FILE" ]; then
|
|
echo "File $SNAP_APPS_FILE not found!"
|
|
exit 1
|
|
fi
|
|
|
|
# Read each line in the "snap_apps.lst" file
|
|
while IFS= read -r line
|
|
do
|
|
# Skip empty lines and lines starting with '#'
|
|
if [ -z "$line" ] || [[ "$line" == \#* ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Install the snap package
|
|
|
|
echo -e "\033[0;32m[SNAP]\033[0m installing snap packages: $line"
|
|
sudo snap install "$line"
|
|
|
|
# Check if the installation was successful
|
|
if [ $? -eq 0 ]; then
|
|
echo "$line installed successfully!"
|
|
else
|
|
echo "Failed to install $line"
|
|
fi
|
|
done < "$SNAP_APPS_FILE"
|
|
|
|
echo "All snap packages have been processed."
|
|
|
|
|
|
}
|
|
|
|
# Check with sudo
|
|
if sudo [ -f "$REFINDCONF" ]; then
|
|
echo "The file '$REFINDCONF' exists, skipping refind installation"
|
|
else
|
|
echo "refind not installed, installing now"
|
|
install_secureboot
|
|
install_theme
|
|
read -p "Do you want to create a Boot entry for rEFInd? (Y/n): " RESPONSE
|
|
RESPONSE=${RESPONSE,,}
|
|
if [[ "$RESPONSE" == "y" || -z "$RESPONSE" ]]; then
|
|
create_menuentry
|
|
else
|
|
echo "Aborted."
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ! pkg_installed snapd; then
|
|
read -p "Do you want to install Snap? (y/n): " answer
|
|
|
|
# Handle user input
|
|
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
|
|
|
echo -e "\033[0;32m[SNAP]\033[0m installing snap..."
|
|
# Install Snapd
|
|
install_snapd
|
|
|
|
# Install Snap packages
|
|
|
|
echo -e "\033[0;32m[SNAP]\033[0m installing snap packages..."
|
|
install_snap_apps
|
|
else
|
|
echo -e "\033[0;33m[SKIP]\033[0m installing snap..."
|
|
fi
|
|
|
|
else
|
|
echo -e "\033[0;33m[SKIP]\033[0m snapd is already installed..."
|
|
fi
|
|
|
|
|
|
read -p "enable systemd-resolved? (needed for wireguard) (y/n): " answer
|
|
|
|
# Handle user input
|
|
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
|
sudo systemctl enable --now systemd-resolved
|
|
else
|
|
echo "systemd-resolved skipped"
|
|
fi
|
|
|