mirror of
https://github.com/eoli3n/archiso-zfs.git
synced 2026-02-04 14:14:24 +01:00
fixed a return and some improvments
This commit is contained in:
parent
1e779d36aa
commit
52835c103e
97
init
97
init
|
|
@ -9,9 +9,68 @@ print () {
|
|||
echo -e "\n\033[1m> $1\033[0m\n"
|
||||
}
|
||||
|
||||
get_running_kernel_version () {
|
||||
# Returns running kernel version
|
||||
|
||||
# Get running kernel version
|
||||
kernel_version=$(LANG=C pacman -Qi linux | sed -n 's/^Version\s*: //p')
|
||||
|
||||
print "Current kernel version is $kernel_version"
|
||||
|
||||
return "$kernel_version"
|
||||
}
|
||||
|
||||
get_iso_build_date () {
|
||||
# Returns running kernel build date formated as 'YYYY/MM/DD'
|
||||
|
||||
# Get running kernel build date
|
||||
kernel_date=(date +%Y/%m/%d -d "$(LANG=C pacman -Qi linux |sed -n 's/^Install Date\s*: //p')")
|
||||
|
||||
return "$kernel_date"
|
||||
}
|
||||
|
||||
init_archzfs () {
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
init_archlinux_archive () {
|
||||
# $1 is date formated as 'YYYY/MM/DD'
|
||||
# Returns False if repo does not exists
|
||||
|
||||
# Set repo
|
||||
repo="Server=https://archive.archlinux.org/repos/$1/\$repo/os/\$arch"
|
||||
|
||||
# If repo exists, set it, if not, return False
|
||||
curl -s $repo && echo $repo > /etc/pacman.d/mirrorlist || return "False"
|
||||
return "True"
|
||||
|
||||
}
|
||||
|
||||
init_repositories () {
|
||||
# $1 is date formated as 'YYYY/MM/DD'
|
||||
init_archzfs
|
||||
init_archlinux_archive
|
||||
pacman -Sy
|
||||
}
|
||||
|
||||
|
||||
search_package () {
|
||||
# $1 is package name to search
|
||||
# $2 is version to match
|
||||
# It returns package url
|
||||
|
||||
# Set regex to match package
|
||||
regex='href="\K'"$1"'-[0-9].*?'"$2"'.*?(?!.+\.sig)x86_64[^\"]+'
|
||||
|
|
@ -19,7 +78,7 @@ search_package () {
|
|||
# \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
|
||||
# '"$2"' # 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
|
||||
|
|
@ -51,9 +110,9 @@ search_package () {
|
|||
done
|
||||
}
|
||||
|
||||
|
||||
download_package () {
|
||||
# $1 is package url to download in tmp
|
||||
# It returns downloaded file path
|
||||
|
||||
filename="${url##*/}"
|
||||
|
||||
|
|
@ -68,6 +127,8 @@ download_package () {
|
|||
return "$output"
|
||||
}
|
||||
|
||||
### Main
|
||||
|
||||
print "Testing if archiso is running"
|
||||
|
||||
grep archiso /proc/cmdline > /dev/null
|
||||
|
|
@ -76,33 +137,16 @@ print "Increasing cowspace to half of RAM"
|
|||
|
||||
mount -o remount,size=50% /run/archiso/cowspace
|
||||
|
||||
# Get running kernel version
|
||||
# Search kernel package
|
||||
# https://github.com/archzfs/archzfs/issues/337#issuecomment-624312576
|
||||
kernel_version=$(pacman -Qi linux | sed -n 's/^Version\s*: //p')
|
||||
kernel_version=$(get_running_kernel_version)
|
||||
kernel_version_fixed="${kernel_version//-/\.}"
|
||||
|
||||
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
|
||||
|
||||
print "Current kernel version is $kernel_version"
|
||||
|
||||
# Search kernel package
|
||||
|
||||
zfs_utils_package_url=$(search_package "zfs-linux" "$kernel_version_fixed")
|
||||
# Search zfs-linux package matching running kernel version
|
||||
zfs_linux_package_url=$(search_package "zfs-linux" "$kernel_version_fixed")
|
||||
|
||||
# If a package is found
|
||||
if [[ -n $zfs_utils_package_url ]]
|
||||
if [[ -n $zfs_linux_package_url ]]
|
||||
then
|
||||
|
||||
# Download package
|
||||
|
|
@ -110,14 +154,18 @@ then
|
|||
|
||||
print "Extracting $zfs_linux_package"
|
||||
|
||||
# Extract package
|
||||
tar xvf "$zfs_linux_package" -C /tmp/extract
|
||||
|
||||
print "Searching zfs-utils version required"
|
||||
|
||||
# Get zfs-utils dependency version
|
||||
zfs_utils_version=$(grep 'depend = zfs-utils' /tmp/extract/.PKGINFO | grep -o '[[:digit:]].*')
|
||||
|
||||
# Clean extracted dir
|
||||
rm -Rf /tmp/extract
|
||||
|
||||
# Search zfs-utils package matching zfs-linux package dependency
|
||||
zfs_utils_url=$(search_package "zfs-utils" "$zfs_utils_version")
|
||||
|
||||
if [[ -n $zfs_utils_url ]]
|
||||
|
|
@ -125,6 +173,7 @@ then
|
|||
|
||||
print "Installing zfs-utils"
|
||||
|
||||
# Install packages
|
||||
pacman -U "$zfs_utils_url" --noconfirm
|
||||
pacman -U "$zfs_linux_package" --noconfirm
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue