updated with functions and zfs utils dependency install

This commit is contained in:
eoli3n 2020-05-06 10:17:46 +02:00
parent 0de5e28935
commit 4cbc94c34b

120
init
View file

@ -3,10 +3,71 @@
# github.com/eoli3n
# Thanks to CalimeroTeknik on #archlinux-fr, FFY00 on #archlinux-projects, JohnDoe2 on #regex
### Functions
print () {
echo -e "\n\033[1m> $1\033[0m\n"
}
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"
}
print "Testing if archiso is running"
grep archiso /proc/cmdline > /dev/null
@ -36,51 +97,32 @@ pacman-key --lsign-key F75D9D76
print "Current kernel version is $kernel_version"
# Set regex to match package
regex='href="\Kzfs-linux-[0-9].*?'"$kernel_version_fixed"'.*?(?!.+\.sig)x86_64[^\"]+'
# href=" # match href="
# \K # don't return anything matched prior to this point
# zfs-linux-\d # find me zfs-linux-#
# .*? # match anything but newlines 0 or more times, as few times as possible (non-greedy)
# '"$kernel_version"' # match version and escape with 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
# Search kernel package
# 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"
# Break loop
break
fi
done
zfs_utils_package_url=$(search_package "zfs-linux" "$kernel_version_fixed")
# If a package is found
if [[ ! -z $package ]]
if [[ ! -z $zfs_utils_package_url ]]
then
# Build package url
package_url="$url$package"
print "Installing package $package..."
# Download package
zfs_linux_package=$(download_package "zfs-linux" "$kernel_version_fixed")
# Install package
pacman -U "$package_url"
print "Extracting $zfs_linux_package"
tar xvf $zfs_linux_package -C /tmp/extract
print "Searching zfs-utils version required"
zfs_utils_version=$(cat /tmp/extract/.PKGINFO | grep 'depend = zfs-utils' | grep -o '[[:digit:]].*')
rm -Rf /tmp/extract
zfs_utils_url=$(search_package "zfs-utils" "$zfs_utils_version")
print "Installing zfs-utils"
pacman -U $zfs_utils_url --noconfirm
pacman -U $zfs_linux_package --noconfirm
print "Loading zfs kernel module"