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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
#!/bin/bash
kpatch_set_ccache_max_size()
{
local ccache_max_size=${1:-10G}
ccache --max-size="${ccache_max_size}"
}
kpatch_ubuntu_dependencies()
{
sudo sed -i 's/# deb-src/deb-src/' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y make gcc libelf-dev elfutils
sudo apt-get install -y dpkg-dev devscripts
sudo apt-get build-dep -y linux
sudo apt-get install -y ccache
# Add ddebs repository
if ! grep -q 'ddebs.ubuntu.com' /etc/apt/sources.list.d/ddebs.list; then
local codename
codename=$(lsb_release -sc)
sudo tee /etc/apt/sources.list.d/ddebs.list <<-EOF
deb http://ddebs.ubuntu.com/ ${codename} main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-security main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-updates main restricted universe multiverse
deb http://ddebs.ubuntu.com/ ${codename}-proposed main restricted universe multiverse
EOF
# add APT key
wget -Nq http://ddebs.ubuntu.com/dbgsym-release-key.asc -O- | sudo apt-key add -
sudo apt-get update
fi
sudo apt-get install -y "linux-image-$(uname -r)-dbgsym"
}
kpatch_rhel_dependencies()
{
local kernel_version
local arch
local rhel_major
local yum_utils_version
kernel_version=$(uname -r)
arch=$(uname -m)
rhel_major=${VERSION_ID%%.*}
# kpatch-build dependencies
sudo yum install -y \
elfutils \
elfutils-devel \
gcc \
gcc-c++ \
git \
"kernel-devel-${kernel_version%.*}" \
rpm-build \
wget \
yum-utils
sudo debuginfo-install -y "kernel-${kernel_version%.*}"
[[ "$arch" == "ppc64le" ]] && sudo yum install -y gcc-plugin-devel
# kernel dependencies
yum_utils_version=$(rpm -q --queryformat="%{version}" yum-utils)
if [[ "${yum_utils_version}" = "$(echo -e "${yum_utils_version}\\n4.0.12" | sort -rV | head -n1)" ]]; then
sudo yum-builddep -y --skip-unavailable "kernel-${kernel_version%.*}"
else
sudo yum-builddep -y "kernel-${kernel_version%.*}"
fi
[[ "$arch" == "x86_64" ]] && sudo yum install -y pesign
# ccache
if ! command -v ccache &> /dev/null; then
if ! sudo yum install -y ccache; then
sudo yum install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${rhel_major}.noarch.rpm" && \
sudo yum install -y ccache && \
sudo yum remove -y epel-release
fi
fi
}
kpatch_centos_dependencies()
{
kpatch_rhel_dependencies
}
kpatch_fedora_dependencies()
{
kpatch_rhel_dependencies
}
kpatch_openEuler_dependencies()
{
local kernel_version
local arch
kernel_version=$(uname -r)
arch=$(uname -m)
sudo yum install -y make gcc patch bison flex openssl-devel dwarves \
rpm-build dnf-plugins-core python3-devel openssl-devel ncurses-devel elfutils-libelf-devel
sudo yum install -y "kernel-source-${kernel_version%.*}" \
"kernel-debuginfo-${kernel_version%.*}" "kernel-devel-${kernel_version%.*}"
}
kpatch_photon_dependencies()
{
local flavor
flavor=$(uname -r | cut -d "-" -f 3)
if [[ $(uname -r | cut -d "-" -f 2) == "rt" ]]; then
flavor="rt"
fi
tdnf install -y kmod bash rpm-build coreutils util-linux sed findutils \
elfutils-devel systemd-rpm-macros build-essential wget
if [[ -z "$flavor" ]]; then
tdnf install -y linux-debuginfo
else
tdnf install -y linux-"$flavor"-debuginfo
fi
}
kpatch_opencloudos_dependencies()
{
local kernel_version
local arch
kernel_version=$(uname -r)
arch=$(uname -m)
sudo yum install -y make gcc patch bison flex openssl-devel dwarves dnf-utils \
rpm-build dnf-plugins-core python3-devel openssl-devel ncurses-devel elfutils-libelf-devel
sudo yum install -y "kernel-debuginfo-${kernel_version%.*}"\
"kernel-devel-${kernel_version%.*}"
sudo yum-builddep -y "kernel-${kernel_version}*"
}
kpatch_anolis_dependencies()
{
local kernel_version
local arch
kernel_version=$(uname -r)
arch=$(uname -m)
sudo yum install -y make gcc patch bison flex openssl-devel dwarves \
rpm-build dnf-plugins-core python3-devel openssl-devel ncurses-devel elfutils-libelf-devel
sudo yum install -y "kernel-debuginfo-${kernel_version%.*}"\
"kernel-devel-${kernel_version%.*}"
}
kpatch_dependencies()
{
# shellcheck disable=SC1091
source /etc/os-release
eval "kpatch_${ID}_dependencies" || { echo "Unsupported distro: ${ID}"; exit 1; }
}
kpatch_separate_partition_cache()
{
local partition=${1}
local mountpoint=${2}
local reformat=${3}
local owner=${USER}
if [[ "${reformat}" == "y" ]]; then
sudo mkfs.xfs -f "${partition}"
fi
sudo mkdir -p "${mountpoint}"
sudo mount "${partition}" "${mountpoint}"
sudo chown "${owner}":"${owner}" "${mountpoint}"
rm -rf "${mountpoint}/.ccache"
rm -rf "${mountpoint}/.kpatch"
mkdir "${mountpoint}/.ccache"
mkdir "${mountpoint}/.kpatch"
rm -rf "${HOME}/.ccache"
rm -rf "${HOME}/.kpatch"
ln -sv "${mountpoint}/.ccache" "${HOME}/.ccache"
ln -sv "${mountpoint}/.kpatch" "${HOME}/.kpatch"
}
kpatch_separate_disk_cache()
{
local device=${1}
local mountpoint=${2}
local partition="${device}1"
echo -e "o\\nn\\np\\n1\\n\\n\\nw\\n" | sudo fdisk "${device}"
kpatch_separate_partition_cache "${partition}" "${mountpoint}" y
}
kpatch_install_vagrant_centos()
{
local image_path=${1}
sudo yum group install -y "Development Tools"
sudo yum -y install qemu-kvm libvirt virt-install bridge-utils libvirt-devel libxslt-devel libxml2-devel libvirt-devel libguestfs-tools-c libvirt-client
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ipforward.conf
sudo sysctl -p /etc/sysctl.d/99-ipforward.conf
sudo systemctl enable libvirtd
sudo systemctl start libvirtd || exit 1
if [[ -n "${image_path}" ]]; then
mkdir -p "${image_path}/libvirt/images"
virsh pool-define-as --target "${image_path}/libvirt/images" default dir || exit 1
virsh pool-start default || exit 1
fi
sudo yum install -y https://releases.hashicorp.com/vagrant/2.1.2/vagrant_2.1.2_x86_64.rpm || exit 1
vagrant plugin install vagrant-libvirt
}
kpatch_install_vagrant_rhel()
{
local image_path=${1}
kpatch_install_vagrant_centos "${image_path}"
sudo systemctl enable nfs
sudo systemctl start nfs || exit 1
}
kpatch_install_vagrant_fedora()
{
local image_path=${1}
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-ipforward.conf
sudo sysctl -p /etc/sysctl.d/99-ipforward.conf
sudo dnf install -y libvirt virt-install libvirt-client nfs-utils vagrant vagrant-libvirt
echo "[nfsd]" | sudo tee -a /etc/nfs.conf
echo "udp=y" | sudo tee -a /etc/nfs.conf
echo "vers3=y" | sudo tee -a /etc/nfs.conf
sudo systemctl restart nfs
sudo systemctl enable libvirtd
sudo systemctl start libvirtd || exit 1
if [[ -n "${image_path}" ]]; then
mkdir -p "${image_path}/libvirt/images"
virsh pool-define-as --target "${image_path}/libvirt/images" default dir || exit 1
virsh pool-start default || exit 1
fi
}
kpatch_install_vagrant()
{
local image_path=${1}
# shellcheck disable=SC1091
source /etc/os-release
eval "kpatch_install_vagrant_${ID} ${image_path}" || { echo "Unsupported distro: ${ID}"; exit 1; }
}
kpatch_check_install_vagrant()
{
local image_path=${1}
# shellcheck disable=SC2230
[ "$(which vagrant)" == "" ] && kpatch_install_vagrant "${image_path}"
return 0
}
kpatch_write_vagrantfile_template()
{
local target_distro=${1}
local box_prefix="kpatch"
cat >Vagrantfile <<EOF
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.storage :file, :size => '40G'
libvirt.cpus = $(getconf _NPROCESSORS_ONLN)
libvirt.memory = $(awk '/MemTotal/ {printf("%d\n", ($2*0.8)/1024)}' /proc/meminfo)
libvirt.graphics_type = "none"
libvirt.disk_bus = 'virtio'
libvirt.disk_device = 'vda'
end
config.vm.box = "${box_prefix}/${target_distro}"
config.vm.synced_folder ".", "/vagrant", type: "nfs"
EOF
}
kpatch_write_vagrantfile_centos_provision()
{
cat >>Vagrantfile <<EOF
config.vm.provision "shell", inline: "yum install -y git"
EOF
}
kpatch_write_vagrantfile()
{
local target_distro=${1}
kpatch_write_vagrantfile_template "${target_distro}"
if echo "${target_distro}" | grep -qE "^centos"; then
kpatch_write_vagrantfile_centos_provision
fi
echo 'end' >>Vagrantfile
}
kpatch_integration_tests_vagrant_distro()
{
local target_distro=${1}
local test_script=${2}
local slowtest=${3}
local testdir
local workdir
local logdir
testdir="$(pwd)"
workdir="${target_distro}.vagrant"
rm -rf "${workdir}"
mkdir -p "${workdir}"
cd "${workdir}" || exit 1
kpatch_write_vagrantfile "${target_distro}"
vagrant up || { vagrant destroy -f; exit 1; }
local test_cmd="KPATCH_GIT=${KPATCH_GIT} KPATCH_REV=${KPATCH_REV} bash /vagrant/runtest.sh"
if [ "${slowtest}" == "1" ]; then
test_cmd="${test_cmd} --slow"
fi
cp "${test_script}" ./runtest.sh
vagrant ssh -c "${test_cmd}"
local rc=$?
if [ $rc -eq 0 ]; then
echo "${target_distro} PASS"
else
echo "${target_distro} FAIL"
fi
logdir="${testdir}/${target_distro}_log"
rm -rf "${logdir}"
mkdir -p "${logdir}"
cp logs/* "${logdir}"
vagrant destroy -f
cd "${testdir}" || exit 1
if [ $rc -eq 0 ]; then
rm -rf "${workdir}"
fi
return "${rc}"
}
|