Customized Arch Linux kernel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

148 lines
2.5 KiB

#!/bin/sh
#
# Copyright (C) 2021 Rick <riyyi3@gmail.com>
#
# SPDX-License-Identifier: GPL-2.0-only
#
# Build the Linux kernel
# Depends: asp, base-devel, coreutils
# Setup
# --------------------------------------
b="$(tput bold)"
u="$(tput smul)"
blue="$(tput setf 1)"
red="$(tput setf 4)"
n="$(tput sgr0)"
error()
{
echo "${b}${red}Error:${n} $1" >&2
exit 1
}
if [ "$(dirname "$0")" != "." ]; then
error "please run this script from the directory it resides."
fi
help()
{
cat << EOF
${b}NAME${n}
kernel.sh - build the Linux kernel
${b}SYNOPSIS${n}
${u}kernel.sh${n} [${u}OPTION${n}] ${u}COMMAND${n}
${b}OPTIONS${n}
${b}-h${n}, ${b}--help${n} Display usage message and exit.
${b}COMMANDS${n}
${b}build${n}
Build the kernel, this is the default.
${b}install${n}
Install the kernel.
EOF
}
# Main functionality
# --------------------------------------
cdSafe()
{
if ! cd "$1" 2> /dev/null; then
error "no such file or directory: $1"
fi
}
fileExist()
{
if [ ! -f "$1" ] ; then
error "no such file or directory: $1"
fi
}
checkDependencies()
{
dependencies="
asp
base-devel
coreutils
"
for dependency in $dependencies; do
if ! pacman -Qs "$dependency" > /dev/null; then
error "required dependency '$dependency' is missing."
fi
done
}
build()
{
cdSafe build
rm -rf "./linux"
asp update linux
asp export linux
fileExist linux/config && mv linux/config .
fileExist linux/PKGBUILD && mv linux/PKGBUILD .
rm -rf "./linux"
patch --forward --strip=1 config < ../patch/config.patch
patch --forward --strip=1 PKGBUILD < ../patch/pkgbuild.patch
ln -s ../patch/i2c-hid-disable-incomplete-reports.patch . 2> /dev/null
updpkgsums
printf "\n%s=>> Edit linux/%sPKGBUILD%s? [y/N]: " "${u}${blue}" "${n}${b}${u}" "${n}"
read -r edit
if [ "$edit" = "y" ] || [ "$edit" = "Y" ]; then
$EDITOR PKGBUILD
fi
time makepkg -s
}
install()
{
cdSafe build
packages="$(find . -name "*.tar.zst" -type f)"
found="$(echo "$packages" | wc -l)"
if [ "$found" -ne 2 ]; then
error "kernel was not build yet."
fi
if ! sudo -v; then
error "you cannot perform this operation uness you are root."
fi
echo "$packages" | xargs --open-tty sudo pacman -U --needed
}
# Execute
# --------------------------------------
checkDependencies
script="$(basename "$0")"
case "$1" in
-h | --help)
help
;;
build | "")
build
;;
install)
install
;;
*)
echo "$script: invalid option '$1'" >&2
echo "Try '$script -h' for more information." >&2
exit 1
;;
esac