Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Debian GNU/Linux 12 (bookworm) & Kernel Linux 6.6.x #12

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
**This project has been deprecated, you can refer to [XScript](https://github.com/geekworm-com/xscript), there is a better implementation in [XScript](https://github.com/geekworm-com/xscript)**

User Guide: https://wiki.geekworm.com/XScript

Past User Guide: https://wiki.geekworm.com/X-C1_Software

Update for Debian GNU/Linux 12 (bookworm) & Kernel Linux 6.6.x

Using ```pigpio``` as ```sysfs``` is not supported any longer.

#### Required commands for setup

* ```
sudo apt-get install pigpio
```
* ```
sudo systemctl enable pigpiod
```
* ```
sudo systemctl start pigpiod
```
35 changes: 16 additions & 19 deletions install-dietPi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@ echo '#!/bin/bash
SHUTDOWN=4
REBOOTPULSEMINIMUM=200
REBOOTPULSEMAXIMUM=600
echo "$SHUTDOWN" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$SHUTDOWN/direction
pigs modes ${SHUTDOWN} r
BOOT=17
echo "$BOOT" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$BOOT/direction
echo "1" > /sys/class/gpio/gpio$BOOT/value
pigs modes ${BOOT} w
pigs w ${BOOT} 1

echo "Power management script is running..."

while [ 1 ]; do
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
if [ $shutdownSignal = 0 ]; then
shutdownSignal=$(pigs r ${SHUTDOWN})
if [ ${shutdownSignal} -eq 0 ]; then
/bin/sleep 0.2
else
pulseStart=$(date +%s%N | cut -b1-13)
while [ $shutdownSignal = 1 ]; do
while [ ${shutdownSignal} -eq 1 ]; do
/bin/sleep 0.02
if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMAXIMUM ]; then
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMAXIMUM} ]; then
echo "Your device are shutting down", SHUTDOWN, ", halting Rpi ..."
sudo poweroff
exit
fi
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
shutdownSignal=$(pigs r ${SHUTDOWN})
done
if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMINIMUM ]; then
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMINIMUM} ]; then
echo "Your device are rebooting", SHUTDOWN, ", recycling Rpi ..."
sudo reboot
exit
Expand All @@ -46,21 +44,20 @@ echo '#!/bin/bash

BUTTON=27

echo "$BUTTON" > /sys/class/gpio/export;
echo "out" > /sys/class/gpio/gpio$BUTTON/direction
echo "1" > /sys/class/gpio/gpio$BUTTON/value
pigs modes ${BUTTON} w
pigs w ${BUTTON} 1

SLEEP=${1:-4}

re='^[0-9\.]+$'
if ! [[ $SLEEP =~ $re ]] ; then
if ! [[ ${SLEEP} =~ ${re} ]] ; then
echo "error: sleep time not a number" >&2; exit 1
fi

echo "Your device will shutting down in 4 seconds..."
/bin/sleep $SLEEP
/bin/sleep ${SLEEP}

echo "0" > /sys/class/gpio/gpio$BUTTON/value
pigs w ${BUTTON} 0
' > /usr/local/bin/x-c1-softsd.sh
sudo chmod +x /usr/local/bin/x-c1-softsd.sh

Expand All @@ -83,8 +80,8 @@ echo "#!/bin/bash

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
if [ "${_IP}" ]; then
printf "My IP address is %s\n" "${_IP}"
fi

/etc/x-c1-pwr.sh &
Expand Down
39 changes: 18 additions & 21 deletions install-manjaro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,29 @@ echo '#!/bin/bash
SHUTDOWN=4
REBOOTPULSEMINIMUM=200
REBOOTPULSEMAXIMUM=600
echo "$SHUTDOWN" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$SHUTDOWN/direction
pigs modes ${SHUTDOWN} r
BOOT=17
echo "$BOOT" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$BOOT/direction
echo "1" > /sys/class/gpio/gpio$BOOT/value
pigs modes ${BOOT} w
pigs w ${BOOT} 1

echo "Your device are shutting down..."

