-
Notifications
You must be signed in to change notification settings - Fork 5
/
build_local.sh
executable file
·125 lines (113 loc) · 3.19 KB
/
build_local.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
#
# Copyright The Titan Project Contributors.
#
set -e
optstring=":ukb:z:d:r:"
function usage {
echo "Usage: $(basename $0) $optstring" 2>&1
echo ' -u build userland only'
echo ' -k build kernel only'
echo ' -b URL for archive'
echo ' -z zfs version'
echo ' -d home directory'
echo ' -r kernel release'
exit 1
}
while getopts ${optstring} arg; do
case "${arg}" in
b)
archive_url=$OPTARG
;;
d)
home_dir=$OPTARG
;;
u)
userland_only=true
;;
k)
kernel_only=true
;;
z)
zfs_versions=$OPTARG
;;
r)
release=$OPTARG
;;
*)
usage
;;
esac
done
out_dir=$home_dir/out
archive_dir=$out_dir/archive
build_dir=$out_dir/build
userland_archive=zfs-$zfs_versions-userland.tar.gz
kernel_archive=zfs-$zfs_versions-$release.tar.gz
function archive_exists() {
[[ -n $archive_url ]] && curl --output /dev/null --fail --silent --head $archive_url/$1
}
# Download Linux Headers
function install_packages() {
sudo apt-get update -y
sudo apt-get install -y linux-headers-$release
# potentially install headers from URL instead of APT
sudo apt-get install -y \
curl xz-utils \
build-essential autoconf automake libtool gawk alien fakeroot dkms \
libblkid-dev uuid-dev libudev-dev libssl-dev zlib1g-dev libaio-dev \
libattr1-dev libelf-dev python3 python3-dev \
python3-setuptools python3-cffi libffi-dev python3-packaging git \
libcurl4-openssl-dev
}
# Checkout ZFS source
function get_zfs_source() {
if [ ! -d $home_dir/src/zfs ]; then
git clone https://github.com/zfsonlinux/zfs.git $home_dir/src/zfs
cd $home_dir/src/zfs
[ -z $ZFS_VERSION ] && ZFS_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $ZFS_VERSION
fi
}
# Build ZFS
function build_zfs() {
get_zfs_source
sh ./autogen.sh
./configure \
--prefix=/ \
--libdir=/lib \
--with-linux=/usr/src/linux-headers-$release \
--with-linux-obj=/usr/src/linux-headers-$release \
--with-config=all
make -s -j$(nproc)
make install DESTDIR=$build_dir
}
if [[ $userland_only = true ]]; then
zfs_config=user
if archive_exists $userland_archive; then
echo "Archive $userland_archive exists, skipping"
exit 0
fi
else
zfs_config=kernel
if archive_exists $kernel_archive; then
echo "Archive $kernel_archive exists, skipping"
exit 0
fi
fi
install_packages
build_zfs
if [[ $zfs_config != kernel ]]; then
echo "Creating userland archive $userland_archive"
cd $build_dir
mkdir $archive_dir
tar -czf $archive_dir/$userland_archive \
--exclude lib/modules --exclude lib/udev --exclude "lib/libzpool.*" \
--exclude sbin/zdb --exclude sbin/ztest sbin lib || exit 1
fi
if [[ $zfs_config != user ]]; then
echo "Creating kernel archive $kernel_archive"
cd $build_dir
mkdir $archive_dir
tar -czf $archive_dir/$kernel_archive lib/modules || exit 1
fi