ZTS: Improve cleanup in removal_with_export
[zfs.git] / copy-builtin
blob36e19545d9c4413372671a3bbaee0932143e753c
1 #!/usr/bin/env bash
3 set -e
5 usage()
7 echo "usage: $0 <kernel source tree>" >&2
8 exit 1
11 [ "$#" -eq 1 ] || usage
12 KERNEL_DIR="$(readlink --canonicalize-existing "$1")"
14 if ! [ -e 'zfs_config.h' ]
15 then
16 echo >&2
17 echo " $0: you did not run configure, or you're not in the ZFS source directory." >&2
18 echo " $0: run configure with --with-linux=$KERNEL_DIR and --enable-linux-builtin." >&2
19 echo >&2
20 exit 1
23 make clean || true
24 make gitrev
26 rm -rf "$KERNEL_DIR/include/zfs" "$KERNEL_DIR/fs/zfs"
27 cp --recursive include "$KERNEL_DIR/include/zfs"
28 cp --recursive module "$KERNEL_DIR/fs/zfs"
29 cp zfs_config.h "$KERNEL_DIR/include/zfs/"
31 cat > "$KERNEL_DIR/fs/zfs/Kconfig" <<"EOF"
32 config ZFS
33 tristate "ZFS filesystem support"
34 depends on EFI_PARTITION
35 select ZLIB_INFLATE
36 select ZLIB_DEFLATE
37 help
38 This is the ZFS filesystem from the OpenZFS project.
40 See https://github.com/openzfs/zfs
42 To compile this file system support as a module, choose M here.
44 If unsure, say N.
45 EOF
47 add_after()
49 local FILE="$1"
50 local MARKER="$2"
51 local NEW="$3"
52 local LINE
54 while IFS='' read -r LINE
56 echo "$LINE"
58 if [ -n "$MARKER" -a "$LINE" = "$MARKER" ]
59 then
60 echo "$NEW"
61 MARKER=''
62 if IFS='' read -r LINE
63 then
64 [ "$LINE" != "$NEW" ] && echo "$LINE"
67 done < "$FILE" > "$FILE.new"
69 mv "$FILE.new" "$FILE"
72 add_after "$KERNEL_DIR/fs/Kconfig" 'if BLOCK' 'source "fs/zfs/Kconfig"'
73 add_after "$KERNEL_DIR/fs/Makefile" 'endif' 'obj-$(CONFIG_ZFS) += zfs/'
75 echo >&2
76 echo " $0: done." >&2
77 echo " $0: now you can build the kernel with ZFS support." >&2
78 echo " $0: make sure you enable ZFS support (CONFIG_ZFS) before building." >&2
79 echo >&2