archiso-zfs/init
2020-05-05 23:43:48 +02:00

70 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
# This script load zfs kernel module for any archiso.
# github.com/eoli3n
# Thanks to CalimeroTeknik on #archlinux-fr, FFY00 on #archlinux-projects, JohnDoe2 on #regex
print () {
echo -e "\n\033[1m> $1\033[0m\n"
}
print "Testing if archiso is running"
grep archiso /proc/cmdline > /dev/null
print "Increasing cowspace to half of RAM"
mount -o remount,size=50% /run/archiso/cowspace
# Get running kernel version
# https://github.com/archzfs/archzfs/issues/337#issuecomment-624312576
kernel_version=$(pacman -Qi linux | sed -n 's/^Version\s*: //p')
kernel_version_fixed=$(sed 's/-/\./' <<< $kernel_version)
print "Current kernel version is $kernel_version"
# Set regex to match package
regex='href="\Kzfs-linux-[0-9].*?'"$kernel_version_fixed"'.*?(?!.+\.sig)x86_64[^\"]+'
# Set archzfs URLs list
urls="http://archzfs.com/archzfs/x86_64/ http://archzfs.com/archive_archzfs/"
# Loop search
for url in $urls
do
print "Searching on $url..."
# Query url and try to match package
package=$(curl -s "$url" | grep -Po "$regex")
# If a package is found
if [[ ! -z $package ]]
then
print "$package found"
# Break loop
break
fi
done
# If a package is found
if [[ ! -z $package ]]
then
# Build package url
package_url="$url$package"
print "Installing package $package..."
# Install package
pacman -U "$package_url"
print "Loading zfs kernel module"
# Load kernel module
modprobe zfs && print "ZFS module is working"
else
print "No module found for current kernel version on Archzfs repos"
fi