while [ 1 ]; do
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
if [ $shutdownSignal = 0 ]; then
shutdownSignal=$(pigs r ${SHUTDOWN})
if [ ${shutdownSignal} -eq 0 ]; then
/bin/sleep 0.2
else
pulseStart=$(date +%s%N | cut -b1-13)
while [ $shutdownSignal = 1 ]; do
while [ ${shutdownSignal} -eq 1 ]; do
/bin/sleep 0.02
if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMAXIMUM ]; then
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMAXIMUM} ]; then
echo "Your device are shutting down", SHUTDOWN, ", halting Rpi ..."
sudo poweroff
exit
fi
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
shutdownSignal=$(pigs r ${SHUTDOWN})
done
if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMINIMUM ]; then
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMINIMUM} ]; then
echo "Your device are rebooting", SHUTDOWN, ", recycling Rpi ..."
sudo reboot
exit
Expand All @@ -46,28 +44,27 @@ echo '#!/bin/bash

BUTTON=27

echo "$BUTTON" > /sys/class/gpio/export;
echo "out" > /sys/class/gpio/gpio$BUTTON/direction
echo "1" > /sys/class/gpio/gpio$BUTTON/value
pigs modes ${BUTTON} w
pigs w ${BUTTON} 1

SLEEP=${1:-4}

re='^[0-9\.]+$'
if ! [[ $SLEEP =~ $re ]] ; then
if ! [[ ${SLEEP} =~ ${re} ]] ; then
echo "error: sleep time not a number" >&2; exit 1
fi

echo "Your device will shutting down in 4 seconds..."
/bin/sleep $SLEEP
/bin/sleep ${SLEEP}

echo "0" > /sys/class/gpio/gpio$BUTTON/value
pigs w ${BUTTON} 0
' > /usr/local/bin/x-c1-softsd.sh
sudo chmod +x /usr/local/bin/x-c1-softsd.sh

# create pigpiog service - begin
SERVICE_NAME="/lib/systemd/system/pigpiod.service"
if [ -e $SERVICE_NAME ]; then
sudo rm $SERVICE_NAME -f
if [ -e ${SERVICE_NAME} ]; then
sudo rm ${SERVICE_NAME} -f
fi

sudo echo '[Unit]
Expand All @@ -83,8 +80,8 @@ WantedBy=multi-user.target
' >> ${SERVICE_NAME}

RC_SERVICE_NAME="/lib/systemd/system/rc.local.service"
if [ -e $RC_SERVICE_NAME ]; then
sudo rm $RC_SERVICE_NAME -f
if [ -e ${RC_SERVICE_NAME} ]; then
sudo rm ${RC_SERVICE_NAME} -f
fi
sudo echo '[Unit]
Description=/etc/rc.local Compatibility
Expand Down
31 changes: 14 additions & 17 deletions install-mynode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@ echo '#!/bin/bash
SHUTDOWN=4
REBOOTPULSEMINIMUM=200
REBOOTPULSEMAXIMUM=600
echo "$SHUTDOWN" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$SHUTDOWN/direction
pigs modes ${SHUTDOWN} r
BOOT=17
echo "$BOOT" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$BOOT/direction
echo "1" > /sys/class/gpio/gpio$BOOT/value
pigs modes ${BOOT} w
pigs w ${BOOT} 1

echo "Power management script is running..."

while [ 1 ]; do
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
if [ $shutdownSignal = 0 ]; then
shutdownSignal=$(pigs r ${SHUTDOWN})
if [ ${shutdownSignal} -eq 0 ]; then
/bin/sleep 0.2
else
pulseStart=$(date +%s%N | cut -b1-13)
while [ $shutdownSignal = 1 ]; do
while [ ${shutdownSignal} -eq 1 ]; do
/bin/sleep 0.02
if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMAXIMUM ]; then
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMAXIMUM} ]; then
echo "Your device are shutting down", SHUTDOWN, ", halting Rpi ..."
sudo poweroff
exit
fi
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
shutdownSignal=$(pigs r ${SHUTDOWN})
done
if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMINIMUM ]; then
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMINIMUM} ]; then
echo "Your device are rebooting", SHUTDOWN, ", recycling Rpi ..."
sudo reboot
exit
Expand All @@ -46,21 +44,20 @@ echo '#!/bin/bash

