diff --git a/conf.sh b/conf.sh index ac8a2d8..96e9bae 100644 --- a/conf.sh +++ b/conf.sh @@ -1,3 +1,6 @@ +# ZFSonLinux stable version (LTS packages) +AZB_ZOL_VERSION="0.6.2" + # Kernel version for GIT packages AZB_GIT_PKGREL="1" AZB_GIT_KERNEL_VERSION="3.14.1" @@ -28,9 +31,6 @@ AZB_KERNEL_ARCHISO_PKGREL="1" # AZB_KERNEL_TEST_PKG_VERSION="${AZB_ZOL_VERSION}_${AZB_KERNEL_TEST_VERSION}" # AZB_KERNEL_TEST_FULL_VERSION="${AZB_KERNEL_TEST_PKG_VERSION}-${AZB_GIT_PKGREL}" -# ZFSonLinux stable version (LTS packages) -AZB_ZOL_VERSION="0.6.2" - # The paths to the ZOL git repos AZB_ZFS_GIT_PATH="/home/demizer/src/c/zfs" AZB_SPL_GIT_PATH="/home/demizer/src/c/spl" diff --git a/lib.sh b/lib.sh index a839460..3a646ee 100644 --- a/lib.sh +++ b/lib.sh @@ -129,15 +129,24 @@ full_kernel_git_version() { [[ ${AZB_GIT_KERNEL_VERSION} =~ ^[[:digit:]]+\.[[:digit:]]+\.([[:digit:]]+) ]] if [[ ${BASH_REMATCH[1]} != "" ]]; then AZB_GIT_KERNEL_X32_VERSION_FULL=${AZB_GIT_KERNEL_X32_VERSION} - AZB_GIT_KERNEL_X32_VERSION_CLEAN=$(echo ${AZB_GIT_KERNEL_X32_VERSION} | sed s/-/_/g) AZB_GIT_KERNEL_X64_VERSION_FULL=${AZB_GIT_KERNEL_X64_VERSION} - AZB_GIT_KERNEL_X64_VERSION_CLEAN=$(echo ${AZB_GIT_KERNEL_X64_VERSION} | sed s/-/_/g) else # Kernel version has the format 3.14, so add a 0. AZB_GIT_KERNEL_X32_VERSION_FULL=${AZB_GIT_KERNEL_VERSION}.0-${AZB_GIT_KERNEL_X32_PKGREL} - AZB_GIT_KERNEL_X32_VERSION_CLEAN=${AZB_GIT_KERNEL_VERSION}.0_${AZB_GIT_KERNEL_X32_PKGREL} AZB_GIT_KERNEL_X64_VERSION_FULL=${AZB_GIT_KERNEL_VERSION}.0-${AZB_GIT_KERNEL_X64_PKGREL} - AZB_GIT_KERNEL_X64_VERSION_CLEAN=${AZB_GIT_KERNEL_VERSION}.0_${AZB_GIT_KERNEL_X64_PKGREL} + fi +} + +full_kernel_lts_version() { + # Determine if the kernel version has the format 3.14 or 3.14.1 + [[ ${AZB_LTS_KERNEL_VERSION} =~ ^[[:digit:]]+\.[[:digit:]]+\.([[:digit:]]+) ]] + if [[ ${BASH_REMATCH[1]} != "" ]]; then + AZB_LTS_KERNEL_X32_VERSION_FULL=${AZB_LTS_KERNEL_X32_VERSION} + AZB_LTS_KERNEL_X64_VERSION_FULL=${AZB_LTS_KERNEL_X64_VERSION} + else + # Kernel version has the format 3.14, so add a 0. + AZB_LTS_KERNEL_X32_VERSION_FULL=${AZB_LTS_KERNEL_VERSION}.0-${AZB_LTS_KERNEL_X32_PKGREL} + AZB_LTS_KERNEL_X64_VERSION_FULL=${AZB_LTS_KERNEL_VERSION}.0-${AZB_LTS_KERNEL_X64_PKGREL} fi } diff --git a/spl-lts/PKGBUILD b/spl-lts/PKGBUILD index a48957e..b2e7031 100644 --- a/spl-lts/PKGBUILD +++ b/spl-lts/PKGBUILD @@ -1,67 +1,66 @@ # Maintainer: Jesus Alvarez # Contributor: Kyle Fuller - -pkgname="spl-git" -pkgver=0.6.2_3.14 +# +# This PKGBUILD was generated by the archzfs build scripts located at +# +# http://github.com/demizer/archzfs +# +# The build script generates and updates the pkgver and _kernel* variables. +# +pkgname="spl-lts" +pkgver=0.6.2_3.10.37 pkgrel=1 # Used incase the i686 and x86_64 linux packages get out of sync with the # PKGREL. This occurred on January 31, 2014 where i686 was versioned at # 3.12.9-1 and x86_64 was versioned at 3.12.9-2. -_kernel_version_x32="3.14-4" -_kernel_version_x64="3.14-4" - -[[ $CARCH == "i686" ]] && _kernel_version=$_kernel_version_x32 || - _kernel_version=$_kernel_version_x64 +_kernel_version_x32="3.10.37-1" +_kernel_version_x32_full="3.10.37-1" +_kernel_version_x64="3.10.37-1" +_kernel_version_x64_full="3.10.37-1" -# If _kernel_version does not have a minor version, we need to add "0" as the -# minor version for the kernel module path. Kernel modules for linux versions -# with no minor version (i.e. 3.14) are kept in /usr/lib/modules/3.14.0-4-ARCH -[[ $_kernel_version =~ ^[:digit:]+\.[:digit:]+\.([:digit:]+)\-[:digit:]+ ]] -if [[ ${BASH_REMATCH[1]} == "" ]]; then - [[ $_kernel_version =~ ^([[:digit:]\.]+)\-([[:digit:]]+) ]] && - _kernel_version_base=${BASH_REMATCH[1]}; - _kernel_version_pkgrel=${BASH_REMATCH[2]} - _kernel_version=${_kernel_version_base}.0-${_kernel_version_pkgrel} +if [[ $CARCH == "i686" ]]; then + _kernel_version=${_kernel_version_x32} + _kernel_version_full=${_kernel_version_x32_full} +else + _kernel_version=${_kernel_version_x64} + _kernel_version_full=${_kernel_version_x64_full} fi pkgdesc="Solaris Porting Layer kernel modules." -depends=("spl-utils-git" "linux=$LINUX_VERSION") -makedepends=("git", "linux-headers=$LINUX_VERSION") +depends=("spl-utils-lts" "linux-lts=${_kernel_version}") +makedepends=("linux-headers-lts=${_kernel_version}") arch=("i686" "x86_64") url="http://zfsonlinux.org/" -source=("git+https://github.com/zfsonlinux/zfs.git") -groups=("archzfs") -md5sums=('SKIP') +source=("http://archive.zfsonlinux.org/downloads/zfsonlinux/spl/spl-0.6.2.tar.gz") +groups=("archzfs-lts") +md5sums=('f00535bf89a7fde0e08f44a14a1f1e03') license=("GPL") install=spl.install provides=("spl") -conflicts=("spl") - -pkgver() { - cd "${srcdir}/spl" - # cutting off 'spl-' prefix that presents in the git tag - echo $(git describe --long | \ - sed -r 's/^spl-//;s/([^-]*-g)/r\1/;s/-/./g')_${_kernver} -} +conflicts=("spl" "spl-git") build() { - cd "$srcdir/spl" + cd "${srcdir}/spl-0.6.2" ./autogen.sh _at_enable="" [ "${CARCH}" == "i686" ] && _at_enable="--enable-atomic-spinlocks" - ./configure --prefix=/usr --libdir=/usr/lib --sbindir=/usr/bin \ - --with-linux=/usr/lib/modules/$MOD_BASENAME/build \ - --with-config=kernel ${_at_enable} + ./configure --prefix=/usr \ + --libdir=/usr/lib \ + --sbindir=/usr/bin \ + --with-linux=/usr/lib/modules/${_kernel_version_full}-ARCH/build \ + --with-config=kernel \ + ${_at_enable} + make } package() { - cd "${srcdir}/spl" + cd "${srcdir}/spl-0.6.2" make DESTDIR="${pkgdir}" install mv "${pkgdir}/lib" "${pkgdir}/usr/" - sed -i "s+${srcdir}++" ${pkgdir}/usr/src/spl-*/${_kernfullpkgver}-ARCH/Module.symvers + sed -i "s+${srcdir}++" ${pkgdir}/usr/src/spl-*/${_kernel_version_full}-ARCH/Module.symvers } diff --git a/spl-utils-lts/PKGBUILD b/spl-utils-lts/PKGBUILD index a225f08..17e777a 100644 --- a/spl-utils-lts/PKGBUILD +++ b/spl-utils-lts/PKGBUILD @@ -1,45 +1,46 @@ # Maintainer: Jesus Alvarez # Contributor: Kyle Fuller - -pkgname="spl-utils-git" # -# This script doesn't use bash variables for the version number because AUR -# doesn't properly parse bash variables. We use a custom build script to -# automatically change the appropriate variables before building in a clean -# chroot environment (using systemd-ndspawn). +# This PKGBUILD was generated by the archzfs build scripts located at +# +# http://github.com/demizer/archzfs # -# The build script can be found at -# https://github.com/demizer/archzfs/blob/master/build.sh +# The build script generates and updates the pkgver and _kernel* variables. # -pkgver= +pkgname="spl-utils-lts" +pkgver=0.6.2_3.10.37 pkgrel=1 pkgdesc="Solaris Porting Layer kernel module support files." arch=("i686" "x86_64") url="http://zfsonlinux.org/" -source=("git+https://github.com/zfsonlinux/zfs.git" +source=("http://archive.zfsonlinux.org/downloads/zfsonlinux/spl/spl-0.6.2.tar.gz" "spl-utils.hostid") -groups=("archzfs") -md5sums=() +groups=("archzfs-lts") +md5sums=('f00535bf89a7fde0e08f44a14a1f1e03' + 'a54f0041a9e15b050f25c463f1db7449') license=("GPL") provides=("spl-utils") -conflicts=("spl-utils") +conflicts=("spl-utils" "spl-utils-git") build() { - cd "$srcdir/spl" - ./autogen.sh - if [[ $CARCH == "i686" ]]; then - ./configure --prefix=/usr --libdir=/usr/lib --sbindir=/usr/bin \ - --with-config=user - else - ./configure --prefix=/usr --libdir=/usr/lib --sbindir=/usr/bin \ - --with-config=user - fi - make + cd "${srcdir}/spl-0.6.2" + ./autogen.sh + + _at_enable="" + [ "${CARCH}" == "i686" ] && _at_enable="--enable-atomic-spinlocks" + + ./configure --prefix=/usr \ + --libdir=/usr/lib \ + --sbindir=/usr/bin \ + --with-config=user \ + ${_at_enable} + + make } package() { - cd "$srcdir/spl" - make DESTDIR="$pkgdir" install + cd "${srcdir}/spl-0.6.2" + make DESTDIR="${pkgdir}" install - install -D -m644 "$srcdir"/spl-utils.hostid "$pkgdir"/etc/hostid + install -D -m644 "${srcdir}"/spl-utils.hostid "${pkgdir}"/etc/hostid } diff --git a/zfs-lts/PKGBUILD b/zfs-lts/PKGBUILD index b414131..33eb2e0 100644 --- a/zfs-lts/PKGBUILD +++ b/zfs-lts/PKGBUILD @@ -1,64 +1,50 @@ # Maintainer: Jesus Alvarez # Contributor: Kyle Fuller # See http://github.com/demizer/archzfs for build scripts. - -pkgname="zfs-git" -pkgver=0.6.2_3.14 -pkgrel=2 +# +# This PKGBUILD was generated by the archzfs build scripts located at +# +# http://github.com/demizer/archzfs +# +# The build script generates and updates the pkgver and _kernel* variables. +# +pkgname="zfs-lts" +pkgver=0.6.2_3.10.37 +pkgrel=1 # Used incase the i686 and x86_64 linux packages get out of sync with the # PKGREL. This occurred on January 31, 2014 where i686 was versioned at # 3.12.9-1 and x86_64 was versioned at 3.12.9-2. -_kernel_version_x32="3.14-4" -_kernel_version_x64="3.14-4" - -[[ $CARCH == "i686" ]] && _kernel_version=$_kernel_version_x32 || - _kernel_version=$_kernel_version_x64 +_kernel_version_x32="3.10.37-1" +_kernel_version_x32_full="3.10.37-1" +_kernel_version_x64="3.10.37-1" +_kernel_version_x64_full="3.10.37-1" -# If _kernel_version does not have a minor version, we need to add "0" as the -# minor version for the kernel module path. Kernel modules for linux versions -# with no minor version (i.e. 3.14) are kept in /usr/lib/modules/3.14.0-4-ARCH -[[ $_kernel_version =~ ^[:digit:]+\.[:digit:]+\.([:digit:]+)\-[:digit:]+ ]] -if [[ ${BASH_REMATCH[1]} == "" ]]; then - [[ $_kernel_version =~ ^([[:digit:]\.]+)\-([[:digit:]]+) ]] && - _kernel_version_base=${BASH_REMATCH[1]}; - _kernel_version_pkgrel=${BASH_REMATCH[2]} - _kernel_version=${_kernel_version_base}.0-${_kernel_version_pkgrel} +if [[ $CARCH == "i686" ]]; then + _kernel_version=${_kernel_version_x32} + _kernel_version_full=${_kernel_version_x32_full} +else + _kernel_version=${_kernel_version_x64} + _kernel_version_full=${_kernel_version_x64_full} fi pkgdesc="Kernel modules for the Zettabyte File System." -depends=("spl=0.6.2_3.14-2" "zfs-utils" "linux=$LINUX_VERSION") -makedepends=("linux-headers=$LINUX_VERSION") +depends=("spl-lts" "zfs-utils-lts" "linux-lts=${_kernel_version}") +makedepends=("linux-headers-lts=${_kernel_version}") arch=("i686" "x86_64") url="http://zfsonlinux.org/" -source=(http://archive.zfsonlinux.org/downloads/zfsonlinux/zfs/zfs-0.6.2.tar.gz - http://demizerone.com/patches/20140411-zfs-git-master.patch) -groups=("archzfs") -md5sums=('0b183b0abdd5be287046ad9ce4f899fd' - 'b7632a5a80d474272d1de046b6da5f81') +source=("http://archive.zfsonlinux.org/downloads/zfsonlinux/zfs/zfs-0.6.2.tar.gz") +groups=("archzfs-lts") +md5sums=('0b183b0abdd5be287046ad9ce4f899fd') license=("CDDL") install=zfs.install - -prepare() { - cd "$srcdir/zfs-0.6.2" - patch -Np1 < ../20140411-zfs-git-master.patch -} +provides=("zfs") +conflicts=("zfs" "zfs-git") build() { - cd "$srcdir/zfs-0.6.2" - ./autogen.sh - if [[ $CARCH == "i686" ]]; then - ./configure --prefix=/usr \ - --sysconfdir=/etc \ - --sbindir=/usr/bin \ - --libdir=/usr/lib \ - --datadir=/usr/share \ - --includedir=/usr/include \ - --with-udevdir=/lib/udev \ - --libexecdir=/usr/lib/zfs-0.6.2 \ - --with-config=kernel \ - --with-linux=/usr/lib/modules/$MOD_BASENAME/build - else + cd "${srcdir}/zfs-0.6.2" + ./autogen.sh + ./configure --prefix=/usr \ --sysconfdir=/etc \ --sbindir=/usr/bin \ @@ -68,16 +54,17 @@ build() { --with-udevdir=/lib/udev \ --libexecdir=/usr/lib/zfs-0.6.2 \ --with-config=kernel \ - --with-linux=/usr/lib/modules/$MOD_BASENAME/build - fi - make + --with-linux=/usr/lib/modules/${_kernel_version_full}-ARCH/build + + make } package() { - cd "$srcdir/zfs-0.6.2" - make DESTDIR="$pkgdir" install + cd "${srcdir}/zfs-0.6.2" + make DESTDIR="${pkgdir}" install + + cp -r "$pkgdir"/{lib,usr} + rm -r "$pkgdir"/lib - # move module tree /lib -> /usr/lib - cp -r "$pkgdir"/{lib,usr} - rm -r "$pkgdir"/lib + sed -i "s+${srcdir}++" ${pkgdir}/usr/src/zfs-*/${_kernel_version_full}-ARCH/Module.symvers } diff --git a/zfs-utils-lts/PKGBUILD b/zfs-utils-lts/PKGBUILD index 41de453..ccc45cd 100644 --- a/zfs-utils-lts/PKGBUILD +++ b/zfs-utils-lts/PKGBUILD @@ -1,58 +1,36 @@ # Maintainer: Jesus Alvarez # Contributor: Kyle Fuller - -pkgname="zfs-utils-git" - # -# This script doesn't use bash variables for the version number because AUR -# doesn't properly parse bash variables. We use a custom build script to -# automatically change the appropriate variables before building in a clean -# chroot environment (using systemd-ndspawn). +# This PKGBUILD was generated by the archzfs build scripts located at # -# The build script can be found at -# https://github.com/demizer/archzfs/blob/master/build.sh +# http://github.com/demizer/archzfs # - -pkgver=0.6.2_3.14 -pkgrel=2 +# The build script generates and updates the pkgver and _kernel* variables. +# +pkgname="zfs-utils-lts" +pkgver=0.6.2_3.10.37 +pkgrel=1 pkgdesc="Kernel module support files for the Zettabyte File System." -depends=("spl") +depends=("spl-lts") arch=("i686" "x86_64") url="http://zfsonlinux.org/" -source=(http://archive.zfsonlinux.org/downloads/zfsonlinux/zfs/zfs-0.6.2.tar.gz - zfs-utils.bash-completion - zfs-utils.initcpio.install - zfs-utils.initcpio.hook - zfs-utils.service - http://demizerone.com/patches/20140411-zfs-git-master.patch) -groups=("archzfs") +source=("http://archive.zfsonlinux.org/downloads/zfsonlinux/zfs/zfs-0.6.2.tar.gz" + "zfs-utils.bash-completion-r1" + "zfs-utils.initcpio.install" + "zfs-utils.initcpio.hook") md5sums=('0b183b0abdd5be287046ad9ce4f899fd' - '3e1c4a29c4f7d590e6a3041f2c61d6ff' + '9ddb0c8a94861f929d0fa741fdc49950' 'ebea2b1e593a9a19efa0f7ae7451bbc7' - 'b567a95a34759f196bf4be8061a895e5' - '1f16ea8592509edb8efa4d7da25f8182' - 'b7632a5a80d474272d1de046b6da5f81') + 'b567a95a34759f196bf4be8061a895e5') license=("CDDL") - -prepare() { - cd "$srcdir/zfs-0.6.2" - patch -Np1 < ../20140411-zfs-git-master.patch -} +groups=("archzfs-lts") +provides=("zfs-utils") +conflicts=("zfs-utils" "zfs-utils-git") build() { - cd "$srcdir/zfs-0.6.2" - ./autogen.sh - if [[ $CARCH == "i686" ]]; then - ./configure --prefix=/usr \ - --sysconfdir=/etc \ - --sbindir=/usr/bin \ - --libdir=/usr/lib \ - --datadir=/usr/share \ - --includedir=/usr/include \ - --with-udevdir=/lib/udev \ - --libexecdir=/usr/lib/zfs-0.6.2 \ - --with-config=user - else + cd "${srcdir}/zfs-0.6.2" + ./autogen.sh + ./configure --prefix=/usr \ --sysconfdir=/etc \ --sbindir=/usr/bin \ @@ -62,28 +40,26 @@ build() { --with-udevdir=/lib/udev \ --libexecdir=/usr/lib/zfs-0.6.2 \ --with-config=user - fi - make + make } package() { - cd "$srcdir/zfs-0.6.2" - make DESTDIR="$pkgdir" install + cd "${srcdir}/zfs-0.6.2" + make DESTDIR="${pkgdir}" install - # Remove uneeded files - rm -r "$pkgdir"/etc/init.d - rm -r "$pkgdir"/usr/lib/dracut + # Remove uneeded files + rm -r "${pkgdir}"/etc/init.d + rm -r "${pkgdir}"/usr/lib/dracut - # move module tree /lib -> /usr/lib - cp -r "$pkgdir"/{lib,usr} - rm -r "$pkgdir"/lib + # move module tree /lib -> /usr/lib + cp -r "${pkgdir}"/{lib,usr} + rm -r "${pkgdir}"/lib - # Fixup path - mv "$pkgdir"/sbin/mount.zfs "$pkgdir"/usr/bin/ - rm -r "$pkgdir"/sbin + # Fixup path + mv "${pkgdir}"/sbin/mount.zfs "${pkgdir}"/usr/bin/ + rm -r "${pkgdir}"/sbin - install -D -m644 "$srcdir"/zfs-utils.initcpio.hook "$pkgdir"/usr/lib/initcpio/hooks/zfs - install -D -m644 "$srcdir"/zfs-utils.initcpio.install "$pkgdir"/usr/lib/initcpio/install/zfs - install -D -m644 "$srcdir"/zfs-utils.service "$pkgdir"/usr/lib/systemd/system/zfs.service - install -D -m644 "$srcdir"/zfs-utils.bash-completion "$pkgdir"/usr/share/bash-completion/completions/zfs + install -D -m644 "${srcdir}"/zfs-utils.initcpio.hook "${pkgdir}"/usr/lib/initcpio/hooks/zfs + install -D -m644 "${srcdir}"/zfs-utils.initcpio.install "${pkgdir}"/usr/lib/initcpio/install/zfs + install -D -m644 "${srcdir}"/zfs-utils.bash-completion-r1 "${pkgdir}"/usr/share/bash-completion/completions/zfs } diff --git a/zfs-utils-lts/zfs-utils.bash-completion-r1 b/zfs-utils-lts/zfs-utils.bash-completion-r1 new file mode 100644 index 0000000..b1aded3 --- /dev/null +++ b/zfs-utils-lts/zfs-utils.bash-completion-r1 @@ -0,0 +1,391 @@ +# Copyright (c) 2013, Aneurin Price + +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: + +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +#if [[ -w /dev/zfs ]]; then + __ZFS_CMD="zfs" + __ZPOOL_CMD="zpool" +#else +# __ZFS_CMD="sudo zfs" +# __ZPOOL_CMD="sudo zpool" +#fi + +__zfs_get_commands() +{ + $__ZFS_CMD 2>&1 | awk '/^\t[a-z]/ {print $1}' | cut -f1 -d '|' | uniq +} + +__zfs_get_properties() +{ + $__ZFS_CMD get 2>&1 | awk '$2 == "YES" || $2 == "NO" {print $1}'; echo all name space +} + +__zfs_get_editable_properties() +{ + $__ZFS_CMD get 2>&1 | awk '$2 == "YES" {print $1"="}' +} + +__zfs_get_inheritable_properties() +{ + $__ZFS_CMD get 2>&1 | awk '$3 == "YES" {print $1}' +} + +__zfs_list_datasets() +{ + $__ZFS_CMD list -H -o name -t filesystem,volume +} + +__zfs_list_filesystems() +{ + $__ZFS_CMD list -H -o name -t filesystem +} + +__zfs_match_snapshot() +{ + local base_dataset=${cur%@*} + if [[ $base_dataset != $cur ]] + then + $__ZFS_CMD list -H -o name -t snapshot -d 1 $base_dataset + else + $__ZFS_CMD list -H -o name -t filesystem,volume | awk '{print $1"@"}' + fi +} + +__zfs_match_explicit_snapshot() +{ + local base_dataset=${cur%@*} + if [[ $base_dataset != $cur ]] + then + $__ZFS_CMD list -H -o name -t snapshot -d 1 $base_dataset + fi +} + +__zfs_match_multiple_snapshots() +{ + local existing_opts=$(expr "$cur" : '\(.*\)[%,]') + if [[ $existing_opts ]] + then + local base_dataset=${cur%@*} + if [[ $base_dataset != $cur ]] + then + local cur=${cur##*,} + if [[ $cur =~ ^%|%.*% ]] + then + # correct range syntax is start%end + return 1 + fi + local range_start=$(expr "$cur" : '\(.*%\)') + $__ZFS_CMD list -H -o name -t snapshot -d 1 $base_dataset | sed 's$.*@$'$range_start'$g' + fi + else + __zfs_match_explicit_snapshot; __zfs_list_datasets + fi +} + +__zfs_list_volumes() +{ + $__ZFS_CMD list -H -o name -t volume +} + +__zfs_argument_chosen() +{ + local word property + for word in $(seq $((COMP_CWORD-1)) -1 2) + do + local prev="${COMP_WORDS[$word]}" + if [[ ${COMP_WORDS[$word-1]} != -[tos] ]] + then + if [[ "$prev" == [^,]*,* ]] || [[ "$prev" == *[@:]* ]] + then + return 0 + fi + for property in $@ + do + if [[ $prev == "$property" ]] + then + return 0 + fi + done + fi + done + return 1 +} + +__zfs_complete_ordered_arguments() +{ + local list1=$1 + local list2=$2 + local cur=$3 + local extra=$4 + if __zfs_argument_chosen $list1 + then + COMPREPLY=($(compgen -W "$list2 $extra" -- "$cur")) + else + COMPREPLY=($(compgen -W "$list1 $extra" -- "$cur")) + fi +} + +__zfs_complete_multiple_options() +{ + local options=$1 + local cur=$2 + + COMPREPLY=($(compgen -W "$options" -- "${cur##*,}")) + local existing_opts=$(expr "$cur" : '\(.*,\)') + if [[ $existing_opts ]] + then + COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" ) + fi +} + +__zfs_complete_switch() +{ + local options=$1 + if [[ ${cur:0:1} == - ]] + then + COMPREPLY=($(compgen -W "-{$options}" -- "$cur")) + return 0 + else + return 1 + fi +} + +__zfs_complete() +{ + local cur prev cmd cmds + COMPREPLY=() + # Don't split on colon + _get_comp_words_by_ref -n : -c cur -p prev -w COMP_WORDS -i COMP_CWORD + cmd="${COMP_WORDS[1]}" + + if [[ ${prev##*/} == zfs ]] + then + cmds=$(__zfs_get_commands) + COMPREPLY=($(compgen -W "$cmds -?" -- "$cur")) + return 0 + fi + + case "${cmd}" in + clone) + case "${prev}" in + -o) + COMPREPLY=($(compgen -W "$(__zfs_get_editable_properties)" -- "$cur")) + ;; + *) + if ! __zfs_complete_switch "o,p" + then + if __zfs_argument_chosen + then + COMPREPLY=($(compgen -W "$(__zfs_list_datasets)" -- "$cur")) + else + COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur")) + fi + fi + ;; + esac + ;; + get) + case "${prev}" in + -d) + COMPREPLY=($(compgen -W "" -- "$cur")) + ;; + -t) + __zfs_complete_multiple_options "filesystem volume snapshot all" "$cur" + ;; + -s) + __zfs_complete_multiple_options "local default inherited temporary none" "$cur" + ;; + -o) + __zfs_complete_multiple_options "name property value source received all" "$cur" + ;; + *) + if ! __zfs_complete_switch "H,r,p,d,o,t,s" + then + if __zfs_argument_chosen $(__zfs_get_properties) + then + COMPREPLY=($(compgen -W "$(__zfs_match_explicit_snapshot) $(__zfs_list_datasets)" -- "$cur")) + else + __zfs_complete_multiple_options "$(__zfs_get_properties)" "$cur" + fi + fi + ;; + esac + ;; + inherit) + if ! __zfs_complete_switch "r" + then + __zfs_complete_ordered_arguments "$(__zfs_get_inheritable_properties)" "$(__zfs_match_explicit_snapshot) $(__zfs_list_datasets)" $cur + fi + ;; + list) + case "${prev}" in + -d) + COMPREPLY=($(compgen -W "" -- "$cur")) + ;; + -t) + __zfs_complete_multiple_options "filesystem volume snapshot all" "$cur" + ;; + -o) + __zfs_complete_multiple_options "$(__zfs_get_properties)" "$cur" + ;; + -s|-S) + COMPREPLY=($(compgen -W "$(__zfs_get_properties)" -- "$cur")) + ;; + *) + if ! __zfs_complete_switch "H,r,d,o,t,s,S" + then + COMPREPLY=($(compgen -W "$(__zfs_match_explicit_snapshot) $(__zfs_list_datasets)" -- "$cur")) + fi + ;; + esac + ;; + promote) + COMPREPLY=($(compgen -W "$(__zfs_list_filesystems)" -- "$cur")) + ;; + rollback) + if ! __zfs_complete_switch "r,R,f" + then + COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur")) + fi + ;; + send) + if ! __zfs_complete_switch "d,n,P,p,R,v,i,I" + then + COMPREPLY=($(compgen -W "$(__zfs_match_snapshot)" -- "$cur")) + fi + ;; + snapshot) + case "${prev}" in + -o) + COMPREPLY=($(compgen -W "$(__zfs_get_editable_properties)" -- "$cur")) + ;; + *) + if ! __zfs_complete_switch "o,r" + then + COMPREPLY=($(compgen -W "$(__zfs_list_datasets | awk '{print $1"@"}')" -- "$cur")) + fi + ;; + esac + ;; + set) + __zfs_complete_ordered_arguments "$(__zfs_get_editable_properties)" "$(__zfs_match_explicit_snapshot) $(__zfs_list_datasets)" $cur + ;; + upgrade) + case "${prev}" in + -a|-V|-v) + COMPREPLY=($(compgen -W "" -- "$cur")) + ;; + *) + if ! __zfs_complete_switch "a,V,v,r" + then + COMPREPLY=($(compgen -W "$(__zfs_list_filesystems)" -- "$cur")) + fi + ;; + esac + ;; + destroy) + if ! __zfs_complete_switch "d,f,n,p,R,r,v" + then + __zfs_complete_multiple_options "$(__zfs_match_multiple_snapshots)" $cur + fi + ;; + *) + COMPREPLY=($(compgen -W "$(__zfs_match_explicit_snapshot) $(__zfs_list_datasets)" -- "$cur")) + ;; + esac + __ltrim_colon_completions "$cur" + return 0 +} + +__zpool_get_commands() +{ + $__ZPOOL_CMD 2>&1 | awk '/^\t[a-z]/ {print $1}' | uniq +} + +__zpool_get_properties() +{ + $__ZPOOL_CMD get 2>&1 | awk '$2 == "YES" || $2 == "NO" {print $1}'; echo all +} + +__zpool_get_editable_properties() +{ + $__ZPOOL_CMD get 2>&1 | awk '$2 == "YES" {print $1"="}' +} + +__zpool_list_pools() +{ + $__ZPOOL_CMD list -H -o name +} + +__zpool_complete() +{ + local cur prev cmd cmds + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmd="${COMP_WORDS[1]}" + + if [[ ${prev##*/} == zpool ]] + then + cmds=$(__zpool_get_commands) + COMPREPLY=($(compgen -W "$cmds" -- "$cur")) + return 0 + fi + + case "${cmd}" in + get) + __zfs_complete_ordered_arguments "$(__zpool_get_properties)" "$(__zpool_list_pools)" $cur + return 0 + ;; + import) + if [[ $prev == -d ]] + then + _filedir -d + else + COMPREPLY=($(compgen -W "$(__zpool_list_pools) -d" -- "$cur")) + fi + return 0 + ;; + set) + __zfs_complete_ordered_arguments "$(__zpool_get_editable_properties)" "$(__zpool_list_pools)" $cur + return 0 + ;; + add|attach|clear|create|detach|offline|online|remove|replace) + local pools="$(__zpool_list_pools)" + if __zfs_argument_chosen $pools + then + _filedir + else + COMPREPLY=($(compgen -W "$pools" -- "$cur")) + fi + return 0 + ;; + *) + COMPREPLY=($(compgen -W "$(__zpool_list_pools)" -- "$cur")) + return 0 + ;; + esac + +} + +complete -F __zfs_complete zfs +complete -F __zpool_complete zpool