Compare commits

...
4 Commits
Author SHA1 Message Date
Riyyi 9e9e017aa9 kernel.sh: Add error helper function 2021-09-11 17:12:28 +02:00
Riyyi 63effa3927 kernel.sh: Add fileExist helper function 2021-09-11 17:06:48 +02:00
Riyyi 19fc765477 kernel.sh: Add help option 2021-09-11 17:06:16 +02:00
Riyyi 68470003a1 kernel.sh+README: Add option to install 2021-09-11 17:04:01 +02:00
2 changed files with 86 additions and 13 deletions
+8 -2
View File
@@ -8,6 +8,12 @@ Disables incomplete reports in ~i2c-hid-code.c~ to stop logging spam.
* Build instructions
#+BEGIN_SRC sh
$ mkdir build
$ ./kernel.sh
$ mkdir build
$ ./kernel.sh
#+END_SRC
* Install
#+BEGIN_SRC sh
$ ./kernel.sh install
#+END_SRC
+78 -11
View File
@@ -5,7 +5,7 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# Build the Linux kernel
# Depends: asp, base-devel
# Depends: asp, base-devel, coreutils
# Setup
# --------------------------------------
@@ -16,19 +16,51 @@ blue="$(tput setf 1)"
red="$(tput setf 4)"
n="$(tput sgr0)"
if [ "$(dirname "$0")" != "." ]; then
echo "${b}${red}Error:${n} please run this script from the directory it resides." >&2
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
echo "${b}${red}Error:${n} no such file or directory: $1" >&2
exit 1
error "no such file or directory: $1"
fi
}
fileExist()
{
if [ ! -f "$1" ] ; then
error "no such file or directory: $1"
fi
}
@@ -37,12 +69,12 @@ checkDependencies()
dependencies="
asp
base-devel
coreutils
"
for dependency in $dependencies; do
if ! pacman -Qs "$dependency" > /dev/null; then
echo "${b}${red}Error:${n} required dependency '$dependency' is missing." >&2
exit 1
error "required dependency '$dependency' is missing."
fi
done
}
@@ -54,14 +86,14 @@ build()
rm -rf "./linux"
asp update linux
asp export linux
[ -f linux/config ] && mv linux/config .
[ -f linux/PKGBUILD ] && mv linux/PKGBUILD .
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 .
ln -s ../patch/i2c-hid-disable-incomplete-reports.patch . 2> /dev/null
updpkgsums
@@ -74,8 +106,43 @@ build()
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
build
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