I have written a bash script capable to do this: create-debian-rpi-package.sh
#!/usr/bin/bash
#
# @Ephemeral
#
# USAGE:
#
# sudo bash create-debian-rpi-package.sh create PACKAGENAME
# sudo dpkg -i PACKAGENAME.deb
# sudo bash create-debian-rpi-package.sh clean PACKAGENAME
#
# sudo tail -f /var/log/dpkg.log
ARCHITECTURE="armhf" # RPi3B, test: raspbian buster
PROJECT=/tmp
function CREATE(){
if [ ! -d "${PROJECT}/package/DEBIAN" ];then
mkdir -p "${PROJECT}/package/DEBIAN"
else
echo "A temporary directory ${PROJECT}/package already exists !"
echo "You can use 'sudo bash create-debian-rpi-package.sh clean'"
exit 0
fi;
cd "${PROJECT}/package"
echo "creating embeded files..."
#mkdir -p ./boot/overlays
#cp arch/arm/boot/dts/dtb ./boot
#cp arch/arm/boot/dts/overlays/.dtb* ./boot/overlays/
#cp arch/arm/boot/dts/overlays/README ./boot/overlays/
#cp arch/arm/boot/zImage ./boot/$KERNEL.img
mkdir -p ./usr/bin/
echo "ip a" > ./usr/bin/mytool.sh
cd "DEBIAN"
echo "creating pre install file, use this for saving KERNEL..."
cat << EOF > preinst
#!/bin/sh
echo "pre install job"
BACKUP_DIR="/home/pi/boot-backup-$(date +%m-%d-%Y_%H-%M-%S)"
echo "Creating /boot backup in ${BACKUP_DIR}"
if [ ! -d "${BACKUP_DIR}" ];then
mkdir "${BACKUP_DIR}"
cp -R /boot "${BACKUP_DIR}"
fi;
exit 0
EOF
chmod 0755 preinst
echo "creating control file..."
cat << EOF > control
Package: ${PACKAGENAME}
Version: 0.1-0
Architecture: ${ARCHITECTURE}
Maintainer: ${PACKAGENAME} <${PACKAGENAME}@debian.org>
Description: utility package
EOF
echo "creating post install file..."
cat << EOF > postinst
#!/bin/sh
echo "post install job"
#chmod -R +x /boot/overlays
#chmod +x /boot/$KERNEL.img
#chmod +x /boot/*.dtb
exit 0
EOF
chmod 0755 postinst
echo "building debian package ${PACKAGENAME}.deb ..."
cd ..
dpkg-deb --build /tmp/package
if [ ${?} -eq "0" ];then
mv /tmp/package.deb /tmp/${PACKAGENAME}.deb
echo "SUCCESS building /tmp/${PACKAGENAME}.deb"
echo -e "\nINSTALL\nsudo dpkg -i /tmp/${PACKAGENAME}.deb\n\n"
fi
}
function CLEAN(){
rm -R /tmp/package
rm -R /tmp/${PACKAGENAME}.deb
dpkg --purge ${PACKAGENAME}
}
if [ -z "${SUDO_USER}" ];then
echo "Sorry you must an sudo user for running this script."
exit 0
fi
case ${1} in
create|CREATE|Create)if [ -z "${2}" ];then echo "You must provide the package name."; exit 0; else PACKAGENAME="${2}";fi; CREATE;;
clean|CLEAN|Clean)if [ -z "${2}" ];then echo "You must provide the package name."; exit 0;else PACKAGENAME="${2}";fi; CLEAN;;
*)echo -e "Unknown option ${1}\nOptions are: CREATE or CLEAN";;
esac
The output of the script when I create a package named mypackage
:
pi@raspberrypi:~ $ sudo bash create-debian-rpi-package.sh create mypackage
creating embeded files...
creating pre install file, use this for saving KERNEL...
creating control file...
creating post install file...
building debian package mypackage.deb ...
dpkg-deb: building package 'mypackage' in '/tmp/package.deb'.
SUCCESS building /tmp/mypackage.deb
INSTALL
sudo dpkg -i /tmp/mypackage.deb
pi@raspberrypi:~$ sudo dpkg -i /tmp/mypackage.deb
Selection of the previously unselected mypackage package.
(Reading the database... 152119 files and directories already installed.)
Preparing unpacking of /tmp/mypackage.deb ...
pre install job
Creating /boot backup in /home/pi/boot-backup-07-10-2019_18-17-05
Unpacking mypackage (0.1-0) ...
Parameterization of mypackage (0.1-0) ...
post install job
pi@raspberrypi:~$sudo bash create-debian-rpi-package.sh clean mypackage
(Reading the database ... 152120 files and directories already installed.)
Deleting mypackage (0.1-0) ...
But, because it's relativly dangerous to copy file into /boot directory, I have not uncommented the code for your case precisly (all cp arm/...
) . I have put an example with /usr/bin
directory and a bash script
installation.
I have added a pre-install function, this function create a backup directory in /home/pi/boot-backup-$(date)
of the /boot
directory before installing any files.
For your case you must :
- uncomment the line where you copy your new kernel, adjust full
arm/
path and adjust $KERNEL.img
name.
- uncomment the
chmod +x
because all file in /boot seems to are executable in the post install file creation (yes after the copy of your files, they must exist so that we can apply them the rights).
Additionally
As specified here, you can add, once the installation is done and thus in the posinst file, a line with sed for example to replace kernel=kernel-myconfig.img
in /boot/config.txt
with the name of your kernel img and then ask the user if he wants to restart or not with his new kernel for example ...