From 2bd5f16cc1dd9e277d5b568d19b053bbe9267acb Mon Sep 17 00:00:00 2001 From: Saverio Miroddi Date: Wed, 28 Apr 2021 15:38:59 +0200 Subject: [PATCH 1/4] Cosmetic: Move set_zfs_ppa_requirement forward In preparation for the next changes. --- install-zfs.sh | 82 +++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/install-zfs.sh b/install-zfs.sh index 3975cf7..c466cb4 100755 --- a/install-zfs.sh +++ b/install-zfs.sh @@ -476,46 +476,6 @@ If you think this is a bug, please open an issue on https://github.com/saveriomi print_variables v_suitable_disks } -# REQUIREMENT: it must be ensured that, for any distro, `apt update` is invoked at this step, as -# subsequent steps rely on it. -# -# There are three parameters: -# -# 1. the tools are preinstalled (ie. Ubuntu Desktop based); -# 2. the default repository supports ZFS 0.8 (ie. Ubuntu 20.04+ based); -# 3. the distro provides the precompiled ZFS module (i.e. Ubuntu based, not Debian) -# -# Fortunately, with Debian-specific logic isolated, we need conditionals based only on #2 - see -# install_host_packages() and install_host_packages_UbuntuServer(). -# -function set_zfs_ppa_requirement { - apt update - - local zfs_package_version - zfs_package_version=$(apt show zfsutils-linux 2> /dev/null | perl -ne 'print /^Version: (\d+\.\d+)/') - - # Test returns true if $zfs_package_version is blank. - # - if [[ ${ZFS_USE_PPA:-} == "1" ]] || dpkg --compare-versions "$zfs_package_version" lt 0.8; then - v_use_ppa=1 - fi -} - -function set_zfs_ppa_requirement_Debian { - # Only update apt; in this case, ZFS packages are handled in a specific way. - - apt update -} - -# Mint 20 has the CDROM repository enabled, but apt fails when updating due to it (or possibly due -# to it being incorrectly setup). -# -function set_zfs_ppa_requirement_Linuxmint { - perl -i -pe 's/^(deb cdrom)/# $1/' /etc/apt/sources.list - - invoke "set_zfs_ppa_requirement" -} - # By using a FIFO, we avoid having to hide statements like `echo $v_passphrase | zpoool create ...` # from the logs. # @@ -571,6 +531,46 @@ export ZFS_FREE_TAIL_SPACE=12 trap _exit_hook EXIT } +# REQUIREMENT: it must be ensured that, for any distro, `apt update` is invoked at this step, as +# subsequent steps rely on it. +# +# There are three parameters: +# +# 1. the tools are preinstalled (ie. Ubuntu Desktop based); +# 2. the default repository supports ZFS 0.8 (ie. Ubuntu 20.04+ based); +# 3. the distro provides the precompiled ZFS module (i.e. Ubuntu based, not Debian) +# +# Fortunately, with Debian-specific logic isolated, we need conditionals based only on #2 - see +# install_host_packages() and install_host_packages_UbuntuServer(). +# +function set_zfs_ppa_requirement { + apt update + + local zfs_package_version + zfs_package_version=$(apt show zfsutils-linux 2> /dev/null | perl -ne 'print /^Version: (\d+\.\d+)/') + + # Test returns true if $zfs_package_version is blank. + # + if [[ ${ZFS_USE_PPA:-} == "1" ]] || dpkg --compare-versions "$zfs_package_version" lt 0.8; then + v_use_ppa=1 + fi +} + +function set_zfs_ppa_requirement_Debian { + # Only update apt; in this case, ZFS packages are handled in a specific way. + + apt update +} + +# Mint 20 has the CDROM repository enabled, but apt fails when updating due to it (or possibly due +# to it being incorrectly setup). +# +function set_zfs_ppa_requirement_Linuxmint { + perl -i -pe 's/^(deb cdrom)/# $1/' /etc/apt/sources.list + + invoke "set_zfs_ppa_requirement" +} + # Whiptail's lack of multiline editing is quite painful. # function install_dialog_package { @@ -1511,9 +1511,9 @@ invoke "display_intro_banner" invoke "check_system_memory" invoke "save_disks_log" invoke "find_suitable_disks" -invoke "set_zfs_ppa_requirement" invoke "register_exit_hook" invoke "create_passphrase_named_pipe" +invoke "set_zfs_ppa_requirement" invoke "install_dialog_package" invoke "select_disks" From cca6b2bef9286ffb4227ee36be2cdff76eed073e Mon Sep 17 00:00:00 2001 From: Saverio Miroddi Date: Wed, 28 Apr 2021 15:41:57 +0200 Subject: [PATCH 2/4] Refactoring: Split apt index update into separate step --- install-zfs.sh | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/install-zfs.sh b/install-zfs.sh index c466cb4..0ef7d0c 100755 --- a/install-zfs.sh +++ b/install-zfs.sh @@ -531,6 +531,19 @@ export ZFS_FREE_TAIL_SPACE=12 trap _exit_hook EXIT } +function update_apt_index { + apt update +} + +# Mint 20 has the CDROM repository enabled, but apt fails when updating due to it (or possibly due +# to it being incorrectly setup). +# +function update_apt_index_Linuxmint { + perl -i -pe 's/^(deb cdrom)/# $1/' /etc/apt/sources.list + + invoke "update_apt_index" +} + # REQUIREMENT: it must be ensured that, for any distro, `apt update` is invoked at this step, as # subsequent steps rely on it. # @@ -544,8 +557,6 @@ export ZFS_FREE_TAIL_SPACE=12 # install_host_packages() and install_host_packages_UbuntuServer(). # function set_zfs_ppa_requirement { - apt update - local zfs_package_version zfs_package_version=$(apt show zfsutils-linux 2> /dev/null | perl -ne 'print /^Version: (\d+\.\d+)/') @@ -558,17 +569,7 @@ function set_zfs_ppa_requirement { function set_zfs_ppa_requirement_Debian { # Only update apt; in this case, ZFS packages are handled in a specific way. - - apt update -} - -# Mint 20 has the CDROM repository enabled, but apt fails when updating due to it (or possibly due -# to it being incorrectly setup). -# -function set_zfs_ppa_requirement_Linuxmint { - perl -i -pe 's/^(deb cdrom)/# $1/' /etc/apt/sources.list - - invoke "set_zfs_ppa_requirement" + : } # Whiptail's lack of multiline editing is quite painful. @@ -1513,6 +1514,7 @@ invoke "save_disks_log" invoke "find_suitable_disks" invoke "register_exit_hook" invoke "create_passphrase_named_pipe" +invoke "update_apt_index" invoke "set_zfs_ppa_requirement" invoke "install_dialog_package" From 84b3cbe9c0441e0fc2022256ce9bd0cf312e5aac Mon Sep 17 00:00:00 2001 From: Saverio Miroddi Date: Wed, 28 Apr 2021 15:55:11 +0200 Subject: [PATCH 3/4] Separate step "prepare_standard_repositories", and add universe repository --- install-zfs.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/install-zfs.sh b/install-zfs.sh index 0ef7d0c..9a7df72 100755 --- a/install-zfs.sh +++ b/install-zfs.sh @@ -531,22 +531,33 @@ export ZFS_FREE_TAIL_SPACE=12 trap _exit_hook EXIT } -function update_apt_index { - apt update +function prepare_standard_repositories { + # Make sure it's enabled. Ubuntu MATE has it, while the standard Ubuntu doesn't. + # The program exits with success if the repository is already enabled. + # + add-apt-repository --yes --no-update universe } # Mint 20 has the CDROM repository enabled, but apt fails when updating due to it (or possibly due # to it being incorrectly setup). # -function update_apt_index_Linuxmint { +function prepare_standard_repositories_Linuxmint { perl -i -pe 's/^(deb cdrom)/# $1/' /etc/apt/sources.list - invoke "update_apt_index" + # The universe repository may be already enabled, but it's more solid to ensure it. + # + invoke "prepare_standard_repositories" +} + +function prepare_standard_repositories_Debian { + # Debian doesn't require universe (for dialog). + : +} + +function update_apt_index { + apt update } -# REQUIREMENT: it must be ensured that, for any distro, `apt update` is invoked at this step, as -# subsequent steps rely on it. -# # There are three parameters: # # 1. the tools are preinstalled (ie. Ubuntu Desktop based); @@ -1514,6 +1525,7 @@ invoke "save_disks_log" invoke "find_suitable_disks" invoke "register_exit_hook" invoke "create_passphrase_named_pipe" +invoke "prepare_standard_repositories" invoke "update_apt_index" invoke "set_zfs_ppa_requirement" invoke "install_dialog_package" From 9adce4e14147b49ffc221c1279f6525168f6e977 Mon Sep 17 00:00:00 2001 From: Saverio Miroddi Date: Wed, 28 Apr 2021 15:56:14 +0200 Subject: [PATCH 4/4] Rename horrible function `set_zfs_ppa_requirement` --- install-zfs.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install-zfs.sh b/install-zfs.sh index 9a7df72..1eb928f 100755 --- a/install-zfs.sh +++ b/install-zfs.sh @@ -567,7 +567,7 @@ function update_apt_index { # Fortunately, with Debian-specific logic isolated, we need conditionals based only on #2 - see # install_host_packages() and install_host_packages_UbuntuServer(). # -function set_zfs_ppa_requirement { +function set_use_zfs_ppa { local zfs_package_version zfs_package_version=$(apt show zfsutils-linux 2> /dev/null | perl -ne 'print /^Version: (\d+\.\d+)/') @@ -578,7 +578,7 @@ function set_zfs_ppa_requirement { fi } -function set_zfs_ppa_requirement_Debian { +function set_use_zfs_ppa_Debian { # Only update apt; in this case, ZFS packages are handled in a specific way. : } @@ -1527,7 +1527,7 @@ invoke "register_exit_hook" invoke "create_passphrase_named_pipe" invoke "prepare_standard_repositories" invoke "update_apt_index" -invoke "set_zfs_ppa_requirement" +invoke "set_use_zfs_ppa" invoke "install_dialog_package" invoke "select_disks"