Cannot get script to run-Ran fine in Noobs, not in DIetPi?

Hey everyone, thanks a bunch for all of the help thus far. Hopefully someday I will understand these systems much better then i currently do…

I am trying to run a script to initiate the shutdown sequence when the ff switch is triggered. I had no issue getting this to work on Noobs, but will not work on DietPi. I am using a Mausberry Circuits car switch, and going through their listed method to install the script. So far, it will not run.

This is the script in the .SH file that came directly from Mausberry Circuits (https://www.mausberrycircuits.com/pages/setup):
echo '#!/bin/bash

#this is the GPIO pin connected to the lead on switch labeled OUT
GPIOpin1=23

#this is the GPIO pin connected to the lead on switch labeled IN
GPIOpin2=24

echo “$GPIOpin1” > /sys/class/gpio/export
echo “in” > /sys/class/gpio/gpio$GPIOpin1/direction
echo “$GPIOpin2” > /sys/class/gpio/export
echo “out” > /sys/class/gpio/gpio$GPIOpin2/direction
echo “1” > /sys/class/gpio/gpio$GPIOpin2/value
while [ 1 = 1 ]; do
power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
if [ $power = 0 ]; then
sleep 1
else
sudo poweroff
fi
done’ > /etc/switch.sh
sudo chmod 777 /etc/switch.sh
sudo sed -i ‘$ i /etc/switch.sh &’ /etc/rc.local

I have tried several methods to run the script, but I am getting a number of error such as

root@DietPi:~# sudo bash setup.sh
setup.sh: line 1: !DOCTYPE: No such file or directory
setup.sh: line 2: syntax error near unexpected token newline' setup.sh: line 2: http://www.w3.org/TR/html4/strict.dtd”>’
root@DietPi:~#


I am outclassed here. This is way beyond my knowledge to modify, change, or even understand what is wrong…Is there something so vastly different about DietPI that would make this work in Noobs but not this?

I thought i might revisit this one last time to see if anyone had any insight into why this script wouldn’t run on dietpi, but has no issue on Rasberry Pi NOOBS, the new Raspberry Pi OS, and i would imagine several other distros.

I moved back tousing NOOBS for my dashboard simply because this script would run properly for my auto shut down switch in my car. That being said, i REALLY liked how quickly dietPi would boot…I would very much like to get this running before i put the dash back into the car this week.

Hi,

I don’t think the install script is working on DietPi because at the end the script is expecting /etc/rc.local, which did not exist on DietPi at all

Ok, thats good to know. Now with that being said, i wish i knew what that did or what to replace it with. Is this something I can replace something else? If i understand correctly, rc.local is for auto starting things? Is there something else DietPi uses that i could replace that part with?

I’m not 100% sure but DietPi is using systemd to start services. Better to ask MichaIng as developer :slight_smile:

If you want you can just create your own /etc/rc.local file, its quite useful and it’s what I did when I needed it for certain functions.

https://superuser.com/questions/1095117/accidentally-deleted-rc-local-on-linux-mint-17-3

Thanks for that. I will look into it. If I can make this work, it might be worth redoing my dash for the 4th time this week. 50 second bootup to loading the tuning software dashboard on the car is a bit hard to swallow, even for a dedicated race car.

root@DietPi:~# sudo bash setup.sh
setup.sh: line 1: !DOCTYPE: No such file or directory
setup.sh: line 2: syntax error near unexpected token newline' setup.sh: line 2: "> http://www.w3.org/TR/html4/strict.dtd> ">’
root@DietPi:~#

Aside of the rc.local topic, the syntax error looks like you tried to download the script but downloaded a raw HTML document instead. This happens regularly to me when I try to run this script via

bash -c "$(curl -s https://github.com/MichaIng/DietPi/blob/master/PREP_SYSTEM_FOR_DIETPI.sh)"

accidentally instead of using the URL of the actual file content:

bash -c "$(curl -s https://raw.githubusercontent.com/MichaIng/DietPi/master/PREP_SYSTEM_FOR_DIETPI.sh)"

The same would happen if the URL target does not exist, e.g. typo or removed file and the webserver returns a 404 HTML page.

From what I see, otherwise the script should work just fine after doing:

echo 'exit 0' > /etc/rc.local
chmod +x /etc/rc.local