forked from geekworm-com/x-c1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-ubuntu.sh
125 lines (104 loc) · 3.39 KB
/
install-ubuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#IMPORTANT! This script is only for the x-c1
#x-c1 Powering on /reboot /full shutdown through hardware
#!/bin/bash
echo '#!/bin/bash
SHUTDOWN=4
REBOOTPULSEMINIMUM=200
REBOOTPULSEMAXIMUM=600
pigs modes ${SHUTDOWN} r
BOOT=17
pigs modes ${BOOT} w
pigs w ${BOOT} 1
echo "Your device are shutting down..."
while [ 1 ]; do
shutdownSignal=$(pigs r ${SHUTDOWN})
if [ ${shutdownSignal} -eq 0 ]; then
/bin/sleep 0.2
else
pulseStart=$(date +%s%N | cut -b1-13)
while [ ${shutdownSignal} -eq 1 ]; do
/bin/sleep 0.02
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=$(pigs r ${SHUTDOWN})
done
if [ $(($(date +%s%N | cut -b1-13)-${pulseStart})) -gt ${REBOOTPULSEMINIMUM} ]; then
echo "Your device are rebooting", SHUTDOWN, ", recycling Rpi ..."
sudo reboot
exit
fi
fi
done' > /etc/x-c1-pwr.sh
sudo chmod +x /etc/x-c1-pwr.sh
#sudo sed -i '$ i /etc/x-c1-pwr.sh &' ${AUTO_RUN}
#x-c1 full shutdown through shell
echo '#!/bin/bash
BUTTON=27
pigs modes ${BUTTON} w
pigs w ${BUTTON} 1
SLEEP=${1:-4}
re='^[0-9\.]+$'
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}
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
fi
sudo echo '[Unit]
Description=Daemon required to control GPIO pins via pigpio
[Service]
ExecStart=/usr/local/bin/pigpiod
ExecStop=/bin/systemctl kill pigpiod
Type=forking
[Install]
WantedBy=multi-user.target
' >> ${SERVICE_NAME}
# create pigpiog service - begin
sudo systemctl enable pigpiod
CUR_DIR=$(pwd)
#####################################
echo "#!/bin/bash
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "${_IP}" ]; then
printf "My IP address is %s\n" "${_IP}"
fi
/etc/x-c1-pwr.sh &
python3 ${CUR_DIR}/fan.py &
exit 0
" > /etc/rc.local
sudo chmod +x /etc/rc.local
#得到上一级目录
#dname=$(dirname ${CUR_DIR})
#echo "alias xoff='sudo /usr/local/bin/x-c1-softsd.sh'" >> ${dname}/.bashrc
sudo pigpiod
python3 ${CUR_DIR}/fan.py&
echo "The installation is complete."
echo "Please run 'sudo reboot' to reboot the device."
echo "NOTE:"
echo "1. DON'T modify the name fold: $(basename ${CUR_DIR}), or the PWM fan will not work after reboot."
echo "2. fan.py is python file to control fan speed according temperature of CPU, you can modify it according your needs.The fan.py file uses the third-party pigpiod library, and fan-rpi.py only uses the gpio library of the Raspberry Pi. We will gradually abandon the use of the third-party pigpiod library"
echo "3. PWM fan needs a PWM signal to start working. If fan doesn't work in third-party OS afer reboot only remove the FAN HS jumper of x-c1 shield to let the fan run immediately or contact us: [email protected]."