BUTTON=27

echo "$BUTTON" > /sys/class/gpio/export;
echo "out" > /sys/class/gpio/gpio$BUTTON/direction
echo "1" > /sys/class/gpio/gpio$BUTTON/value
pigs modes ${BUTTON} w
pigs w ${BUTTON} 1

SLEEP=${1:-4}

re='^[0-9\.]+$'
if ! [[ $SLEEP =~ $re ]] ; then
if ! [[ ${SLEEP} =~ ${re} ]] ; then
echo "error: sleep time not a number" >&2; exit 1
fi

echo "Your device will shutting down in 4 seconds..."
/bin/sleep $SLEEP
/bin/sleep ${SLEEP}

echo "0" > /sys/class/gpio/gpio$BUTTON/value
pigs w ${BUTTON} 0
' > /usr/local/bin/x-c1-softsd.sh
sudo chmod +x /usr/local/bin/x-c1-softsd.sh

Expand Down
39 changes: 18 additions & 21 deletions install-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,29 @@ echo '#!/bin/bash
SHUTDOWN=4
REBOOTPULSEMINIMUM=200
REBOOTPULSEMAXIMUM=600
echo "$SHUTDOWN" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$SHUTDOWN/direction
pigs modes ${SHUTDOWN} r
BOOT=17
echo "$BOOT" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$BOOT/direction
echo "1" > /sys/class/gpio/gpio$BOOT/value
pigs modes ${BOOT} w
pigs w ${BOOT} 1

echo "Your device are shutting down..."

while [ 1 ]; do
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
if [ $shutdownSignal = 0 ]; then
shutdownSignal=$(pigs r ${SHUTDOWN})
if [ ${shutdownSignal} -eq 0 ]; then
/bin/sleep 0.2
else
pulseStart=$(date +%s%N | cut -b1-13)
while [ $shutdownSignal = 1 ]; do
while [ ${shutdownSignal} -eq 1 ]; do
/bin/sleep 0.02
if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMAXIMUM ]; then
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMAXIMUM} ]; then
echo "Your device are shutting down", SHUTDOWN, ", halting Rpi ..."
sudo poweroff
exit
fi
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
shutdownSignal=$(pigs r ${SHUTDOWN})
done
if [ $(($(date +%s%N | cut -b1-13)-$pulseStart)) -gt $REBOOTPULSEMINIMUM ]; then
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMINIMUM} ]; then
echo "Your device are rebooting", SHUTDOWN, ", recycling Rpi ..."
sudo reboot
exit
Expand All @@ -46,29 +44,28 @@ echo '#!/bin/bash

BUTTON=27

echo "$BUTTON" > /sys/class/gpio/export;
echo "out" > /sys/class/gpio/gpio$BUTTON/direction
echo "1" > /sys/class/gpio/gpio$BUTTON/value
pigs modes ${BUTTON} w
pigs w ${BUTTON} 1

SLEEP=${1:-4}

re='^[0-9\.]+$'
if ! [[ $SLEEP =~ $re ]] ; then
if ! [[ ${SLEEP} =~ ${re} ]] ; then
echo "error: sleep time not a number" >&2; exit 1
fi

echo "Your device will shutting down in 4 seconds..."
/bin/sleep $SLEEP
/bin/sleep ${SLEEP}

echo "0" > /sys/class/gpio/gpio$BUTTON/value
pigs w ${BUTTON} 0
' > /usr/local/bin/x-c1-softsd.sh
sudo chmod +x /usr/local/bin/x-c1-softsd.sh

# create pigpiog service - begin
SERVICE_NAME="/lib/systemd/system/pigpiod.service"
# Create service file on system.
if [ -e $SERVICE_NAME ]; then
sudo rm $SERVICE_NAME -f
if [ -e ${SERVICE_NAME} ]; then
sudo rm ${SERVICE_NAME} -f
fi

sudo echo '[Unit]
Expand Down Expand Up @@ -103,8 +100,8 @@ echo "#!/bin/bash

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
if [ "${_IP}" ]; then
printf "My IP address is %s\n" "${_IP}"
fi

/etc/x-c1-pwr.sh &
Expand Down
Loading