0

I'm running Armbian Linux and trying to execute a shell file at boot. The file runs perfectly when I execute it through the command line after boot. However, it skips my Python commands (which are supposed to send animations to an OLED screen) when it runs during boot. It does still, however, turn on and off an LED.

The shell file is placed in /etc/init.d and I ran the following commands.

sudo update-rc.d startup.sh defaults
sudo update-rc.d startup.sh enable
chmod +x /etc/init.d/startup.sh

Here is the shell file.

#!/bin/sh
### BEGIN INIT INFO
# Provides:          startup
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: display to screen
### END INIT INFO


main() {
    #GPIO numbers for the RGB-Led Pins
    RGB_GPIO_RED=157
    RGB_GPIO_GREEN=156
    RGB_GPIO_BLUE=154
    #OLED settings
    OLED_I2C_PORT=2
    OLED_ORIENTATION=2
    OLED_DISPLAY_TYPE='sh1106'

    # turn on the blue led while configuring and updating
    cd /sys/class/gpio
    sudo sh -c 'echo '$RGB_GPIO_BLUE' > export'
    cd gpio$RGB_GPIO_BLUE
    sudo sh -c 'echo out > direction'
    sudo sh -c 'echo 1 > value'
    cd ~

    # display cardano animation
    python ~/display/cardano-luma/examples/cardano-animation.py --display $OLED_DISPLAY_TYPE --i2c-port $OLED_I2C_PORT --rotate $OLED_ORIENTATION

    # turn off blue led and on the green led
    cd /sys/class/gpio
    sudo sh -c 'echo '$RGB_GPIO_BLUE' > export'
    cd gpio$RGB_GPIO_BLUE
    sudo sh -c 'echo out > direction'
    sudo sh -c 'echo 0 > value'
    cd ..
    cd /sys/class/gpio
    sudo sh -c 'echo '$RGB_GPIO_GREEN' > export'
    cd gpio$RGB_GPIO_GREEN
    sudo sh -c 'echo out > direction'
    sudo sh -c 'echo 1 > value'
    cd ~

    # display rock pi information
    sudo python ~/display/cardano-luma/examples/cardano.py --display $OLED_DISPLAY_TYPE --i2c-port $OLED_I2C_PORT --rotate $OLED_ORIENTATION
}

main "$@" || exit 1
jww
  • 97,681
  • 90
  • 411
  • 885
Marc
  • 123
  • 1
  • 4
  • 17
  • 2
    `#!/bin/sh` is **not** bash on ubuntu. Try `#!/usr/bin/env bash` or make sure it works when you run it with `dash`. Also, starting subshells to write files is not what I would do. – Elliott Frisch Dec 21 '19 at 01:49
  • What would you do? essentially i just need to run this script when the system is rebooted. Whether that be during the boot or after. Also I meant to say I'm running armbian, not linux – Marc Dec 21 '19 at 01:59
  • 1
    `update-rc.d` sounds like something archaic for ubuntu, check if you have systemd. – KamilCuk Dec 21 '19 at 02:05
  • Couple points, why do you run a python with `sudo` and the other without? Also if every command has `sudo` in front of it, write the script without `sudo`, and call the entire script with `sudo`. And scripts called at boot time are all called by root so why `sudo`? Finally, do not assume that the boot environment is equal to yours, `python` might not be found in the `$PATH` when your script is called. Create a log capturing the output, it might help figure out the issue. – Nic3500 Dec 21 '19 at 02:20
  • So I logged the output and it gives an error for no such file or directory for those python files – Marc Dec 21 '19 at 02:39
  • Set the `$PATH` variable in the script. See, for example, [Different path variables for root and user using sudo](https://stackoverflow.com/q/17800862/608639), [How to get CRON to call in the correct PATHs](https://stackoverflow.com/q/2388087/608639), [crontab PATH and USER](https://stackoverflow.com/q/10129381/608639), [Script produces different result when executed by Bash than by cron](https://stackoverflow.com/q/18912018/608639), etc. – jww Dec 21 '19 at 03:01
  • 1
    Remember that startup scripts are running as `root`, so `~` in a startup script will refer to `root`'s home directory, not yours. – larsks Dec 21 '19 at 03:23

0 Answers0