2020-11-18 18:12:00 +00:00
#!/bin/bash
2018-10-15 14:58:48 +00:00
2020-11-27 10:19:32 +00:00
# Created on November 27, 2020 by Yasin Kaya (selengalp)
2020-11-18 18:45:59 +00:00
SIXFAB_PATH = "/opt/sixfab"
PPP_PATH = "/opt/sixfab/ppp_connection_manager"
2020-11-18 19:09:09 +00:00
REPO_PATH = "https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer"
BRANCH = revision
2020-11-27 10:02:36 +00:00
SOURCE_PATH = "./src"
SCRIPT_PATH = "./src/reconnect_scripts"
2020-11-19 09:34:16 +00:00
RECONNECT_SCRIPT_NAME = "ppp_reconnect.sh"
MANAGER_SCRIPT_NAME = "ppp_connection_manager.sh"
2020-11-19 08:19:04 +00:00
SERVICE_NAME = "ppp_connection_manager.service"
2020-11-18 19:09:09 +00:00
2018-10-15 14:58:48 +00:00
YELLOW = '\033[1;33m'
RED = '\033[0;31m'
2019-05-02 13:42:04 +00:00
BLUE = '\033[1;34m'
2020-11-25 13:59:31 +00:00
GREEN = '\033[0;32m'
2018-10-15 14:58:48 +00:00
SET = '\033[0m'
2020-11-25 22:50:37 +00:00
# Global Varibales
POWERUP_REQ = 1
POWERUP_NOT_REQ = 0
STATUS_GPRS = 19
STATUS_CELL_IOT_APP = 20
STATUS_CELL_IOT = 23
STATUS_TRACKER = 23
POWERKEY_GPRS = 26
POWERKEY_CELL_IOT_APP = 11
POWERKEY_CELL_IOT = 24
POWERKEY_TRACKER = 24
2020-11-18 18:24:15 +00:00
2020-11-18 18:12:00 +00:00
function colored_echo
{
COLOR = ${ 2 :- $YELLOW }
echo -e " $COLOR $1 ${ SET } "
}
2020-11-18 18:45:59 +00:00
# Check Sixfab path
if [ [ -e $SIXFAB_PATH ] ] ; then
2020-11-19 11:54:45 +00:00
colored_echo "Sixfab path already exist!" ${ SET }
2020-11-18 18:45:59 +00:00
else
sudo mkdir $SIXFAB_PATH
2020-11-19 11:54:45 +00:00
colored_echo "Sixfab path is created." ${ SET }
2020-11-18 18:45:59 +00:00
fi
# Check PPP path
if [ [ -e $PPP_PATH ] ] ; then
2020-11-19 11:54:45 +00:00
colored_echo "PPP path already exist!" ${ SET }
2020-11-18 18:45:59 +00:00
else
sudo mkdir $PPP_PATH
2020-11-19 11:54:45 +00:00
colored_echo "PPP path is created." ${ SET }
2020-11-18 18:45:59 +00:00
fi
2020-11-18 18:12:00 +00:00
colored_echo "Please choose your Sixfab Shield/HAT:"
colored_echo "1: GSM/GPRS Shield"
colored_echo "2: 3G, 4G/LTE Base Shield"
colored_echo "3: Cellular IoT App Shield"
colored_echo "4: Cellular IoT HAT"
colored_echo "5: Tracker HAT"
colored_echo "6: 3G/4G Base HAT"
2019-10-13 19:14:14 +00:00
2018-10-15 14:58:48 +00:00
2019-05-02 13:42:04 +00:00
read shield_hat
case $shield_hat in
2020-11-25 13:59:31 +00:00
1) colored_echo "You chose GSM/GPRS Shield" ${ GREEN } ; ;
2) colored_echo "You chose Base Shield" ${ GREEN } ; ;
3) colored_echo "You chose CellularIoT Shield" ${ GREEN } ; ;
4) colored_echo "You chose CellularIoT HAT" ${ GREEN } ; ;
5) colored_echo "You chose Tracker HAT" ${ GREEN } ; ;
6) colored_echo "You chose 3G/4G Base HAT" ${ GREEN } ; ;
2020-11-18 18:12:00 +00:00
*) colored_echo "Wrong Selection, exiting" ${ RED } ; exit 1;
2018-10-15 14:58:48 +00:00
esac
2020-11-25 14:11:58 +00:00
colored_echo "Checking requirements..."
2020-11-20 12:06:57 +00:00
2020-11-25 14:09:14 +00:00
colored_echo "Updating headers..."
sudo apt-get update
2020-11-20 12:06:57 +00:00
colored_echo "Installing python3 if it is required..."
if ! [ -x " $( command -v python3) " ] ; then
2020-11-25 13:59:31 +00:00
sudo apt-get install python3 -y
2020-11-25 14:06:15 +00:00
if [ [ $? -ne 0 ] ] ; then colored_echo "Process failed" ${ RED } ; exit 1; fi
2020-11-20 12:06:57 +00:00
fi
colored_echo "Installing pip3 if it is required..."
if ! [ -x " $( command -v pip3) " ] ; then
2020-11-25 13:59:31 +00:00
sudo apt-get install python3-pip -y
2020-11-25 14:06:15 +00:00
if [ [ $? -ne 0 ] ] ; then colored_echo "Process failed" ${ RED } ; exit 1; fi
2020-11-20 12:06:57 +00:00
fi
colored_echo "Installing or upgrading atcom if it is required..."
2020-11-25 14:06:15 +00:00
2020-11-25 13:59:31 +00:00
pip3 install -U atcom
2020-11-25 14:06:15 +00:00
if [ [ $? -ne 0 ] ] ; then colored_echo "Process failed" ${ RED } ; exit 1; fi
2020-11-25 13:59:31 +00:00
source ~/.profile
2020-11-25 14:06:15 +00:00
if [ [ $? -ne 0 ] ] ; then colored_echo "Process failed" ${ RED } ; exit 1; fi
2020-11-20 12:06:57 +00:00
2020-11-27 10:02:36 +00:00
colored_echo "Copying setup files..."
2018-10-15 14:58:48 +00:00
2020-11-27 10:07:47 +00:00
cp $SOURCE_PATH /chat-connect chat-connect
cp $SOURCE_PATH /chat-disconnect chat-disconnect
cp $SOURCE_PATH /provider provider
2020-10-21 15:02:46 +00:00
2020-11-18 18:12:00 +00:00
colored_echo "ppp and wiringpi (gpio tool) installing..."
apt-get install ppp wiringpi -y
2020-11-25 14:06:15 +00:00
if [ [ $? -ne 0 ] ] ; then colored_echo "Process failed" ${ RED } ; exit 1; fi
2018-10-15 14:58:48 +00:00
2020-11-25 23:09:42 +00:00
# test wiringpi and fix if there is any issue
gpio readall | grep Oops > /dev/null
if [ [ $? -ne 1 ] ] ; then
colored_echo "Known wiringpi issue is detected! Wiringpi is updating..."
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
fi
2020-11-18 18:12:00 +00:00
colored_echo "What is your carrier APN?"
2018-10-15 14:58:48 +00:00
read carrierapn
2020-11-25 13:59:31 +00:00
colored_echo " Your Input is : $carrierapn " ${ GREEN }
2019-05-02 13:42:04 +00:00
while [ 1 ]
do
2020-11-18 18:12:00 +00:00
colored_echo "Does your carrier need username and password? [Y/n]"
2019-05-02 13:42:04 +00:00
read usernpass
2020-11-25 13:59:31 +00:00
colored_echo " You chose $usernpass " ${ GREEN }
2019-05-02 13:42:04 +00:00
case $usernpass in
2020-11-25 13:59:31 +00:00
[ Yy] * )
while [ 1 ]
2019-05-02 13:42:04 +00:00
do
2020-11-18 18:12:00 +00:00
colored_echo "Enter username"
2019-05-02 13:42:04 +00:00
read username
2020-11-25 13:59:31 +00:00
colored_echo " Your Input is : $username " ${ GREEN }
2020-11-18 18:12:00 +00:00
colored_echo "Enter password"
2019-05-02 13:42:04 +00:00
read password
2020-11-25 13:59:31 +00:00
colored_echo " Your Input is : $password " ${ GREEN }
2019-05-02 13:52:46 +00:00
sed -i " s/noauth/#noauth\nuser \" $username \"\npassword \" $password \"/ " provider
2019-05-02 13:42:04 +00:00
break
done
break; ;
[ Nn] * ) break; ;
2020-11-18 18:12:00 +00:00
*) colored_echo "Wrong Selection, Select among Y or n" ${ RED } ; ;
2019-05-02 13:42:04 +00:00
esac
done
2020-11-18 18:12:00 +00:00
colored_echo "What is your device communication PORT? (ttyS0/ttyUSB3/etc.)"
2018-10-15 14:58:48 +00:00
read devicename
2020-11-25 13:59:31 +00:00
colored_echo " Your input is: $devicename " ${ GREEN }
2020-11-26 15:22:19 +00:00
if grep -q "ttyS0" <<< " $devicename " ; then
2020-11-27 09:48:41 +00:00
colored_echo "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" ${ BLUE }
colored_echo "REMINDER!" ${ BLUE }
colored_echo "- Disable serial console and enable miniuart to use ttyS0 as the serial interface." ${ SET }
colored_echo "✔ If your ttyS0 (miniuart) port is enabled, press ENTER and continue to installation." ${ SET }
colored_echo "✘ If not, please follow the instructions to enable ttyS0 interface on Raspberry Pi" ${ SET }
echo -e "
1. Start raspi-config: ${ BLUE } sudo raspi-config${ SET } .
2. Select option 3 - ${ BLUE } Interface Options${ SET } .
3. Select option P6 - ${ BLUE } Serial Port${ SET } .
4. ${ BLUE } At the prompt Would you like a login shell to be accessible over serial?${ SET } answer ${ BLUE } 'No' ${ SET }
5. ${ BLUE } At the prompt Would you like the serial port hardware to be enabled?${ SET } answer ${ BLUE } 'Yes' ${ SET }
6. Exit raspi-config and ${ BLUE } reboot${ SET } the Pi for changes to take effect.
"
colored_echo "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" ${ BLUE }
echo
echo -e " Press ${ BLUE } ENTER ${ SET } key to continue to installation or press ${ BLUE } CTRL^C ${ SET } to abort installation and enable ttyS0 serial interface. "
read -p "" ENTER
colored_echo "Doing atcom configuration for ttyS0 serial..."
2020-11-26 15:22:19 +00:00
# create atcom config
echo port: "/dev/ttyS0" > configs.yml
mv configs.yml $PPP_PATH
else
# delete atcom config
ls $PPP_PATH | grep configs.yml > /dev/null
if [ [ $? -eq 0 ] ] ; then rm $PPP_PATH /configs.yml; fi
fi
2018-10-15 14:58:48 +00:00
mkdir -p /etc/chatscripts
2020-10-21 15:02:46 +00:00
2018-10-15 14:58:48 +00:00
mv chat-connect /etc/chatscripts/
mv chat-disconnect /etc/chatscripts/
mkdir -p /etc/ppp/peers
sed -i " s/#APN/ $carrierapn / " provider
sed -i " s/#DEVICE/ $devicename / " provider
mv provider /etc/ppp/peers/provider
2019-12-03 11:11:23 +00:00
if ! ( grep -q 'sudo route' /etc/ppp/ip-up ) ; then
2018-10-15 14:58:48 +00:00
echo "sudo route add default ppp0" >> /etc/ppp/ip-up
fi
2020-11-23 13:44:06 +00:00
if [ [ $shield_hat -eq 2 ] ] || [ [ $shield_hat -eq 6 ] ] ; then
2018-10-15 14:58:48 +00:00
if ! ( grep -q 'max_usb_current' /boot/config.txt ) ; then
echo "max_usb_current=1" >> /boot/config.txt
fi
fi
while [ 1 ]
do
2020-11-18 18:12:00 +00:00
colored_echo "Do you want to activate auto connect/reconnect service at R.Pi boot up? [Y/n]"
2019-05-02 13:42:04 +00:00
read auto_reconnect
2018-10-15 14:58:48 +00:00
2020-11-25 13:59:31 +00:00
colored_echo " You chose $auto_reconnect " ${ GREEN }
2019-05-02 13:42:04 +00:00
case $auto_reconnect in
2020-11-27 10:02:36 +00:00
[ Yy] * ) colored_echo "Copying setup file..."
2018-10-15 14:58:48 +00:00
2020-11-27 10:16:25 +00:00
cp $SOURCE_PATH /$SERVICE_NAME $SERVICE_NAME
cp $SOURCE_PATH /functions.sh functions.sh
cp $SOURCE_PATH /configs.sh configs.sh
cp $SOURCE_PATH /configure_modem.sh configure_modem.sh
cp $SOURCE_PATH /$MANAGER_SCRIPT_NAME $MANAGER_SCRIPT_NAME
2020-11-18 18:45:59 +00:00
2020-11-26 11:20:04 +00:00
# APN Configuration
sed -i " s/SIM_APN/ $carrierapn / " configure_modem.sh
2020-11-18 18:45:59 +00:00
2019-10-09 10:55:04 +00:00
if [ $shield_hat -eq 1 ] ; then
2018-10-15 14:58:48 +00:00
2020-11-27 10:07:47 +00:00
cp $SCRIPT_PATH /reconnect_gprsshield $RECONNECT_SCRIPT_NAME
2020-11-25 22:50:37 +00:00
sed -i " s/STATUS_PIN/ $STATUS_GPRS / " configure_modem.sh
sed -i " s/POWERKEY_PIN/ $POWERKEY_GPRS / " configure_modem.sh
sed -i " s/POWERUP_FLAG/ $POWERUP_REQ / " configure_modem.sh
2020-11-26 11:20:04 +00:00
2018-10-15 14:58:48 +00:00
2019-10-09 10:55:04 +00:00
elif [ $shield_hat -eq 2 ] ; then
2018-10-15 14:58:48 +00:00
2020-11-27 10:07:47 +00:00
cp $SCRIPT_PATH /reconnect_baseshield $RECONNECT_SCRIPT_NAME
2020-11-25 22:50:37 +00:00
sed -i " s/POWERUP_FLAG/ $POWERUP_NOT_REQ / " configure_modem.sh
2018-10-15 14:58:48 +00:00
2019-10-09 10:55:04 +00:00
elif [ $shield_hat -eq 3 ] ; then
2018-10-15 14:58:48 +00:00
2020-11-27 10:07:47 +00:00
cp $SCRIPT_PATH /reconnect_cellulariot_app $RECONNECT_SCRIPT_NAME
2020-11-25 22:50:37 +00:00
sed -i " s/STATUS_PIN/ $STATUS_CELL_IOT_APP / " configure_modem.sh
sed -i " s/POWERKEY_PIN/ $POWERKEY_CELL_IOT_APP / " configure_modem.sh
sed -i " s/POWERUP_FLAG/ $POWERUP_REQ / " configure_modem.sh
2018-10-15 14:58:48 +00:00
2019-10-09 10:55:04 +00:00
elif [ $shield_hat -eq 4 ] ; then
2019-04-12 13:47:20 +00:00
2020-11-27 10:07:47 +00:00
cp $SCRIPT_PATH /reconnect_cellulariot $RECONNECT_SCRIPT_NAME
2020-11-25 22:50:37 +00:00
sed -i " s/STATUS_PIN/ $STATUS_CELL_IOT / " configure_modem.sh
sed -i " s/POWERKEY_PIN/ $POWERKEY_CELL_IOT / " configure_modem.sh
sed -i " s/POWERUP_FLAG/ $POWERUP_REQ / " configure_modem.sh
2019-10-09 10:55:04 +00:00
elif [ $shield_hat -eq 5 ] ; then
2020-11-27 10:07:47 +00:00
cp $SCRIPT_PATH /reconnect_tracker $RECONNECT_SCRIPT_NAME
2019-10-09 10:55:04 +00:00
2020-11-25 22:50:37 +00:00
sed -i " s/STATUS_PIN/ $STATUS_TRACKER / " configure_modem.sh
sed -i " s/POWERKEY_PIN/ $POWERKEY_TRACKER / " configure_modem.sh
sed -i " s/POWERUP_FLAG/ $POWERUP_REQ / " configure_modem.sh
2019-10-13 19:14:14 +00:00
elif [ $shield_hat -eq 6 ] ; then
2020-11-27 10:07:47 +00:00
cp $SCRIPT_PATH /reconnect_basehat $RECONNECT_SCRIPT_NAME
2019-10-13 19:14:14 +00:00
2020-11-25 22:50:37 +00:00
sed -i " s/POWERUP_FLAG/ $POWERUP_NOT_REQ / " configure_modem.sh
2020-11-19 09:34:16 +00:00
fi
2018-10-15 14:58:48 +00:00
2020-11-18 18:45:59 +00:00
mv functions.sh $PPP_PATH
mv configs.sh $PPP_PATH
2020-11-19 09:34:16 +00:00
mv configure_modem.sh $PPP_PATH
mv $RECONNECT_SCRIPT_NAME $PPP_PATH
mv $MANAGER_SCRIPT_NAME $PPP_PATH
2020-11-19 08:19:04 +00:00
mv $SERVICE_NAME /etc/systemd/system/
2018-10-15 14:58:48 +00:00
systemctl daemon-reload
2020-11-19 08:19:04 +00:00
systemctl enable $SERVICE_NAME
2018-10-15 14:58:48 +00:00
break; ;
2020-11-18 18:12:00 +00:00
[ Nn] * ) echo -e " ${ YELLOW } To connect to internet run ${ BLUE } \"sudo pon\" ${ YELLOW } and to disconnect run ${ BLUE } \"sudo poff\" ${ SET } "
2018-10-15 14:58:48 +00:00
break; ;
2020-11-18 18:12:00 +00:00
*) colored_echo "Wrong Selection, Select among Y or n" ${ RED } ; ;
2018-10-15 14:58:48 +00:00
esac
done
2019-05-02 13:42:04 +00:00
read -p "Press ENTER key to reboot" ENTER
2020-11-25 13:59:31 +00:00
colored_echo "Rebooting..." ${ GREEN }
2020-06-04 09:12:42 +00:00
reboot