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
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
### Functions
|
|
|
|
|
|
2020-05-01 16:19:33 +02:00
|
|
|
print () {
|
|
|
|
|
echo -e "\n\033[1m> $1\033[0m\n"
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
search_package () {
|
|
|
|
|
# $1 is package name to search
|
|
|
|
|
# $2 is version to match
|
|
|
|
|
|
|
|
|
|
# Set regex to match package
|
|
|
|
|
regex='href="\K'"$1"'-[0-9].*?'"$2"'.*?(?!.+\.sig)x86_64[^\"]+'
|
|
|
|
|
# href=" # match href="
|
|
|
|
|
# \K # don't return anything matched prior to this point
|
|
|
|
|
# '"$1"'-[0-9] # find me package-# escaped by shell
|
|
|
|
|
# .*? # match anything but newlines 0 or more times, as few times as possible (non-greedy)
|
|
|
|
|
# '"$kernel_version"' # match version escaped by shell
|
|
|
|
|
# .*? # match anything but newlines 0 or more times, as few times as possible (non-greedy)
|
|
|
|
|
# (?![^"\n]+\.sig) # remove .sig matches
|
|
|
|
|
# x86_64 # now match architecture
|
|
|
|
|
# [^\n"]+ # continue matching anything but newlines and ", 1 or more times, until end
|
|
|
|
|
|
|
|
|
|
# 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" | tail -n 1)
|
|
|
|
|
|
|
|
|
|
# If a package is found
|
|
|
|
|
if [[ ! -z $package ]]
|
|
|
|
|
then
|
|
|
|
|
|
|
|
|
|
print "$package found"
|
|
|
|
|
|
|
|
|
|
# Build package url
|
|
|
|
|
package_url="$url$package"
|
|
|
|
|
|
|
|
|
|
return $package_url
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
download_package () {
|
|
|
|
|
# $1 is package url to download in tmp
|
|
|
|
|
|
|
|
|
|
filename="${url##*/}"
|
|
|
|
|
|
|
|
|
|
# Download package in tmp
|
|
|
|
|
wget "$1" -P /tmp
|
|
|
|
|
|
|
|
|
|
# Set out file
|
|
|
|
|
output="/tmp/$filename"
|
|
|
|
|
|
|
|
|
|
print "Downloading $output ..."
|
|
|
|
|
|
|
|
|
|
return "$output"
|
|
|
|
|
}
|
|
|
|
|
|
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 23:53:53 +02:00
|
|
|
print "Adding archzfs repo"
|
|
|
|
|
|
|
|
|
|
cat >> /etc/pacman.conf <<"EOF"
|
|
|
|
|
[archzfs]
|
|
|
|
|
Server = http://archzfs.com/archzfs/x86_64
|
|
|
|
|
Server = http://mirror.sum7.eu/archlinux/archzfs/archzfs/x86_64
|
|
|
|
|
Server = https://mirror.biocrafting.net/archlinux/archzfs/archzfs/x86_64
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
print "Fetching archzfs signing keys"
|
|
|
|
|
|
|
|
|
|
pacman-key --recv-keys F75D9D76
|
|
|
|
|
pacman-key --lsign-key F75D9D76
|
|
|
|
|
|
2020-05-05 22:45:57 +02:00
|
|
|
print "Current kernel version is $kernel_version"
|
|
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
# Search kernel package
|
2020-05-01 16:19:33 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
zfs_utils_package_url=$(search_package "zfs-linux" "$kernel_version_fixed")
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
# If a package is found
|
|
|
|
|
if [[ ! -z $zfs_utils_package_url ]]
|
|
|
|
|
then
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
# Download package
|
|
|
|
|
zfs_linux_package=$(download_package "zfs-linux" "$kernel_version_fixed")
|
2020-05-05 22:45:57 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
print "Extracting $zfs_linux_package"
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
tar xvf $zfs_linux_package -C /tmp/extract
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
print "Searching zfs-utils version required"
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
zfs_utils_version=$(cat /tmp/extract/.PKGINFO | grep 'depend = zfs-utils' | grep -o '[[:digit:]].*')
|
|
|
|
|
rm -Rf /tmp/extract
|
2020-05-01 16:19:33 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
zfs_utils_url=$(search_package "zfs-utils" "$zfs_utils_version")
|
2020-05-05 22:45:57 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
print "Installing zfs-utils"
|
2020-05-05 22:45:57 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
pacman -U $zfs_utils_url --noconfirm
|
|
|
|
|
pacman -U $zfs_linux_package --noconfirm
|
2020-05-05 22:45:57 +02:00
|
|
|
|
|
|
|
|
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
|