-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.sh
81 lines (67 loc) · 2.05 KB
/
tasks.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
#!/usr/bin/env bash
set -euo pipefail
readonly BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC2046
[ -f "${BASE_DIR}/.env" ] && export $(grep -vE "^(#.*|\s*)$" "${BASE_DIR}/.env" | xargs)
readonly KERNEL_NAME="${KERNEL_NAME:?"You must provide a kernel name (linux or linux-lts)"}"
readonly PKG_BASE_NAME="${PKG_BASE_NAME:?"You must provide a package name (eg. linux-custom)"}"
readonly PATCHES_DIR="${BASE_DIR}/patches/${KERNEL_NAME}"
readonly BUILD_DIR="${BASE_DIR}/build"
readonly LINUX_DIR="${BUILD_DIR}/${KERNEL_NAME}/repo"
readonly PACKAGE_DIR="${BUILD_DIR}/${KERNEL_NAME}/package"
readonly DIST_DIR="${BASE_DIR}/dist"
function checkout_linux_repo() {
if [[ -d "${LINUX_DIR}" ]]; then
echo "Fetching linux kernel repository..."
cd "${LINUX_DIR}"
git pull
cd ..
else
echo "Cloning linux kernel repository ${KERNEL_NAME}..."
git clone https://github.com/archlinux/svntogit-packages --branch "packages/${KERNEL_NAME}" --single-branch "${LINUX_DIR}"
fi
mkdir -p "${PACKAGE_DIR}"
cd "${PACKAGE_DIR}"
echo "Copying package build instructions from trunk..."
cp "${LINUX_DIR}"/trunk/{config,PKGBUILD} .
cp "${LINUX_DIR}"/trunk/*.patch . || true
cd ..
}
function configure_package() {
local pkg_base="${PKG_BASE_NAME}"
apply_patches "remove-doc"
echo "Set pkgbase='${pkg_base}' into PKGBUILD..."
cd "${PACKAGE_DIR}"
sed -i "s/pkgbase=${KERNEL_NAME}/pkgbase=${pkg_base}/g" PKGBUILD
cd ..
echo "Prepare custom config"
cd "${PACKAGE_DIR}"
cat "${PATCHES_DIR}/config" >>config
updpkgsums
cd ..
}
function apply_patches() {
local patches=("${@}")
cd "${PACKAGE_DIR}"
for patch in "${patches[@]}"; do
patch PKGBUILD <"${PATCHES_DIR}/PKGBUILD-${patch}.patch"
done
cd ..
}
function build() {
cd "${PACKAGE_DIR}"
makepkg -s
cd ..
mkdir -p "${DIST_DIR}"
mv "${PACKAGE_DIR}"/*.tar.zst "${DIST_DIR}"
}
function default {
help
}
function help {
echo "$0 <task> <args>"
echo "Tasks:"
compgen -A function | cat -n
}
TIMEFORMAT="Task completed in %3lR"
time "${@:-default}"