67 lines
2.1 KiB
Bash
67 lines
2.1 KiB
Bash
#!/bin/bash
|
|
|
|
BRANCH="main"
|
|
|
|
show_cron_menu() {
|
|
echo "Choose option:"
|
|
echo " 1) Control modem via GPIO"
|
|
echo " 2) Control modem via MQTT"
|
|
}
|
|
|
|
# force run from root user
|
|
if [[ $EUID -ne 0 ]]; then
|
|
exec sudo bash "$(realpath $0)" "$@"
|
|
fi
|
|
|
|
rm /etc/ppp/chatscripts/t3hs_sim800 &> /dev/null
|
|
rm /etc/ppp/peers/t3hs_sim800 &> /dev/null
|
|
rm /usr/bin/t3hs/t3hs_sim800 &> /dev/null
|
|
rm /etc/init.d/t3hs_sim800.sh &> /dev/null
|
|
rm /etc/cron.d/t3hs_sim800_gpio &> /dev/null
|
|
rm /etc/cron.d/t3hs_sim800_mqtt &> /dev/null
|
|
echo "Old files removed"
|
|
|
|
apt update
|
|
apt remove -y inetutils-ping
|
|
apt install -y ppp curl iputils-ping mosquitto-clients
|
|
echo "Dependencies installed"
|
|
|
|
mkdir -p /etc/ppp/chatscripts
|
|
curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/$BRANCH/etc/ppp/chatscripts/t3hs_sim800" > /etc/ppp/chatscripts/t3hs_sim800
|
|
|
|
mkdir -p /etc/ppp/peers
|
|
curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/$BRANCH/etc/ppp/peers/t3hs_sim800" > /etc/ppp/peers/t3hs_sim800
|
|
|
|
mkdir -p /usr/bin/t3hs
|
|
curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/$BRANCH/usr/bin/t3hs/t3hs_sim800" > /usr/bin/t3hs/t3hs_sim800
|
|
chmod +x /usr/bin/t3hs/t3hs_sim800
|
|
|
|
mkdir -p /etc/init.d
|
|
curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/$BRANCH/etc/init.d/t3hs_sim800.sh" > /etc/init.d/t3hs_sim800.sh
|
|
chmod +x /etc/init.d/t3hs_sim800.sh
|
|
|
|
mkdir -p /etc/cron.d
|
|
while true; do
|
|
show_cron_menu
|
|
read -p "Your choose (1/2): " choice
|
|
case "$choice" in
|
|
1)
|
|
curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/$BRANCH/etc/cron.d/t3hs_sim800_gpio" > /etc/cron.d/t3hs_sim800_gpio
|
|
chmod 644 /etc/cron.d/t3hs_sim800_gpio
|
|
chown root:root /etc/cron.d/t3hs_sim800_gpio
|
|
break
|
|
;;
|
|
2)
|
|
curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/$BRANCH/etc/cron.d/t3hs_sim800_mqtt" > /etc/cron.d/t3hs_sim800_mqtt
|
|
chmod 644 /etc/cron.d/t3hs_sim800_mqtt
|
|
chown root:root /etc/cron.d/t3hs_sim800_mqtt
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ ! -f /etc/t3hs/sim800 ]]; then
|
|
mkdir -p /etc/t3hs
|
|
curl -sSL "https://git.openergy.ru/LUCKFOX/SIM800C/raw/branch/$BRANCH/etc/t3hs/sim800" > /etc/t3hs/sim800
|
|
fi
|