Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7283

Raspberry Pi OS • How to request reboot when building a postinst script in package

$
0
0
This is going to be difficult for me to explain. I will give it a shot.

I have a project using a Raspberry Pi Zero 2 W. It has a couple of sensors on the i2c bus. I use CPACK to create a .deb package that has my software daemon that I want to run. Of course to access the I2C sensors the /boot/firmware/config.txt file has to have dtparam=i2c_arm=on in order to access the sensors.

I want the postinst script to make sure that the i2c bus is available. In the postinst script a check is made to see if /dev/12c-1 exists. If it doesn't it edits the config.txt script and makes sure there is a dtparam=i2c_arm=on line. If I needed to edit config.txt the postinst script just enables the daemon, but doesn't bother to start it because a reboot is needed to make the /dev/i2c-1 bus available. Since it is enabled it will start the daemon on the next reboot and /dev/i2c-1 should be available now that dtparam=i2c_arm=on is set in config.txt.

On my Ubuntu host when I update packages through the GUI software update package, I will sometimes get a message that a reboot is necessary, but I have no idea how this is implemented.

Is there some way for my postinst script to report that a reboot is necessary?

I assume I don't want to put a reboot command in the postinst script as I don't want things to reboot before the package installation is properly registered. Also, forcing a reboot is poor form. Installing a package and the machine reboots on me would not make me a happy camper.

Here is roughly what I have for the postinst script without any commands to get a reboot done.

Code:

need_reboot="false"$device_bus="/dev/i2c-1"if [ ! -c $device_bus ]; then  # The I2C bus doesn't exist so we have to add it to /boot/firmware/config.txt  # and then do a reboot before weather station can run  need_reboot="true"  #  # Check if there is a line that sets the i2c_arm parameter  #  if [ ! grep -q "^\s*dtparam=i2c_arm=on" $firmware_config_file ]; then    #    # We have to add the dtparam=i2c_arm=on line to the config.txt file    # Check if there is a commented out line    if [ grep -q "^.*#.*dtparam=i2c_arm" $firmware_config_file ]; then      #      # There is a line for i2c_arm, but it is commented out.      # Change the line to remove comment and set to on      #      sed -i 's/^.*#.*dtparam=i2c_arm.*/dtparam=i2c_arm=on/' $firmware_config_file    elif [ grep -q "^.*dtparam=i2c_arm=off" $firmware_config_file ]; then      #      # arm_i2c is specifically set to off. Change the line to set to on      #      sed -i 's/^.*dtparam=i2c_arm=off.*/dtparam=i2c_arm=on/' $firmware_config_file    else      #      # I2c_arm is not set to off nor is there a commented out line so just add      # a line for it      # (I am not sure if it can go to the end of the file or not. That might      #  put it under category [all] which may be a problem. I am not sure)      cat "dtparam=i2c_arm=on" >> $firmware_config_file    fi  fifisystemctl daemon-reload## Whether we need to reboot or not Check if it is enabled. If not enable it#systemctl -q is-enabled $qw_serviceif [ $? -ne 0 ]; then  systemctl -q enable $qw_servicefi## If we don't need to reboot to get the I2C bus device go# ahead and start the service if it isn't already running.#if [ $need_reboot = "false" ]; then  #  # Check if it is already running. If not start it  #  systemctl -q is-active $qw_service  if [ $? -ne 0 ]; then    systemctl -q start $qw_service  fifi
Thanks
Chris

Statistics: Posted by chriskot870 — Fri Jun 13, 2025 6:29 pm — Replies 1 — Views 71



Viewing all articles
Browse latest Browse all 7283

Trending Articles