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 12:51:53 +02:00
|
|
|
set -e
|
|
|
|
|
|
2022-02-16 10:57:37 +01:00
|
|
|
exec &> >(tee "debug.log")
|
|
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
### Functions
|
|
|
|
|
|
2020-05-01 16:19:33 +02:00
|
|
|
print () {
|
2020-05-06 12:55:53 +02:00
|
|
|
echo -e "\n\033[1m> $1\033[0m"
|
2020-05-01 16:19:33 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-06 10:49:19 +02:00
|
|
|
get_running_kernel_version () {
|
|
|
|
|
# Returns running kernel version
|
|
|
|
|
|
|
|
|
|
# Get running kernel version
|
2020-08-19 20:31:52 +02:00
|
|
|
kernel_version=$(uname -r)
|
2020-05-06 10:49:19 +02:00
|
|
|
|
|
|
|
|
print "Current kernel version is $kernel_version"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_iso_build_date () {
|
|
|
|
|
# Returns running kernel build date formated as 'YYYY/MM/DD'
|
|
|
|
|
|
|
|
|
|
# Get running kernel build date
|
2020-05-06 11:21:39 +02:00
|
|
|
kernel_date=$(date +%Y/%m/%d -d "$(LANG=C pacman -Qi linux |sed -n 's/^Install Date\s*: //p')")
|
2020-05-06 10:49:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_archzfs () {
|
2021-01-13 15:29:43 +01:00
|
|
|
if pacman -Sl archzfs >/dev/null 2>&1; then
|
|
|
|
|
print "archzfs repo was already added"
|
|
|
|
|
return
|
|
|
|
|
fi
|
2020-05-06 10:49:19 +02:00
|
|
|
print "Adding archzfs repo"
|
|
|
|
|
|
2020-05-15 10:54:08 +02:00
|
|
|
pacman -Sy archlinux-keyring --noconfirm &>/dev/null
|
|
|
|
|
pacman-key --populate archlinux &>/dev/null
|
2020-11-03 19:30:17 +01:00
|
|
|
pacman-key --recv-keys F75D9D76 --keyserver keyserver.ubuntu.com &>/dev/null
|
2020-05-15 10:54:08 +02:00
|
|
|
pacman-key --lsign-key F75D9D76 &>/dev/null
|
2020-05-06 10:49:19 +02:00
|
|
|
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
|
2020-08-20 10:03:04 +02:00
|
|
|
pacman -Sy &>/dev/null
|
2020-05-06 10:49:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_archlinux_archive () {
|
|
|
|
|
# $1 is date formated as 'YYYY/MM/DD'
|
|
|
|
|
# Returns False if repo does not exists
|
|
|
|
|
|
2022-02-16 10:53:29 +01:00
|
|
|
# Archlinux Archive workaround for 2022/02/01
|
|
|
|
|
if [[ "$1" == "2022/02/01" ]]
|
|
|
|
|
then
|
|
|
|
|
version="2022/02/02"
|
|
|
|
|
else
|
|
|
|
|
version="$1"
|
|
|
|
|
fi
|
|
|
|
|
|
2020-05-06 10:49:19 +02:00
|
|
|
# Set repo
|
2022-02-16 10:53:29 +01:00
|
|
|
repo="https://archive.archlinux.org/repos/$version/"
|
2020-05-06 10:49:19 +02:00
|
|
|
|
2020-05-06 13:20:33 +02:00
|
|
|
# If repo exists, set it
|
2022-02-16 10:33:38 +01:00
|
|
|
curl -s "$repo" &>/dev/null && echo "Server=$repo\$repo/os/\$arch" > /etc/pacman.d/mirrorlist
|
2020-05-06 10:49:19 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2020-05-06 12:34:39 +02:00
|
|
|
local regex='href="\K(?![^"]*\.sig)'"$1"'-(?=\d)[^"]*'"$2"'[^"]*x86_64[^"]*'
|
2020-05-06 10:17:46 +02:00
|
|
|
# href=" # match href="
|
|
|
|
|
# \K # don't return anything matched prior to this point
|
2020-05-06 12:34:39 +02:00
|
|
|
# (?![^"]*\.sig) # remove .sig matches
|
|
|
|
|
# '"$1"'-(?=\d) # find me '$package-' escaped by shell and ensure that after "-" is a digit
|
|
|
|
|
# [^"]* # match anything between '"'
|
2020-05-06 10:49:19 +02:00
|
|
|
# '"$2"' # match version escaped by shell
|
2020-05-06 12:34:39 +02:00
|
|
|
# [^"]* # match anything between '"'
|
2020-05-06 10:17:46 +02:00
|
|
|
# x86_64 # now match architecture
|
2020-05-06 12:34:39 +02:00
|
|
|
# [^"]* # match anything between '"'
|
2020-05-06 10:17:46 +02:00
|
|
|
|
|
|
|
|
# Set archzfs URLs list
|
2020-05-06 11:11:21 +02:00
|
|
|
local urls="http://archzfs.com/archzfs/x86_64/ http://archzfs.com/archive_archzfs/"
|
2020-05-06 10:17:46 +02:00
|
|
|
|
|
|
|
|
# Loop search
|
|
|
|
|
for url in $urls
|
|
|
|
|
do
|
|
|
|
|
|
2020-05-06 14:21:15 +02:00
|
|
|
print "Searching $1 on $url..."
|
2020-05-06 10:17:46 +02:00
|
|
|
|
|
|
|
|
# Query url and try to match package
|
2020-05-06 11:11:21 +02:00
|
|
|
local package=$(curl -s "$url" | grep -Po "$regex" | tail -n 1)
|
2020-05-06 10:17:46 +02:00
|
|
|
|
|
|
|
|
# If a package is found
|
2020-05-06 10:26:44 +02:00
|
|
|
if [[ -n $package ]]
|
2020-05-06 10:17:46 +02:00
|
|
|
then
|
|
|
|
|
|
2020-05-06 12:59:13 +02:00
|
|
|
print "Package \"$package\" found"
|
2020-05-06 10:17:46 +02:00
|
|
|
|
|
|
|
|
# Build package url
|
|
|
|
|
package_url="$url$package"
|
2020-05-06 11:48:34 +02:00
|
|
|
|
|
|
|
|
# Break loop
|
|
|
|
|
break
|
2020-05-06 10:17:46 +02:00
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
download_package () {
|
|
|
|
|
# $1 is package url to download in tmp
|
2020-05-06 10:49:19 +02:00
|
|
|
# It returns downloaded file path
|
2020-05-06 10:17:46 +02:00
|
|
|
|
2020-05-06 11:24:39 +02:00
|
|
|
local filename="${1##*/}"
|
2020-05-06 10:17:46 +02:00
|
|
|
|
|
|
|
|
# Download package in tmp
|
2020-07-23 12:48:04 +02:00
|
|
|
cd /tmp
|
|
|
|
|
curl -sO "$1"
|
|
|
|
|
cd -
|
2020-05-06 10:17:46 +02:00
|
|
|
|
|
|
|
|
# Set out file
|
2020-05-06 11:11:21 +02:00
|
|
|
package_file="/tmp/$filename"
|
2020-05-06 10:17:46 +02:00
|
|
|
|
2020-05-06 11:38:22 +02:00
|
|
|
print "Downloading to $package_file ..."
|
2020-05-06 10:17:46 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-15 15:20:08 +01:00
|
|
|
dkms_init () {
|
2022-02-16 13:15:45 +01:00
|
|
|
# Init everything to be able to install zfs-dkms
|
2022-02-15 15:14:30 +01:00
|
|
|
|
2022-02-16 10:30:16 +01:00
|
|
|
print "Init Archlinux Archive repository"
|
|
|
|
|
archiso_version=$(sed 's-\.-/-g' /version)
|
|
|
|
|
init_archlinux_archive "$archiso_version"
|
2022-02-15 22:43:39 +01:00
|
|
|
|
2022-02-16 10:21:14 +01:00
|
|
|
print "Download Archlinux Archives package lists and upgrade"
|
2022-02-15 22:48:32 +01:00
|
|
|
pacman -Syyuu --noconfirm
|
2022-02-16 10:21:14 +01:00
|
|
|
|
|
|
|
|
print "Install base-devel"
|
2022-02-16 11:27:24 +01:00
|
|
|
pacman -S --noconfirm base-devel linux-headers
|
2022-02-15 15:14:30 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 10:49:19 +02:00
|
|
|
### Main
|
|
|
|
|
|
2020-05-01 18:34:14 +02:00
|
|
|
print "Testing if archiso is running"
|
2020-05-01 16:19:33 +02:00
|
|
|
|
2021-09-12 17:24:48 +02:00
|
|
|
grep 'arch.*iso' /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
|
|
|
|
|
|
2020-05-06 10:53:38 +02:00
|
|
|
# Init archzfs repository
|
|
|
|
|
init_archzfs
|
|
|
|
|
|
2020-05-06 10:49:19 +02:00
|
|
|
# Search kernel package
|
2020-05-05 23:33:32 +02:00
|
|
|
# https://github.com/archzfs/archzfs/issues/337#issuecomment-624312576
|
2020-05-06 11:21:39 +02:00
|
|
|
get_running_kernel_version
|
2020-05-06 10:26:44 +02:00
|
|
|
kernel_version_fixed="${kernel_version//-/\.}"
|
2022-02-15 15:14:30 +01:00
|
|
|
kernel_version_fixed_for_headers="${kernel_version/-/\.}"
|
2020-05-01 16:19:33 +02:00
|
|
|
|
2020-05-06 10:49:19 +02:00
|
|
|
# Search zfs-linux package matching running kernel version
|
2020-05-06 11:11:21 +02:00
|
|
|
search_package "zfs-linux" "$kernel_version_fixed"
|
2020-05-06 11:45:11 +02:00
|
|
|
zfs_linux_url="$package_url"
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
# If a package is found
|
2020-05-06 11:45:11 +02:00
|
|
|
if [[ -n $zfs_linux_url ]]
|
2020-05-06 10:17:46 +02:00
|
|
|
then
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 10:17:46 +02:00
|
|
|
# Download package
|
2020-05-06 11:45:11 +02:00
|
|
|
download_package $zfs_linux_url
|
|
|
|
|
zfs_linux_package="$package_file"
|
2020-05-05 22:45:57 +02:00
|
|
|
|
2020-05-06 13:39:58 +02:00
|
|
|
print "Extracting zfs-utils version from zfs-linux PKGINFO"
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 13:41:15 +02:00
|
|
|
# Extract zfs-utils version from zfs-linux PKGINFO
|
2020-05-06 13:39:58 +02:00
|
|
|
zfs_utils_version=$(bsdtar -qxO -f "$zfs_linux_package" .PKGINFO | grep -Po 'depend = zfs-utils=\K.*')
|
2020-05-05 22:25:47 +02:00
|
|
|
|
2020-05-06 10:49:19 +02:00
|
|
|
# Search zfs-utils package matching zfs-linux package dependency
|
2020-05-06 11:11:21 +02:00
|
|
|
search_package "zfs-utils" "$zfs_utils_version"
|
2020-05-06 11:45:11 +02:00
|
|
|
zfs_utils_url="$package_url"
|
2020-05-05 22:45:57 +02:00
|
|
|
|
2020-05-06 11:45:11 +02:00
|
|
|
if [[ -n $zfs_utils_url ]]
|
2020-05-06 10:26:44 +02:00
|
|
|
then
|
2020-05-05 22:45:57 +02:00
|
|
|
|
2020-05-06 12:55:28 +02:00
|
|
|
print "Installing zfs-utils and zfs-linux"
|
2020-05-05 22:45:57 +02:00
|
|
|
|
2020-05-06 12:44:14 +02:00
|
|
|
# Install packages
|
2020-08-20 10:03:04 +02:00
|
|
|
pacman -U "$zfs_utils_url" --noconfirm &>/dev/null
|
|
|
|
|
pacman -U "$zfs_linux_package" --noconfirm &>/dev/null && zfs=1
|
2020-05-06 10:26:44 +02:00
|
|
|
fi
|
2022-02-15 15:14:30 +01:00
|
|
|
else
|
|
|
|
|
|
|
|
|
|
# DKMS fallback
|
|
|
|
|
print "No zfs-linux package was found for current running kernel, fallback on DKMS method"
|
2022-02-16 11:27:24 +01:00
|
|
|
dkms_init
|
2022-02-15 15:20:08 +01:00
|
|
|
|
|
|
|
|
print "Install zfs-dkms"
|
|
|
|
|
|
|
|
|
|
# Install package
|
|
|
|
|
pacman -S zfs-dkms --noconfirm && zfs=1
|
2022-02-15 15:14:30 +01:00
|
|
|
|
2020-05-06 11:41:46 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Load kernel module
|
|
|
|
|
if [[ "$zfs" == "1" ]]
|
|
|
|
|
then
|
|
|
|
|
|
2020-05-06 13:00:20 +02:00
|
|
|
modprobe zfs && echo -e "\n\e[32mZFS is ready\n"
|
2020-05-06 11:41:46 +02:00
|
|
|
|
2020-05-05 22:45:57 +02:00
|
|
|
else
|
2020-05-06 11:41:46 +02:00
|
|
|
print "No ZFS module found"
|
2020-05-05 22:45:57 +02:00
|
|
|
fi
|