Add 'zfs rename -u' to rename without remounting
[freebsd.git] / copy-builtin
1 #!/usr/bin/env bash
2
3 set -e
4
5 usage()
6 {
7         echo "usage: $0 <kernel source tree>" >&2
8         exit 1
9 }
10
11 [ "$#" -eq 1 ] || usage
12 KERNEL_DIR="$(readlink --canonicalize-existing "$1")"
13
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
21 fi
22
23 make clean || true
24 make gitrev
25
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/"
30
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 ZFS On Linux project.
39
40           See https://zfsonlinux.org/
41
42           To compile this file system support as a module, choose M here.
43
44           If unsure, say N.
45 EOF
46
47 add_after()
48 {
49         local FILE="$1"
50         local MARKER="$2"
51         local NEW="$3"
52         local LINE
53
54         while IFS='' read -r LINE
55         do
56                 echo "$LINE"
57
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"
65                         fi
66                 fi
67         done < "$FILE" > "$FILE.new"
68
69         mv "$FILE.new" "$FILE"
70 }
71
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/'
74
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