archiso-zfs/init

70 lines
1.6 KiB
Plaintext
Raw Normal View History

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