2018-08-26 20:51:00 +02:00
|
|
|
#! /bin/bash
|
|
|
|
|
2020-05-07 08:42:35 +02:00
|
|
|
# Some colors
|
2018-08-26 20:51:00 +02:00
|
|
|
GREEN='\033[0;32m'
|
2020-05-07 08:42:35 +02:00
|
|
|
RED='\033[0;31m'
|
2018-08-26 20:51:00 +02:00
|
|
|
DEFAULT='\033[0m'
|
2020-05-07 08:42:35 +02:00
|
|
|
|
|
|
|
# Defaults values
|
2018-11-12 13:14:30 +01:00
|
|
|
PREFIX='linux-'
|
2018-08-26 20:51:00 +02:00
|
|
|
EXTENSION='.tar.xz'
|
2020-05-07 08:42:35 +02:00
|
|
|
MAINLINE=1
|
|
|
|
SHOW_MENU_CONFIG=0
|
|
|
|
|
|
|
|
# Function to script script if step fail
|
|
|
|
isPreviousStepOk () {
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "${RED} Error!${DEFAULT}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get arguments from command line
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--help)
|
|
|
|
printf "****************************************************************************************************\n"
|
|
|
|
printf "* pkgkernel-auto: Usage\n"
|
|
|
|
printf "* --menu: show kernel menu\n"
|
|
|
|
printf "* --archive <path to local kernel archive>: Use local kernel archive\n"
|
|
|
|
printf "* --extension <archive extention>: if not a archive extension is not tar.xz (tar.xz or tar.gz)\n"
|
|
|
|
printf "* --rc: Get RC version instead of mainline\n"
|
|
|
|
printf "****************************************************************************************************\n"
|
|
|
|
printf "Example with RC kernel: \n"
|
|
|
|
printf "pkgkernel-auto.sh --archive /home/dbroqua/Downloads/linux-5.7-rc4.tar.gz --extension tar.gz \n"
|
|
|
|
printf "****************************************************************************************************\n"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
--menu)
|
|
|
|
SHOW_MENU_CONFIG=1
|
|
|
|
;;
|
|
|
|
--archive)
|
|
|
|
ARCHIVE=$2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--rc)
|
|
|
|
MAINLINE=0
|
|
|
|
;;
|
|
|
|
--extension)
|
|
|
|
EXTENSION=$2
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "***************************\n"
|
|
|
|
printf "* Error: Invalid argument.*\n"
|
|
|
|
printf "***************************\n"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
|
|
echo "This script must be run as root" 1>&2
|
|
|
|
sudo $0
|
|
|
|
exit 1
|
2018-11-12 13:14:30 +01:00
|
|
|
fi
|
|
|
|
|
2020-05-18 12:03:51 +02:00
|
|
|
# Install build dependancies
|
|
|
|
apt install -y \
|
|
|
|
build-essential \
|
|
|
|
fakeroot \
|
|
|
|
dpkg-dev \
|
|
|
|
perl \
|
|
|
|
libssl-dev \
|
|
|
|
bc \
|
|
|
|
gnupg \
|
|
|
|
dirmngr \
|
|
|
|
libelf-dev \
|
|
|
|
flex \
|
|
|
|
bison \
|
|
|
|
libncurses-dev \
|
|
|
|
rsync \
|
|
|
|
git \
|
|
|
|
curl
|
2018-08-26 20:51:00 +02:00
|
|
|
|
2020-05-07 08:42:35 +02:00
|
|
|
if [ "${ARCHIVE}" != "" ] ; then
|
|
|
|
FILE=`basename "$ARCHIVE"`
|
|
|
|
KERNEL=`echo ${FILE}|sed 's/linux-//'|sed "s/\.${EXTENSION}//"`
|
|
|
|
else
|
|
|
|
if [ ${MAINLINE} -eq 1 ] ; then
|
|
|
|
# Get last kernel version
|
|
|
|
INFO=`curl -Ls https://www.kernel.org/ | perl -lne 'BEGIN{$/=""} print "$1 $2" if \
|
|
|
|
/latest_link.*?<a.*?href=\"(.*?)\".*?>(.*?)</s'`
|
|
|
|
# Extract some values from kernel name
|
|
|
|
KERNEL=`echo ${INFO} | cut -d' ' -f 2`
|
|
|
|
URL=`echo ${INFO} | cut -d' ' -f 1`
|
|
|
|
FILE=`echo ${URL}|rev|cut -d'/' -f 1 | rev`
|
|
|
|
else
|
|
|
|
INFO=`curl -sS https://www.kernel.org/ |grep href |cut -f2 -d\" |grep rc |grep git |grep tar`
|
|
|
|
EXTENSION="tar.gz"
|
|
|
|
URL=${INFO}
|
|
|
|
FILE=`basename "$INFO"`
|
|
|
|
KERNEL=`echo ${FILE}|sed 's/linux-//'|sed "s/\.${EXTENSION}//"`
|
|
|
|
fi
|
|
|
|
fi
|
2018-10-22 09:50:57 +02:00
|
|
|
|
2020-05-07 08:42:35 +02:00
|
|
|
# Directory to store tmp files
|
|
|
|
DIR="/usr/src/${KERNEL}"
|
2019-08-05 10:32:29 +02:00
|
|
|
|
2020-05-07 08:42:35 +02:00
|
|
|
# Make directory in /usr/src/
|
2018-10-22 09:50:57 +02:00
|
|
|
mkdir "${DIR}"
|
|
|
|
|
|
|
|
# Go to build dir
|
|
|
|
cd "${DIR}" || exit
|
|
|
|
|
2020-05-07 08:42:35 +02:00
|
|
|
# Get kernel archive
|
|
|
|
if [ "${ARCHIVE}" == "" ] ; then
|
|
|
|
wget ${URL}
|
|
|
|
isPreviousStepOk
|
|
|
|
fi
|
|
|
|
|
2018-08-26 20:51:00 +02:00
|
|
|
# Extract kernel archive
|
2020-05-07 08:42:35 +02:00
|
|
|
if [ "${EXTENSION}" == '.tar.xz' ] ; then
|
|
|
|
tar xavf "${FILE}"
|
|
|
|
else
|
|
|
|
if [ "${ARCHIVE}" == "" ] ; then
|
|
|
|
tar xzvf "${FILE}"
|
|
|
|
else
|
|
|
|
tar xzvf "${ARCHIVE}" -C ${DIR}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
isPreviousStepOk
|
2018-08-26 20:51:00 +02:00
|
|
|
|
|
|
|
# Enter kernel directory
|
2020-05-07 08:42:35 +02:00
|
|
|
cd "linux-${KERNEL}"
|
|
|
|
isPreviousStepOk
|
2018-08-26 20:51:00 +02:00
|
|
|
|
|
|
|
# Get old config
|
|
|
|
make olddefconfig
|
2020-05-07 08:42:35 +02:00
|
|
|
isPreviousStepOk
|
|
|
|
|
|
|
|
# Show kernel menu
|
|
|
|
if [ ${SHOW_MENU_CONFIG} -eq 1 ]; then
|
|
|
|
make menuconfig
|
|
|
|
fi
|
2018-08-26 20:51:00 +02:00
|
|
|
|
|
|
|
# Some optimizations
|
2020-05-07 08:42:35 +02:00
|
|
|
# ./scripts/config -d CONFIG_MODULE_SIG_ALL -d CONFIG_MODULE_SIG_KEY -d CONFIG_SYSTEM_TRUSTED_KEYS
|
|
|
|
# isPreviousStepOk
|
2018-08-26 20:51:00 +02:00
|
|
|
./scripts/config -d CONFIG_DEBUG_INFO
|
2020-05-07 08:42:35 +02:00
|
|
|
isPreviousStepOk
|
2018-08-26 20:51:00 +02:00
|
|
|
|
|
|
|
# Compile kernel
|
2020-05-07 08:42:35 +02:00
|
|
|
make deb-pkg -j"$(nproc)" LOCALVERSION=-"$(dpkg --print-architecture)" \
|
|
|
|
KDEB_PKGVERSION="$(make kernelversion)-1"
|
|
|
|
isPreviousStepOk
|
2018-08-26 20:51:00 +02:00
|
|
|
|
|
|
|
# Optimization
|
2020-05-07 08:42:35 +02:00
|
|
|
make bindeb-pkg -j"$(nproc)" LOCALVERSION=-"$(dpkg --print-architecture)" \
|
|
|
|
KDEB_PKGVERSION="$(make kernelversion)-1"
|
|
|
|
isPreviousStepOk
|
2018-08-26 20:51:00 +02:00
|
|
|
|
|
|
|
# Go to parent directory
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
# Install new packages
|
2018-10-22 09:50:57 +02:00
|
|
|
dpkg -i ./*${KERNEL}*.deb
|
2020-05-07 08:42:35 +02:00
|
|
|
isPreviousStepOk
|
2018-08-26 20:51:00 +02:00
|
|
|
|
2019-04-04 19:53:01 +02:00
|
|
|
# Update acpi_call
|
|
|
|
git clone git://github.com/teleshoes/acpi_call.git /tmp/acpi_call
|
2020-05-07 08:42:35 +02:00
|
|
|
isPreviousStepOk
|
2019-04-04 19:53:01 +02:00
|
|
|
cd /tmp/acpi_call
|
|
|
|
make
|
2020-05-07 08:42:35 +02:00
|
|
|
isPreviousStepOk
|
2019-04-04 19:53:01 +02:00
|
|
|
make install
|
2020-05-07 08:42:35 +02:00
|
|
|
isPreviousStepOk
|
2019-04-04 19:53:01 +02:00
|
|
|
cd /tmp
|
|
|
|
|
|
|
|
# Clean directories
|
|
|
|
rm -rf /tmp/acpi_call ${DIR}
|
|
|
|
|
2018-08-26 20:51:00 +02:00
|
|
|
echo -e "${GREEN} ALL DONE!\n"
|